tag:blogger.com,1999:blog-15784953814971543012024-03-14T02:19:28.336-04:00The Way of MathematicaHow to use Mathematica and the Wolfram Langage - for beginner, intermediate, and advanced users.Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.comBlogger105125tag:blogger.com,1999:blog-1578495381497154301.post-45810862237180473382023-06-24T12:26:00.002-04:002023-06-24T12:26:59.815-04:00Import animated GIF into a Mathematica Notebook<p>Here's the animated image of a black hole I wanted to Import:</p><p>https://qph.cf2.quoracdn.net/main-qimg-7a4350884a5333a141e4faa234f45861</p><div class="separator" style="clear: both; text-align: center;"><a href="https://qph.cf2.quoracdn.net/main-qimg-7a4350884a5333a141e4faa234f45861" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="437" data-original-width="777" height="437" src="https://qph.cf2.quoracdn.net/main-qimg-7a4350884a5333a141e4faa234f45861" width="777" /></a></div><p>ChatGTP-3.5</p><p>To copy an animated GIF and paste it into a Mathematica notebook, you can follow these steps:</p><p>1. Find the animated GIF you want to use and open it in a web browser or an image viewer.</p><p>2. Right-click on the GIF and select "Copy" or "Copy Image" from the context menu. Alternatively, you can also use keyboard shortcuts like Ctrl+C (Windows) or Command+C (Mac) to copy the image.</p><p>3. Open your Mathematica notebook and navigate to the desired location where you want to paste the animated GIF.</p><p>4. Right-click in the notebook and select "Paste" or use the keyboard shortcuts Ctrl+V (Windows) or Command+V (Mac) to paste the image.</p><p>5. By default, Mathematica treats pasted images as static. However, you can utilize the `Import` function to import the GIF file and display it as an animation.</p><p>6. Place the cursor immediately after the pasted image, and enter the following code on a new line:</p><p>Import["clipboard", "Animation"]</p><p>7. Select the code you just entered and evaluate it by pressing Shift+Enter (Windows) or Shift+Return (Mac) or by clicking the "Evaluate" button in the toolbar.</p><p>Mathematica will now import the image from the clipboard as an animation and display it in the notebook. You can resize or reposition the animation by manipulating the cell containing the code and the imported image.</p><p>Note: If the image doesn't animate after evaluating the code, it's possible that the GIF is not recognized as an animation. In such cases, you might need to save the GIF as a separate file on your computer and use the file path in the `Import` function instead of `"clipboard"`. For example:</p><p>Import["C:/path/to/your/animated.gif", "Animation"]</p><p>Make sure to replace `"C:/path/to/your/animated.gif"` with the actual file path of your saved GIF.</p>Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-13118489071446385972023-04-26T10:17:00.004-04:002023-07-10T19:33:17.219-04:00Mathematica Bibliography<p>This list includes my favorite <i>Mathematica</i> books as well as a few others on good coding practices and algorithms. There is also my article on the Wolfram Language syntax using Prefx (@) and Postfix-Function (//f [ #, params]&) syntax that I use. (Older <a href="https://mathematica-guide.blogspot.com/2012/10/a-mathematica-bibliography-part-1-how.html">list</a>, annotated)</p><div><div>Abell, M. L. (2017). Mathematica by Example. Waltham, MA, Elsevier Inc.</div><div>Abell, M. L. and J. P. Braselton (2023). Differential Equations with Mathematica. London, United Kingdom ; San Diego, CA, United States, Academic Press is an imprint of Elsevier.</div><div>Abell, M. L., J. P. Braselton and J. A. Rafter (1999). Statistics with Mathematica. San Diego, Academic Press.</div><div>Bahder, T. B. (1995). Mathematica for scientists and engineers. Reading, Mass., Addison-Wesley Pub. Co.</div><div>Carlson, K. W. (2007) "A New Mathematica Programming Style." Wolfram Technology Conference.</div><div>Cheung, C. K. (2009). Getting Started with Mathematica. Hoboken, NJ, J. Wiley.</div><div>Crandall, R. E. (1991). Mathematica for the Sciences. Redwood City, Calif., Addison-Wesley, Advanced Book Program.</div><div>Crandall, R. E. (1994). Projects in Scientific Computation. Santa Clara, Calif., TELOS.</div><div>Crandall, R. E. (1996). Advanced Scientific Computation. Santa Clara CA, Springer-Verlag/TELOS.</div><div>Crandall, R. E. (1996). Topics in Advanced Scientific Computation. New York, N.Y., Springer-Telos.</div><div>Don, E. (2019). Mathematica. New York, McGraw-Hill.</div><div>Foxall, J. D. (2003). Practical Standards for Microsoft Visual Basic .NET. Redmond, Wash., Microsoft Press.</div><div>Friedl, J. E. F. (2006). Mastering regular expressions. Sebastapol, CA, O'Reilly.</div><div>Gray, J. W. (1998). Mastering Mathematica: Programming Methods and Applications. San Diego, Academic Press.</div><div>Jacob, C. (2001). Illustrating Evolutionary Computation with Mathematica. San Francisco, Morgan Kaufmann Pub.</div><div>Maeder, R. (1994). The Mathematica Programmer. Boston, AP Professional.</div><div>Maeder, R. (1996). The Mathematica Programmer II. San Diego, Calif., Academic Press.</div><div>Maeder, R. (1997). Programming in Mathematica. Reading, Mass., Addision Wesley Pub.</div><div>Maeder, R. (2000). Computer Science with Mathematica : Theory and Practice for Science, Mathematics, and Engineering. Cambridge, U.K. ; New York, Cambridge University Press.</div><div>Mangano, S. (2010). Mathematica Cookbook. Sebastopol, CA, O'Reilly.</div><div>McConnell, S. (2004). Code Complete. Redmond, Wash., Microsoft Press.</div><div>McDowell, G. L. v. (2016). Cracking the Coding Interview : 189 Programming Questions and Solutions. Palo Alto, CA, CareerCup, LLC.</div><div>Roughgarden, T. (2017). Algorithms Illuminated : Part 1, The Basics. San Francisco, CA, Soundlikeyourself Publishing LLC.</div><div>Roughgarden, T. (2019). Algorithms Illuminated. : Part 3: Greedy Algorithms. San Francisco, CA, Soundlikeyourself Publishing, LLC.</div><div>Ruskeepää, H. (2009). Mathematica Navigator : Mathematics, Statistics, and Graphics. Amsterdam ; Boston, Elsevier/Academic Press.</div><div>Tam, P. (1997). A Physicist's Guide to Mathematica. San Diego, Academic Press.</div><div>Torrence, B. F. and E. A. Torrence (2019). The Student's Introduction to Mathematica and the Wolfram Language. Cambridge, United Kingdom ; New York, NY, Cambridge University Press.</div><div>Trott, M. (2004). The Mathematica Guidebook for Graphics. New York, Springer.</div><div>Trott, M. (2004). The Mathematica GuideBook for Programming. New York, NY, Springer New York : Imprint: Springer.</div><div>Trott, M. and SpringerLink (2006). The Mathematica GuideBook for Symbolics. Mathematics and Statisics. New York, NY, Springer Science+Business Media, Inc</div><div>Springer New York.</div><div>Trott, M. P. D. and SpringerLink (2006). The Mathematica Guidebook for Numerics. Mathematics and Statistics. New York, NY, Springer</div><div>Springer New York.</div><div>Wagner, D. B. (1996). Power programming with Mathematica : the Kernel. New York, McGraw-Hill.</div><div>Wagon, S. (2010). Mathematica in Action: Problem Solving through Visualization and Computation. New York, Springer.</div><div>Wellin, P. R., R. J. Gaylord, S. N. Kamin and R. J. Gaylord (2005). An Introduction to Programming with Mathematica. Cambridge, England ; New York, Cambridge University Press.</div><div>Zimmerman, R. L. and F. I. Olness (2002). Mathematica for Physics. San Francisco, Addison Wesley.</div></div><div><br /></div>Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-15055288478048762052016-04-24T12:56:00.000-04:002016-04-24T12:56:16.217-04:00How It Works: Trapezoid Integration<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
How It Works : Integrate by the Trapezoid Rule</h2>
In related <a href="http://mathematica-guide.blogspot.com/2016/04/example-of-package-in-notebook.html" target="_blank">post </a>I used a numerical integration function from <a href="http://amzn.to/245hL0S" target="_blank">Bahder</a>, Mathematica for Scientists and Engineers, to integrate a sawtooth function. This is a great book. Despite having been written in 1995, it's a wealth of 'under the hood' insights into the Wolfram Language. Here is a second function from Bahder for integration via the trapezoid rule that is more sophisticated than the first one. And due to using built-in Listable functionality in Dot and Plus it's about twice as fast<br />
<br />
The syntax of the parameter uses a named Pattern to check the data parameter to see if it is a List of 2-element (x,y) pairs, then uses Condition to make sure that data contains more than one point.<br />
<br />
Here is the formula for integration by the trapezoid rule:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-EtSetgAMrNE/Vxz6ZCq-z3I/AAAAAAAAD_0/3wFKopOJewQk6pZBJZJmeiL9aX4FQUAlwCLcB/s1600/IntegrateTrapezoid-Formula.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="95" src="https://4.bp.blogspot.com/-EtSetgAMrNE/Vxz6ZCq-z3I/AAAAAAAAD_0/3wFKopOJewQk6pZBJZJmeiL9aX4FQUAlwCLcB/s640/IntegrateTrapezoid-Formula.png" width="640" /></a></div>
<br />
And here is Bahder's code. The syntax of the parameter uses a named Pattern to check data to see if it is a List of 2-element (x,y) pairs, then uses Condition to make sure that data contains more than one point.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@integrateTrapezoid;</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>integrateTrapezoid[data:{{_,_}..}/;Length@data>1]:=Module[{xDifferences,ySums},</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>xDifferences=Dot[{-1,1},#]&/@Partition[First/@data,2,1];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>ySums=Apply[Plus,Partition[Last/@data,2,1],{1}];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Plus@@(xDifferences,ySums)/2</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>]</b></span><br />
<br />
The Dot product multiplies each vector (List) term by term and sums them.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Dot[{a,b,c},{x,y,z}]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">a x+b y+c z</span><br />
<br />
Let's check to make sure the abbreviated operators for Apply and Divide will work as intended; which they will. Apply is 'stickier' than Divide and so Plus will be evaluated before taking the average (dividing by 2).<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Precedence/@{Apply,Divide}</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{620.,470.}</span><br />
<br />
We test it on his data and.. it doesn't work. There is a bug.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>data1={{1.2,51.3},{2.3,72.8},{3.0,87.1},{3.7,53.2}};</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>integrateTrapezoid@data1</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{62.6,80.3,70.5}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
Let's add some Print statements, which suffice for debugging all pure functional programs, that is, short ones.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@integrateTrapezoid;integrateTrapezoid[data:{{_,_}..}/;Length@data>1]:=Module[{xDifferences,ySums},</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>xDifferences=Dot[{-1,1},#]&/@Partition[First/@data,2,1];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Print@xDifferences;</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>ySums=Apply[Plus,Partition[Last/@data,2,1],{1}];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Print@ySums;</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Plus@@(xDifferences,ySums)/2</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
With the Print statement results it's easy to see that xDifferences is indeed the difference between successive x-points and ySums is the sum of each pair of successive y-values.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>integrateTrapezoid@data1</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{1.1,0.7,0.7}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">{124.1,159.9,140.3}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">{62.6,80.3,70.5}</span><br />
<br />
I see the bug. We should be multiplying xDifferences by ySums, not listing them. There's a lesson: Always use a multiplication symbol in code rather than a space, which might be mis-read as I did in Bahder's code. We'll add the multiplication and remove the Print statements.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@integrateTrapezoid;integrateTrapezoid[data:{{_,_}..}/;Length@data>1]:=Module[{xDifferences,ySums},</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>xDifferences=Dot[{-1,1},#]&/@Partition[First/@data,2,1];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>ySums=Apply[Plus,Partition[Last/@data,2,1],{1}];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Print@(xDifferences*ySums);</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Plus@@(xDifferences*ySums)/2</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
Now we get the correct answer.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>integrateTrapezoid@data1</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{136.51,111.93,98.21}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">173.325</span><br />
<br />
Let's try it on something else.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>data2={{0.0,0.0},{1.0,1.0},{2.0,0.0},{3.0,2.0},{4.0,0.0},{5.0,2.0},{6.0,1.0},{7.0,3.0},{8.0,0.0},{9.0,2.0},{10.0,0.0}};</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Graphics[Line@data2,Axes->True]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-1I9gNsVfTLM/Vxz2rpvOMDI/AAAAAAAAD_o/YUAgJ1P4OfAFTv6jeGxXgvku3ruJFJdcgCLcB/s1600/How%2BIt%2BWorks-IntegrateByTrapezoidRule-Fast-graph.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="110" src="https://4.bp.blogspot.com/-1I9gNsVfTLM/Vxz2rpvOMDI/AAAAAAAAD_o/YUAgJ1P4OfAFTv6jeGxXgvku3ruJFJdcgCLcB/s320/How%2BIt%2BWorks-IntegrateByTrapezoidRule-Fast-graph.png" width="320" /></a></div>
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>integrateTrapezoid@data2</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{1.,1.,2.,2.,2.,3.,4.,3.,2.,2.}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">11.</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
Trusting we got xDifferences and ySums right, we can copy and paste them into the program final line by hand to double-check its validity.<br />
<br />
<b><span style="font-family: "courier new" , "courier" , monospace;">Plus@@{1.`,1.`,2.`,2.`,2.`,3.`,4.`,3.`,2.`,2.`}/2</span></b><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">11.</span><br />
<br />
Recommended:<br />
<br /></div>
<a href="http://www.amazon.com/Mathematica-Scientists-Engineers-Thomas-Bahder/dp/0201540908/ref=as_li_ss_il?ie=UTF8&qid=1461251872&sr=8-1&keywords=bahder+mathematica&linkCode=li2&tag=concordpoetry-20&linkId=1a89cfe77d295bcd344006b2c0fa42a5" target="_blank"><img border="0" src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=0201540908&Format=_SL160_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=concordpoetry-20" /></a><img alt="" border="0" height="1" src="//ir-na.amazon-adsystem.com/e/ir?t=concordpoetry-20&l=li2&o=1&a=0201540908" style="border: none !important; margin: 0px !important;" width="1" /></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-83523269435658301812016-04-23T16:27:00.002-04:002016-04-24T08:18:09.004-04:00Compiling a Function: Mandelbrot Set<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Computing the Mandelbrot set is a classic example of the need to Compile a <i>Mathematica</i> function (see <a href="http://amzn.to/1qIiN4o">Ruskeepää</a>, p. 451). You just need to get the syntax right for a successful Compile. Below, the first argument is the parameter, c, and its type, Complex. The entire Module is the second argument, the expression to be compiled. Definitely try this at home!<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@mandelbrot;mandelbrot=Compile[{{c,_Complex}},Module[{z=0+0I,n=0},While [Abs@z<2&&n<50,z=z^2+c;n++];n ] ]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">CompiledFunction[Argument count: 1</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">Argument types: {_Complex}</span><br />
<br />
The CompiledFunction can be applied to individual numbers. The criteria for inclusion in the Mandelbrot set is, after a limited number of iterations of z = z^2 + c (in this case 50), is its absolute value less than a given number (in this case 2). The absolute value of a complex number is its Euclidean distance from the origin. If the absolute value of a number exceeds 2 before 50 iterations, e.g. 4, it is excluded.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>mandelbrot[0.2+I]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">4</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>mandelbrot[0.2+0.2I]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">50</span><br />
<br />
Let's do some heavy-duty computing. As a precaution we'll increase the RAM allocated to <i>Mathematica</i>.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Needs@"JLink`";</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>ReinstallJava[JVMArguments->"-Xmx6000m"]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">LinkObject[[]</span><br />
<br />
Start with a couple of individual plots. I use ImageSize->Full so when you do this yourself a large image will automatically be generated. On my Dell Optiplex 900 these take 2.68 seconds each.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Timing[DensityPlot[mandelbrot[x+I y],{x,-2,1},{y,-1.5,1.5},ColorFunction->Hue,PlotPoints->200,Mesh->False,ImageSize->Full,FrameTicks->{{-2,-1,0,1},{-1,0,1}}]]//Column</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://4.bp.blogspot.com/-Cr3_qgoqlY4/VxvZZwcIaHI/AAAAAAAAD-8/xzWGX67JucMolcirZnFj2q4EMD--T1tfQCLcB/s1600/Compiling%2Ba%2BFunction-Mandelbrot%2BSet-1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="640" src="https://4.bp.blogspot.com/-Cr3_qgoqlY4/VxvZZwcIaHI/AAAAAAAAD-8/xzWGX67JucMolcirZnFj2q4EMD--T1tfQCLcB/s640/Compiling%2Ba%2BFunction-Mandelbrot%2BSet-1.png" width="631" /></a></div>
<b style="font-family: 'courier new', courier, monospace;">Timing[DensityPlot[mandelbrot[x+I y],{x,-2,1},{y,-1.5,1.5},ColorFunction->"Rainbow",PlotPoints->200,Mesh->False,ImageSize->Full,FrameTicks->{{-2,-1,0,1},{-1,0,1}}]]//Column</b><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://2.bp.blogspot.com/-sKjOb8NiCec/VxvZgCNv7MI/AAAAAAAAD_E/eCWpL0CYLMcNQp8-kLDXX8RtpAmVzlSqACLcB/s1600/Compiling%2Ba%2BFunction-Mandelbrot%2BSet-2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="640" src="https://2.bp.blogspot.com/-sKjOb8NiCec/VxvZgCNv7MI/AAAAAAAAD_E/eCWpL0CYLMcNQp8-kLDXX8RtpAmVzlSqACLcB/s640/Compiling%2Ba%2BFunction-Mandelbrot%2BSet-2.png" width="631" /></a></div>
I'm kind of curious about all the built-in ColorFunctions. Let's plot Mandelbrot sets using each of them. Here they are. I reverse the order since I like some of the ones at the end best.<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: "courier new" , "courier" , monospace;"><b>colorFunctions=ColorData@"Gradients"</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: "courier new" , "courier" , monospace;">{AlpineColors,Aquamarine,ArmyColors,AtlanticColors,AuroraColors,AvocadoColors,BeachColors,BlueGreenYellow,BrassTones,BrightBands,BrownCyanTones,CandyColors,CherryTones,CMYKColors,CoffeeTones,DarkBands,DarkRainbow,DarkTerrain,DeepSeaColors,FallColors,FruitPunchColors,FuchsiaTones,GrayTones,GrayYellowTones,GreenBrownTerrain,GreenPinkTones,IslandColors,LakeColors,LightTemperatureMap,LightTerrain,MintColors,NeonColors,Pastel,PearlColors,PigeonTones,PlumColors,Rainbow,RedBlueTones,RedGreenSplit,RoseColors,RustTones,SandyTerrain,SiennaTones,SolarColors,SouthwestColors,StarryNightColors,SunsetColors,TemperatureMap,ThermometerColors,ValentineTones,WatermelonColors}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: "courier new" , "courier" , monospace;"><b>Length@colorFunctions</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: "courier new" , "courier" , monospace;">51</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: inherit;">I'll make a Grid of them that will correspond to the Grid of the plots themselves so we can easily look up the ColorFunction of one we like by finding its name in the corresponding place in the Grid. Although each row will have 3 plots and 3 divides 51 evenly, by habit I use the syntax for Partition that would not drop an overhang of a ragged List (the empty List {} in the position of the padding argument).</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: "courier new" , "courier" , monospace;">Reverse@colorFunctions//Partition[#,3,3,1,{}]&//Grid</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-fQkxZzVmklM/VxvYN_OWXeI/AAAAAAAAD-0/d6HgEieptmQMcr_3tPKg83iFQhQMA6IPACLcB/s1600/Compiling_a_function-ColorFunction-Grid.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://1.bp.blogspot.com/-fQkxZzVmklM/VxvYN_OWXeI/AAAAAAAAD-0/d6HgEieptmQMcr_3tPKg83iFQhQMA6IPACLcB/s1600/Compiling_a_function-ColorFunction-Grid.png" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
The iterator, <i>predefined</i>, in this Table iterates over all the ColorFunctions. Note you do not need to use the cumbersome {i, Length@colorFunctions} requiring the iterator to be a number.<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: "courier new" , "courier" , monospace;">Table[DensityPlot[mandelbrot[x+I y],{x,-2,1},{y,-1.5,1.5},ColorFunction->predefined,PlotPoints->200,Mesh->False,FrameTicks->{{-2,-1,0,1},{-1,0,1}},ImageSize->Medium],{predefined,Reverse@colorFunctions}]//Partition[#,3,3,1,{}]&//Grid</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-uFZbpBwA2JI/VxvZhpDZbXI/AAAAAAAAD_I/HaJ6DpAHLGYzgL6oW_hyJGvmaPQm8DLgACLcB/s1600/Compiling%2Ba%2BFunction-Mandelbrot%2BSet.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://1.bp.blogspot.com/-uFZbpBwA2JI/VxvZhpDZbXI/AAAAAAAAD_I/HaJ6DpAHLGYzgL6oW_hyJGvmaPQm8DLgACLcB/s1600/Compiling%2Ba%2BFunction-Mandelbrot%2BSet.png" /></a></div>
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Recommended:<br />
<br /></div>
<a href="http://www.amazon.com/Mathematica-Navigator-Mathematics-Statistics-Graphics/dp/0123741645/ref=as_li_ss_il?ie=UTF8&qid=1461443387&sr=8-1&keywords=ruskeepaa+mathematica&linkCode=li2&tag=concordpoetry-20&linkId=4fd0459c676458384c5954d4a28992a2" target="_blank"><img border="0" src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=0123741645&Format=_SL160_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=concordpoetry-20" /></a><img alt="" border="0" height="1" src="//ir-na.amazon-adsystem.com/e/ir?t=concordpoetry-20&l=li2&o=1&a=0123741645" style="border: none !important; margin: 0px !important;" width="1" /></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-77774967239147329742016-04-21T11:14:00.002-04:002016-04-24T12:44:03.410-04:00Example of a Package in a Notebook: Trapezoid Integration of Data Points<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
Integrate by the Trapezoid Rule</h2>
<br />
This example of writing your own numerical integration function is from Bahder's excellent <a href="http://amzn.to/1Nmr5t5" target="_blank">book</a>, <i>Mathematica for Scientists and Engineers</i>. I use it to show how to write a Package in a Notebook, as opposed to in a .m file.<br />
<br />
While it always pays to see if <i>Mathematica </i>has a built-in function to do what you want, I don't see that NIntegrate can integrate over data points, although it has this nice introduction for the TrapezoidRule: "The trapezoidal rule for integral estimation is one of the simplest and oldest rules (possibly used by the Babylonians and certainly by the ancient Greek mathematicians)."<br />
<br />
I needed a function to integrate over data points from an irregular, piecewise, sawtooth-type function. Bahder notes that integrating via the trapezoid rule approximates the integral over a list of (x,y) data points that may be irregularly spaced. Here is the formula. Keyboard shortcuts are faster than a palette; here they are Ctrl+- for subscript and Ctrl+spacebar to exit a subscript. Remember to use a double equal sign for 'equals'.<br />
<br />
<br /></div>
</div>
</div>
<div style="text-align: left;">
<a href="https://1.bp.blogspot.com/-CgfIM-cDf8Q/VxjqP76tl7I/AAAAAAAAD-A/ndxYtbnp9mAhjsxrs_HZwXlKpBbXQ0yuwCLcB/s1600/A_Package_in_a_Notebook.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img alt="" border="0" src="https://1.bp.blogspot.com/-CgfIM-cDf8Q/VxjqP76tl7I/AAAAAAAAD-A/ndxYtbnp9mAhjsxrs_HZwXlKpBbXQ0yuwCLcB/s1600/A_Package_in_a_Notebook.png" title="Integrate by Trapezoid Rule" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
Here is the numerical integral in a Package. The Package is in one Cell and I set the Cell to Initialization (right-click on the Cell and select Initialization Cell) to automatically load the Package when I evaluate any function in the Notebook.<br />
<br />
Note Bahder's use of a named Pattern and Repeated to type-check the data argument. It compares a List of repeated two-element Lists to the pairs that we give it. He then makes sure that there is more than one data pair using Condition. Some say the Wolfram Language is weakly-typed. That is incorrect; it has powerful type-creation and type-checking capabilities.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>BeginPackage@"BahderMSE`";</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>IntegrateTrapezoid::usage="IntegrateTrapezoid[data:{{_,_}..}/;Length@data>1] takes a list of (x,y) pairs, x1 < x2 <x3 ..., that are not necessarily evenly spaced and returns a numerical approximation to their integral using the trapezoid rule.";</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Begin@"`Private`";</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>IntegrateTrapezoid[data:{{_,_}..}/;Length@data>1]:=1/2 Sum[(data[[n+1,1]]-data[[n,1]])(data[[n,2]]+data[[n+1,2]]),{n,Length[data]-1}]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>End[];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>EndPackage[]</b></span><br />
<br />
Let's check the usage statement.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>In[7]:= ?IntegrateTrapezoid</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">IntegrateTrapezoid[data:{{_,_}..}/;Length@data>1] takes a list of (x,y) pairs, x1 < x2 <x3 ..., that are not necessarily evenly spaced and returns a numerical approximation to their integral using the trapezoid rule.</span><br />
<br />
Now test it on the same data Bahder used...<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>In[8]:= data1={{1.2,51.3},{2.3,72.8},{3.0,87.1},{3.7,53.2}};</b></span><br />
<br />
And we do get the same result.<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>In[9]:= IntegrateTrapezoid@data1</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">Out[9]= 173.325</span><br />
<br />
Let's try a different example using Mathematica's SawtoothWave function. This is a typical use of Thread to combine the x and y points in their own Lists.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>In[10]:= Thread@{Range[0,3,0.1],SawtoothWave@#&/@Range[0,3,0.1]}</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">Out[10]= {{0.,0.},{0.1,0.1},{0.2,0.2},{0.3,0.3},{0.4,0.4},{0.5,0.5},{0.6,0.6},{0.7,0.7},{0.8,0.8},{0.9,0.9},{1.,0.},{1.1,0.1},{1.2,0.2},{1.3,0.3},{1.4,0.4},{1.5,0.5},{1.6,0.6},{1.7,0.7},{1.8,0.8},{1.9,0.9},{2.,0.},{2.1,0.1},{2.2,0.2},{2.3,0.3},{2.4,0.4},{2.5,0.5},{2.6,0.6},{2.7,0.7},{2.8,0.8},{2.9,0.9},{3.,0.}}</span><br />
<br />
We see that it is a numerical approximation of the full SawtoothWave where the peaks fall short of 1.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-QHRm9yQu5Vg/VxjsBsxlHxI/AAAAAAAAD-M/4oZjWjaisAw3UOLZWv4QHFBAZMV0MgP7QCLcB/s1600/Sawtooth.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="302" src="https://3.bp.blogspot.com/-QHRm9yQu5Vg/VxjsBsxlHxI/AAAAAAAAD-M/4oZjWjaisAw3UOLZWv4QHFBAZMV0MgP7QCLcB/s640/Sawtooth.png" width="640" /></a></div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
There are three triangles of unit length and height = 0.9, so the total area by a = 1/2 b * h is 1.35. The function works for this example but would need to be validated and its accuracy evaluated for others.<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>IntegrateTrapezoid@%%</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">Out[12]= 1.35</span><br />
<br />
<a href="http://www.amazon.com/Mathematica-Scientists-Engineers-Thomas-Bahder/dp/0201540908/ref=as_li_ss_il?ie=UTF8&qid=1461251872&sr=8-1&keywords=bahder+mathematica&linkCode=li2&tag=concordpoetry-20&linkId=1a89cfe77d295bcd344006b2c0fa42a5" target="_blank"><img border="0" src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=0201540908&Format=_SL160_&ID=AsinImage&MarketPlace=US&ServiceVersion=20070822&WS=1&tag=concordpoetry-20" /></a><img alt="" border="0" height="1" src="//ir-na.amazon-adsystem.com/e/ir?t=concordpoetry-20&l=li2&o=1&a=0201540908" style="border: none !important; margin: 0px !important;" width="1" />
<br />
<h3 style="text-align: left;">
<span style="font-family: inherit;"><a href="http://amzn.to/1Nmr5t5" target="_blank"><i>Thomas Bahder, Mathematica for Scientists and Engineers</i></a></span></h3>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
</div>
</div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-85306171465947813442016-02-04T19:23:00.001-05:002016-08-20T14:22:15.138-04:00Wolfram Language Attribute: OneIdentity<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Attributes modify the behavior of entire classes of functions. Some Attributes cause functions to have well-known mathematical properties such as commutativity, associativity, or idempotency, notably for valid pattern-matching. Others control the way the Wolfram Language evaluates or does not evaluate a function's arguments, which if you study that you will see is at the very core of Wolfram Language operation.<br />
<br />
Listable is a valuable functional language Attribute since it incorporates Thread into a function so it automatically maps over a List and instead of taking a List apart, we apply a function to it as a gestalt.<br />
<br />
NumericFunction is an Attribute of all Wolfram Language mathematical functions and is True when all of their arguments are numerical. I suspect it is integral to the interaction of many functions with the underlying knowledge base of Mathematica and therefore to many functions' valid behavior (e.g. Piecewise – always define piecewise mathematical functions with Piecewise).<br />
<br />
<h2 style="text-align: left;">
Attribute: OneIdentity</h2>
<br />
OneIdentity is the mathematical property of idempotency, which dictates that applying a function any number of times to its argument (i.e. Nest) returns the argument unchanged. Examples are adding zero to any number, or multiplying any number by one, or raising any number to 1st or 0th power (except 0 - someone explain that inconsistency to me!).<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>0^0</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">During evaluation of In[549]:= Power::indet: Indeterminate expression 0^0 encountered. >></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">Out[549]= Indeterminate</span><br />
<br />
The Doc Center says that OneIdentity is necessary for pattern-matching to work with the default of Times, Plus, and Power, which is a period. I.e., x_+ y_. => x + 0, x_ * y_. => x * 1, and x_^y_. => x^1.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>MatchQ[x, Times[n_. , x_]]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">True</span><br />
<br />
You can see that OneIdentity removes nested Heads. It says to the evaluator, 'If the given pattern x_ matches any of these patterns, return True.'<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>a+b+c/.x_:>u/;Print@FullForm[Plus[x]//HoldForm]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[Plus[a,b,c]]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[Plus]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[a]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[b]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[c]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">a+b+c</span><br />
<br />
Here are related posts on <a href="http://mathematica-guide.blogspot.com/2016/02/wolfram-language-attribute-flat.html" target="_blank">Flat </a>and <a href="http://mathematica-guide.blogspot.com/2016/02/wolfram-language-attribute-orderless.html" target="_blank">Orderless</a>. This <a href="http://mathematica-guide.blogspot.com/2016/02/all-wolfram-language-functions-with-any.html" target="_blank">post </a>shows how to reveal all built-in functions with a given Attribute, categorized by the Attribute.<br />
<br />
This is an excellent out-of-print book but there is plenty to learn from it. I'd compare it to David Wagner's Power Programming in Mathematica in its insight to how the Wolfram Language works.<br />
<br />
Bahder, Thomas B. Mathematica for Scientists and Engineers. Reading, MA: Addison-Wesley. 1994.<br />
<br />
<br /></div>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ss&ref=ss_til&ad_type=product_link&tracking_id=concordpoetry-20&marketplace=amazon&region=US&placement=0201540908&asins=0201540908&linkId=CDF5GEHTELGIOLRS&show_border=true&link_opens_in_new_window=true" style="height: 240px; width: 120px;">
</iframe><br />
<br />
<div class="gt_newpost" style="background: rgb(255 , 255 , 255); border: 1px solid rgb(204 , 204 , 204); box-shadow: rgb(204 , 204 , 204) 0px 0px 5px; display: inline-table; font-size: 100%; height: auto; outline: 0px; padding: 20px; vertical-align: baseline; width: 240px;">
<div class="form-overlay">
</div>
<form action="http://www.specificfeeds.com/widgets/subscribeWidget/Z0NtcVhZV0pOVGxXdHN0OXh3RUs2cmJyZWdUcnMwQUI5aDVMUHlYbWhrWDlEa0E0QTBvMmhVWjM0L3dzYmY4WWxWNTBHeVFPOE4wd3RnR1p1RDBBRDMvWEFBSWxUYW5OajZPZWgrbGxtU2I0M21uNWlaTmtrbzdGYnNQQkpuV1Z8enlRTUgzSFBidFFUVk5xSWRHMUlkS2JuL1VPeHFuanV6ZTQycnlkUDFXZz0=/8/" method="post" target="popupwindow">
<div style="color: rgb(0 , 0 , 0); font-family: "helvetica" , "arial" , sans-serif; font-size: 16px; font-weight: bold; margin: 0px; text-align: center;">
Get new posts by email:</div>
<input name="data[Widget][email]" placeholder="Enter your email" style="font-size: 16px; line-height: 38px; margin: 15px 0 0 0; text-align: center; width: 100%;" type="text" value="" /> <input name="data[Widget][feed_id]" type="hidden" value="Z0NtcVhZV0pOVGxXdHN0OXh3RUs2cmJyZWdUcnMwQUI5aDVMUHlYbWhrWDlEa0E0QTBvMmhVWjM0L3dzYmY4WWxWNTBHeVFPOE4wd3RnR1p1RDBBRDMvWEFBSWxUYW5OajZPZWgrbGxtU2I0M21uNWlaTmtrbzdGYnNQQkpuV1Z8enlRTUgzSFBidFFUVk5xSWRHMUlkS2JuL1VPeHFuanV6ZTQycnlkUDFXZz0=" /> <input name="data[Widget][feedtype]" type="hidden" value="8" /> <input class="sub_inp_subt" name="subscribe" style="background-color: rgb(204 , 204 , 204); box-shadow: rgb(102 , 102 , 102) 1px 1px 0px; color: rgb(0 , 0 , 0); cursor: pointer; font-family: "helvetica" , "arial" , sans-serif; font-size: 16px; font-weight: bold; line-height: 38px; margin: 15px 0px 0px; text-align: center; width: 100%;" type="submit" value="Subscribe" /> </form>
</div>
</div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com2tag:blogger.com,1999:blog-1578495381497154301.post-4465112176405272472016-02-04T18:31:00.000-05:002016-02-04T19:30:57.368-05:00Wolfram Language Attribute: Flat<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
Attributes modify the behavior of entire classes of functions. Some Attributes cause functions to have well-known mathematical properties such as commutativity, associativity, or idempotency, notably for valid pattern-matching. Others control the way the Wolfram Language evaluates or does not evaluate a function's arguments, which if you study that you will see is at the very core of Wolfram Language operation.<br />
<br />
Listable is a valuable functional language Attribute since it incorporates Thread into a function so it automatically maps over a List and instead of taking a List apart, we apply a function to it as a gestalt.<br />
<br />
NumericFunction is an Attribute of all Wolfram Language mathematical functions and is True when all of their arguments are numerical. I suspect it is integral to the interaction of many functions with the underlying knowledge base of <i>Mathematica </i>and therefore to many functions' valid behavior (e.g. Piecewise – always define piecewise mathematical functions with Piecewise).<br />
<br />
<h2 style="text-align: left;">
Attribute: Flat</h2>
<br />
Flat is the mathematical property of associativity, which dictates that different groupings of numbers to specify the order in which the operation is performed, return the same result. E.g. ((a+b)+c) = (a+(b+c)) and (2x3)x4 = 2x(3x4).<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>a+(b+c)==(a+b)+c</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;">True</span><br />
<br />
Thomas Bahder uses a neat trick to show how Attributes work and how some affect pattern-matching. Here is the trick revealing the mechanism of Flat. Bahder uses a Condition that will never be True, which causes Wolfram Language to try all permutations of the function's arguments that are valid under Orderless. In the false predicate he inserts a Print statement to reveal how the Wolfram Language evaluator works. HoldForm is necessary to stop the evaluator from putting the arguments into standard order before printing them.<br />
<br />
Flat tells the Wolfram Language evaluator, 'If the given pattern x_ + y_ matches any of the following patterns, return True.'<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>a+b+c/.x_+y_:>u/;Print@FullForm[Plus[x,y]//HoldForm]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[a,Plus[b,c]]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[b,Plus[a,c]]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[c,Plus[a,b]]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[Plus[a,b],c]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[Plus[a,c],b]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[Plus[b,c],a]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[a,b]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[b,a]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[a,c]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[c,a]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[b,c]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[c,b]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">a+b+c</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>Here are related posts on <a href="http://mathematica-guide.blogspot.com/2016/02/wolfram-language-attribute-orderless.html" target="_blank">Orderless </a>and <a href="http://mathematica-guide.blogspot.com/2016/02/wolfram-language-attribute-oneidentity.html" target="_blank">OneIdentity</a>, and this <a href="http://mathematica-guide.blogspot.com/2016/02/all-wolfram-language-functions-with-any.html" target="_blank">post </a>shows how to reveal all built-in functions with Attributes categorize by their Attribute.<br />
<br />
This is an excellent out-of-print book but there is plenty to learn from it. I'd compare it to David Wagner's Power Programming in Mathematica in its insight to how the Wolfram Language works.<br />
<br />
Bahder, Thomas B. Mathematica for Scientists and Engineers. Reading, MA: Addison-Wesley. 1994.<br />
<br /></div>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ss&ref=ss_til&ad_type=product_link&tracking_id=concordpoetry-20&marketplace=amazon&region=US&placement=0201540908&asins=0201540908&linkId=CDF5GEHTELGIOLRS&show_border=true&link_opens_in_new_window=true" style="height: 240px; width: 120px;">
</iframe></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-85359665180382358302016-02-04T18:16:00.004-05:002022-09-06T17:57:40.451-04:00Wolfram Language Attribute: Orderless<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on"><span style="font-size: medium;">
Attributes modify the behavior of entire classes of functions. Some Attributes cause functions to have well-known mathematical properties such as commutativity, associativity, or idempotency, notably for valid pattern-matching. Others control the way the Wolfram Language evaluates or does not evaluate a function's arguments, which if you study that you will see is at the very core of Wolfram Language operation.<br />
<br />
Listable is a valuable functional language Attribute since it incorporates Thread into a function so it automatically maps over a List and instead of taking a List apart, we apply a function to it as a gestalt.<br />
<br />
NumericFunction is an Attribute of all WL mathematical functions and is True when all of their arguments are numerical. I suspect it is integral to the interaction of many functions with the underlying knowledge base of Mathematica and therefore to many functions' valid behavior (e.g. Piecewise – always define piecewise mathematical functions with Piecewise).<br />
<br />
</span><h2 style="text-align: left;"><span style="font-size: medium;">
Attribute: Orderless</span></h2>
<span style="font-size: medium;"><br />
Thomas Bahder uses a neat trick to show how Attributes work and how some affect pattern-matching. Here is the trick revealing the mechanism of Orderless, which is equivalent to the mathematical commutative property, that is, x + y = y + x.<br />
<br />
<br />
<br />
Bahder uses a Condition that will never be True, which causes WL to try all permutations of the function's arguments that are valid under Orderless. In the false predicate he inserts a Print statement to reveal how the WL evaluator works. HoldForm is necessary to stop the evaluator from putting the arguments into standard order before printing them.<br />
<br />
Orderless says to the Wolfram Language evaluator, 'If given pattern matches any of these patterns, return True.'<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">a+b+c/.x_+y_+z_:>u/;Print@FullForm[Plus[x,y,z]//HoldForm]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[a,b,c]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[a,c,b]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[b,a,c]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[b,c,a]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[c,a,b]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">HoldForm[Plus[c,b,a]]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">a+b+c</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: inherit;">Here are related posts on <a href="http://mathematica-guide.blogspot.com/2016/02/wolfram-language-attribute-flat.html" target="_blank">Flat </a>and <a href="http://mathematica-guide.blogspot.com/2016/02/wolfram-language-attribute-oneidentity.html" target="_blank">OneIdentity</a>. This <a href="http://mathematica-guide.blogspot.com/2016/02/all-wolfram-language-functions-with-any.html" target="_blank">post </a>lists all Wolfram Language functions that have any Attribute except Protected.</span><br />
<br />
<span style="font-family: inherit;">This is an excellent out-of-print book but there is plenty to learn from it. I'd compare it to David Wagner's Power Programming in Mathematica in its insight to how the Wolfram Language works. </span><br />
<span style="font-family: inherit;"><br /></span>
<br />
<span style="font-family: inherit;">Bahder, Thomas B. Mathematica for Scientists and Engineers. Reading, MA: Addison-Wesley. 1994.</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><br /></span></span></div>
<span style="font-size: medium;"><iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ss&ref=ss_til&ad_type=product_link&tracking_id=concordpoetry-20&marketplace=amazon&region=US&placement=0201540908&asins=0201540908&linkId=CDF5GEHTELGIOLRS&show_border=true&link_opens_in_new_window=true" style="height: 240px; width: 120px;">
</iframe></span></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-51360541717184461922016-02-04T17:33:00.002-05:002016-02-04T19:33:59.474-05:00All Wolfram Language Functions with any Attribute<div dir="ltr" style="text-align: left;" trbidi="on">
Attributes modify the behavior of entire classes of functions. Here are posts on <a href="http://mathematica-guide.blogspot.com/2016/02/wolfram-language-attribute-orderless.html" target="_blank">Orderless</a>, <a href="http://mathematica-guide.blogspot.com/2016/02/wolfram-language-attribute-flat.html" target="_blank">Flat</a>, and <a href="http://mathematica-guide.blogspot.com/2016/02/wolfram-language-attribute-oneidentity.html" target="_blank">OneIdentity</a>.<br />
<br />
Here is the List of the 19 Wolfram Language Attributes in v10. The indefatiguable Trott does something similar in his <i><a href="http://amzn.to/1SvWwmn" target="_blank">Mathematica Guidebook for Programming</a></i>.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>allAttributes = {Orderless, Flat, OneIdentity, Listable, Constant, </b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> NumericFunction, Protected, Locked, HoldFirst, HoldRest, HoldAll, </b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> HoldAllComplete, NHoldFirst, NHoldFirst, NHoldRest, NHoldAll, SequenceHold, </b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> Temporary, Stub}; Length@allAttributes</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">19</span><br />
<br />
About 5000 of the built-in functions are Protected so I'll delete that one since it doesn't tell us much.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>allAttributesLessProtected=DeleteCases[allAttributes,Protected]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{Orderless,Flat,OneIdentity,Listable,Constant,NumericFunction,Locked,HoldFirst,HoldRest,HoldAll,HoldAllComplete,NHoldFirst,NHoldFirst,NHoldRest,NHoldAll,SequenceHold,Temporary,Stub}</span><br />
<br />
Collect all System Symbols. There are 5574 in version 10.2.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>allSystemSymbols = Names@"System`*"; Length@allSystemSymbols</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;">5574</span><br />
<br />
Define a predicate to tell whether a Symbol has an Attribute or not, and make it Listable to automatically Map over a List argument.<br />
<br />
<b><span style="font-family: "courier new" , "courier" , monospace;">SetAttributes[hasAttributeQ, Listable]; </span></b><br />
<b><span style="font-family: "courier new" , "courier" , monospace;">hasAttributeQ[symbol_, attribute_] := </span></b><br />
<b><span style="font-family: "courier new" , "courier" , monospace;"> If[MemberQ[Attributes@symbol, attribute], True, False];</span></b><br />
<br />
Now construct a Table of functions with any of the Attributes. Use Select to apply the predicate hasAttributeQ to each built-in function, and return it if it has an Attribute. I could not get the column label in TableHeadings to work so I used Labeled to add one to each group. The formatting and centering of the Label didn't translate to this blog format but if you execute the code you'll see the result.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Table[Select[hasAttributeQ[#,attribute]&]@allSystemSymbols//TableForm[#,TableHeadings->{Automatic,None}]&//Labeled[#,"\n"<>ToString@attribute,Top,LabelStyle->Directive[Large,Bold,FontFamily->"Times New Roman"]]&,{attribute,allAttributes}]//Column</b></span><br />
<br />
<br />
<b>Orderless</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>ArithmeticGeometricMean<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>BitAnd<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>BitOr<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>BitXor<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>CoprimeQ<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>DiracComb<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>DiracDelta<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>DiscreteDelta<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>Equivalent<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>GCD<br />
11<span class="Apple-tab-span" style="white-space: pre;"> </span>HeavisideLambda<br />
12<span class="Apple-tab-span" style="white-space: pre;"> </span>HeavisidePi<br />
13<span class="Apple-tab-span" style="white-space: pre;"> </span>HeavisideTheta<br />
14<span class="Apple-tab-span" style="white-space: pre;"> </span>KroneckerDelta<br />
15<span class="Apple-tab-span" style="white-space: pre;"> </span>LCM<br />
16<span class="Apple-tab-span" style="white-space: pre;"> </span>Majority<br />
17<span class="Apple-tab-span" style="white-space: pre;"> </span>Max<br />
18<span class="Apple-tab-span" style="white-space: pre;"> </span>Min<br />
19<span class="Apple-tab-span" style="white-space: pre;"> </span>Multinomial<br />
20<span class="Apple-tab-span" style="white-space: pre;"> </span>OrderlessPatternSequence<br />
21<span class="Apple-tab-span" style="white-space: pre;"> </span>Plus<br />
22<span class="Apple-tab-span" style="white-space: pre;"> </span>Times<br />
23<span class="Apple-tab-span" style="white-space: pre;"> </span>UnitBox<br />
24<span class="Apple-tab-span" style="white-space: pre;"> </span>UnitStep<br />
25<span class="Apple-tab-span" style="white-space: pre;"> </span>UnitTriangle<br />
26<span class="Apple-tab-span" style="white-space: pre;"> </span>Xnor<br />
27<span class="Apple-tab-span" style="white-space: pre;"> </span>Xor<br />
<br />
<br />
<b>Flat</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>And<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>BitAnd<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>BitOr<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>BitXor<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>Composition<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>Dot<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>GCD<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>Intersection<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>Join<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>LCM<br />
11<span class="Apple-tab-span" style="white-space: pre;"> </span>Max<br />
12<span class="Apple-tab-span" style="white-space: pre;"> </span>Min<br />
13<span class="Apple-tab-span" style="white-space: pre;"> </span>NonCommutativeMultiply<br />
14<span class="Apple-tab-span" style="white-space: pre;"> </span>Or<br />
15<span class="Apple-tab-span" style="white-space: pre;"> </span>PermutationProduct<br />
16<span class="Apple-tab-span" style="white-space: pre;"> </span>Plus<br />
17<span class="Apple-tab-span" style="white-space: pre;"> </span>RegionProduct<br />
18<span class="Apple-tab-span" style="white-space: pre;"> </span>RightComposition<br />
19<span class="Apple-tab-span" style="white-space: pre;"> </span>StringExpression<br />
20<span class="Apple-tab-span" style="white-space: pre;"> </span>StringJoin<br />
21<span class="Apple-tab-span" style="white-space: pre;"> </span>Times<br />
22<span class="Apple-tab-span" style="white-space: pre;"> </span>Union<br />
23<span class="Apple-tab-span" style="white-space: pre;"> </span>Xor<br />
<br />
<br />
<b>OneIdentity</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>And<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>BitAnd<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>BitOr<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>BitXor<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>Composition<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>Dot<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>GCD<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>Intersection<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>Join<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>LCM<br />
11<span class="Apple-tab-span" style="white-space: pre;"> </span>Max<br />
12<span class="Apple-tab-span" style="white-space: pre;"> </span>Min<br />
13<span class="Apple-tab-span" style="white-space: pre;"> </span>NonCommutativeMultiply<br />
14<span class="Apple-tab-span" style="white-space: pre;"> </span>Or<br />
15<span class="Apple-tab-span" style="white-space: pre;"> </span>PermutationProduct<br />
16<span class="Apple-tab-span" style="white-space: pre;"> </span>Plus<br />
17<span class="Apple-tab-span" style="white-space: pre;"> </span>Power<br />
18<span class="Apple-tab-span" style="white-space: pre;"> </span>RegionProduct<br />
19<span class="Apple-tab-span" style="white-space: pre;"> </span>RightComposition<br />
20<span class="Apple-tab-span" style="white-space: pre;"> </span>StringExpression<br />
21<span class="Apple-tab-span" style="white-space: pre;"> </span>StringJoin<br />
22<span class="Apple-tab-span" style="white-space: pre;"> </span>Times<br />
23<span class="Apple-tab-span" style="white-space: pre;"> </span>Union<br />
24<span class="Apple-tab-span" style="white-space: pre;"> </span>Xor<br />
<br />
<br />
<b>Listable</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>Abs<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>AbsArg<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>AiryAi<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>AiryAiPrime<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>AiryBi<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>AiryBiPrime<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>AlgebraicIntegerQ<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>AlgebraicNumberDenominator<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>AlgebraicNumberNorm<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>AlgebraicNumberTrace<br />
11<span class="Apple-tab-span" style="white-space: pre;"> </span>AlgebraicUnitQ<br />
12<span class="Apple-tab-span" style="white-space: pre;"> </span>Apart<br />
13<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcCos<br />
14<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcCosh<br />
15<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcCot<br />
16<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcCoth<br />
17<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcCsc<br />
18<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcCsch<br />
19<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcSec<br />
20<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcSech<br />
21<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcSin<br />
22<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcSinh<br />
23<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcTan<br />
24<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcTanh<br />
25<span class="Apple-tab-span" style="white-space: pre;"> </span>Arg<br />
26<span class="Apple-tab-span" style="white-space: pre;"> </span>ArithmeticGeometricMean<br />
27<span class="Apple-tab-span" style="white-space: pre;"> </span>Attributes<br />
28<span class="Apple-tab-span" style="white-space: pre;"> </span>BarnesG<br />
29<span class="Apple-tab-span" style="white-space: pre;"> </span>BellB<br />
30<span class="Apple-tab-span" style="white-space: pre;"> </span>BernoulliB<br />
31<span class="Apple-tab-span" style="white-space: pre;"> </span>BesselI<br />
32<span class="Apple-tab-span" style="white-space: pre;"> </span>BesselJ<br />
33<span class="Apple-tab-span" style="white-space: pre;"> </span>BesselK<br />
34<span class="Apple-tab-span" style="white-space: pre;"> </span>BesselY<br />
35<span class="Apple-tab-span" style="white-space: pre;"> </span>Beta<br />
36<span class="Apple-tab-span" style="white-space: pre;"> </span>BetaRegularized<br />
37<span class="Apple-tab-span" style="white-space: pre;"> </span>Binomial<br />
38<span class="Apple-tab-span" style="white-space: pre;"> </span>BitAnd<br />
39<span class="Apple-tab-span" style="white-space: pre;"> </span>BitClear<br />
40<span class="Apple-tab-span" style="white-space: pre;"> </span>BitGet<br />
41<span class="Apple-tab-span" style="white-space: pre;"> </span>BitLength<br />
42<span class="Apple-tab-span" style="white-space: pre;"> </span>BitNot<br />
43<span class="Apple-tab-span" style="white-space: pre;"> </span>BitOr<br />
44<span class="Apple-tab-span" style="white-space: pre;"> </span>BitSet<br />
45<span class="Apple-tab-span" style="white-space: pre;"> </span>BitShiftLeft<br />
46<span class="Apple-tab-span" style="white-space: pre;"> </span>BitShiftRight<br />
47<span class="Apple-tab-span" style="white-space: pre;"> </span>BitXor<br />
48<span class="Apple-tab-span" style="white-space: pre;"> </span>Boole<br />
49<span class="Apple-tab-span" style="white-space: pre;"> </span>BooleanConvert<br />
50<span class="Apple-tab-span" style="white-space: pre;"> </span>BooleanMinimize<br />
51<span class="Apple-tab-span" style="white-space: pre;"> </span>Cancel<br />
52<span class="Apple-tab-span" style="white-space: pre;"> </span>CarmichaelLambda<br />
53<span class="Apple-tab-span" style="white-space: pre;"> </span>Ceiling<br />
54<span class="Apple-tab-span" style="white-space: pre;"> </span>Characters<br />
55<span class="Apple-tab-span" style="white-space: pre;"> </span>ChebyshevT<br />
56<span class="Apple-tab-span" style="white-space: pre;"> </span>ChebyshevU<br />
57<span class="Apple-tab-span" style="white-space: pre;"> </span>Coefficient<br />
58<span class="Apple-tab-span" style="white-space: pre;"> </span>CompositeQ<br />
59<span class="Apple-tab-span" style="white-space: pre;"> </span>Conjugate<br />
60<span class="Apple-tab-span" style="white-space: pre;"> </span>ContinuedFraction<br />
61<span class="Apple-tab-span" style="white-space: pre;"> </span>CoprimeQ<br />
62<span class="Apple-tab-span" style="white-space: pre;"> </span>Cos<br />
63<span class="Apple-tab-span" style="white-space: pre;"> </span>Cosh<br />
64<span class="Apple-tab-span" style="white-space: pre;"> </span>Cot<br />
65<span class="Apple-tab-span" style="white-space: pre;"> </span>Coth<br />
66<span class="Apple-tab-span" style="white-space: pre;"> </span>CreateDirectory<br />
67<span class="Apple-tab-span" style="white-space: pre;"> </span>Csc<br />
68<span class="Apple-tab-span" style="white-space: pre;"> </span>Csch<br />
69<span class="Apple-tab-span" style="white-space: pre;"> </span>CubeRoot<br />
70<span class="Apple-tab-span" style="white-space: pre;"> </span>Cyclotomic<br />
71<span class="Apple-tab-span" style="white-space: pre;"> </span>Decompose<br />
72<span class="Apple-tab-span" style="white-space: pre;"> </span>DedekindEta<br />
73<span class="Apple-tab-span" style="white-space: pre;"> </span>Denominator<br />
74<span class="Apple-tab-span" style="white-space: pre;"> </span>DiracComb<br />
75<span class="Apple-tab-span" style="white-space: pre;"> </span>DiracDelta<br />
76<span class="Apple-tab-span" style="white-space: pre;"> </span>DirectedInfinity<br />
77<span class="Apple-tab-span" style="white-space: pre;"> </span>Discriminant<br />
78<span class="Apple-tab-span" style="white-space: pre;"> </span>Divide<br />
79<span class="Apple-tab-span" style="white-space: pre;"> </span>Divisible<br />
80<span class="Apple-tab-span" style="white-space: pre;"> </span>Divisors<br />
81<span class="Apple-tab-span" style="white-space: pre;"> </span>DivisorSigma<br />
82<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticE<br />
83<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticF<br />
84<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticK<br />
85<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticPi<br />
86<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticTheta<br />
87<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticThetaPrime<br />
88<span class="Apple-tab-span" style="white-space: pre;"> </span>Erf<br />
89<span class="Apple-tab-span" style="white-space: pre;"> </span>Erfc<br />
90<span class="Apple-tab-span" style="white-space: pre;"> </span>Erfi<br />
91<span class="Apple-tab-span" style="white-space: pre;"> </span>EulerE<br />
92<span class="Apple-tab-span" style="white-space: pre;"> </span>EulerPhi<br />
93<span class="Apple-tab-span" style="white-space: pre;"> </span>EvenQ<br />
94<span class="Apple-tab-span" style="white-space: pre;"> </span>Exp<br />
95<span class="Apple-tab-span" style="white-space: pre;"> </span>ExpIntegralE<br />
96<span class="Apple-tab-span" style="white-space: pre;"> </span>ExpIntegralEi<br />
97<span class="Apple-tab-span" style="white-space: pre;"> </span>Exponent<br />
98<span class="Apple-tab-span" style="white-space: pre;"> </span>ExpToTrig<br />
99<span class="Apple-tab-span" style="white-space: pre;"> </span>ExtendedGCD<br />
100<span class="Apple-tab-span" style="white-space: pre;"> </span>Factor<br />
101<span class="Apple-tab-span" style="white-space: pre;"> </span>Factorial<br />
102<span class="Apple-tab-span" style="white-space: pre;"> </span>Factorial2<br />
103<span class="Apple-tab-span" style="white-space: pre;"> </span>FactorialPower<br />
104<span class="Apple-tab-span" style="white-space: pre;"> </span>FactorInteger<br />
105<span class="Apple-tab-span" style="white-space: pre;"> </span>FactorSquareFree<br />
106<span class="Apple-tab-span" style="white-space: pre;"> </span>Fibonacci<br />
107<span class="Apple-tab-span" style="white-space: pre;"> </span>Fibonorial<br />
108<span class="Apple-tab-span" style="white-space: pre;"> </span>Floor<br />
109<span class="Apple-tab-span" style="white-space: pre;"> </span>FractionalPart<br />
110<span class="Apple-tab-span" style="white-space: pre;"> </span>Gamma<br />
111<span class="Apple-tab-span" style="white-space: pre;"> </span>GammaRegularized<br />
112<span class="Apple-tab-span" style="white-space: pre;"> </span>GCD<br />
113<span class="Apple-tab-span" style="white-space: pre;"> </span>GegenbauerC<br />
114<span class="Apple-tab-span" style="white-space: pre;"> </span>Gudermannian<br />
115<span class="Apple-tab-span" style="white-space: pre;"> </span>HankelH1<br />
116<span class="Apple-tab-span" style="white-space: pre;"> </span>HankelH2<br />
117<span class="Apple-tab-span" style="white-space: pre;"> </span>HarmonicNumber<br />
118<span class="Apple-tab-span" style="white-space: pre;"> </span>Haversine<br />
119<span class="Apple-tab-span" style="white-space: pre;"> </span>HeavisideLambda<br />
120<span class="Apple-tab-span" style="white-space: pre;"> </span>HeavisidePi<br />
121<span class="Apple-tab-span" style="white-space: pre;"> </span>HeavisideTheta<br />
122<span class="Apple-tab-span" style="white-space: pre;"> </span>HermiteH<br />
123<span class="Apple-tab-span" style="white-space: pre;"> </span>HurwitzLerchPhi<br />
124<span class="Apple-tab-span" style="white-space: pre;"> </span>HurwitzZeta<br />
125<span class="Apple-tab-span" style="white-space: pre;"> </span>Hypergeometric0F1<br />
126<span class="Apple-tab-span" style="white-space: pre;"> </span>Hypergeometric0F1Regularized<br />
127<span class="Apple-tab-span" style="white-space: pre;"> </span>Hypergeometric1F1<br />
128<span class="Apple-tab-span" style="white-space: pre;"> </span>Hypergeometric1F1Regularized<br />
129<span class="Apple-tab-span" style="white-space: pre;"> </span>Hypergeometric2F1<br />
130<span class="Apple-tab-span" style="white-space: pre;"> </span>Hypergeometric2F1Regularized<br />
131<span class="Apple-tab-span" style="white-space: pre;"> </span>HypergeometricU<br />
132<span class="Apple-tab-span" style="white-space: pre;"> </span>Im<br />
133<span class="Apple-tab-span" style="white-space: pre;"> </span>In<br />
134<span class="Apple-tab-span" style="white-space: pre;"> </span>InString<br />
135<span class="Apple-tab-span" style="white-space: pre;"> </span>IntegerDigits<br />
136<span class="Apple-tab-span" style="white-space: pre;"> </span>IntegerExponent<br />
137<span class="Apple-tab-span" style="white-space: pre;"> </span>IntegerLength<br />
138<span class="Apple-tab-span" style="white-space: pre;"> </span>IntegerPart<br />
139<span class="Apple-tab-span" style="white-space: pre;"> </span>IntegerString<br />
140<span class="Apple-tab-span" style="white-space: pre;"> </span>IntervalMemberQ<br />
141<span class="Apple-tab-span" style="white-space: pre;"> </span>InverseGudermannian<br />
142<span class="Apple-tab-span" style="white-space: pre;"> </span>InverseHaversine<br />
143<span class="Apple-tab-span" style="white-space: pre;"> </span>IrreduciblePolynomialQ<br />
144<span class="Apple-tab-span" style="white-space: pre;"> </span>JacobiP<br />
145<span class="Apple-tab-span" style="white-space: pre;"> </span>JacobiSymbol<br />
146<span class="Apple-tab-span" style="white-space: pre;"> </span>JacobiZeta<br />
147<span class="Apple-tab-span" style="white-space: pre;"> </span>KelvinBei<br />
148<span class="Apple-tab-span" style="white-space: pre;"> </span>KelvinBer<br />
149<span class="Apple-tab-span" style="white-space: pre;"> </span>KelvinKei<br />
150<span class="Apple-tab-span" style="white-space: pre;"> </span>KelvinKer<br />
151<span class="Apple-tab-span" style="white-space: pre;"> </span>LaguerreL<br />
152<span class="Apple-tab-span" style="white-space: pre;"> </span>LambertW<br />
153<span class="Apple-tab-span" style="white-space: pre;"> </span>LCM<br />
154<span class="Apple-tab-span" style="white-space: pre;"> </span>LegendreP<br />
155<span class="Apple-tab-span" style="white-space: pre;"> </span>LegendreQ<br />
156<span class="Apple-tab-span" style="white-space: pre;"> </span>LerchPhi<br />
157<span class="Apple-tab-span" style="white-space: pre;"> </span>Limit<br />
158<span class="Apple-tab-span" style="white-space: pre;"> </span>Log<br />
159<span class="Apple-tab-span" style="white-space: pre;"> </span>Log10<br />
160<span class="Apple-tab-span" style="white-space: pre;"> </span>Log2<br />
161<span class="Apple-tab-span" style="white-space: pre;"> </span>LogBarnesG<br />
162<span class="Apple-tab-span" style="white-space: pre;"> </span>LogGamma<br />
163<span class="Apple-tab-span" style="white-space: pre;"> </span>LogIntegral<br />
164<span class="Apple-tab-span" style="white-space: pre;"> </span>LogisticSigmoid<br />
165<span class="Apple-tab-span" style="white-space: pre;"> </span>LucasL<br />
166<span class="Apple-tab-span" style="white-space: pre;"> </span>MakeExpression<br />
167<span class="Apple-tab-span" style="white-space: pre;"> </span>MantissaExponent<br />
168<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuC<br />
169<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCharacteristicA<br />
170<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCharacteristicB<br />
171<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCharacteristicExponent<br />
172<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCPrime<br />
173<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuS<br />
174<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuSPrime<br />
175<span class="Apple-tab-span" style="white-space: pre;"> </span>MessageList<br />
176<span class="Apple-tab-span" style="white-space: pre;"> </span>MinimalPolynomial<br />
177<span class="Apple-tab-span" style="white-space: pre;"> </span>Minus<br />
178<span class="Apple-tab-span" style="white-space: pre;"> </span>Mod<br />
179<span class="Apple-tab-span" style="white-space: pre;"> </span>MoebiusMu<br />
180<span class="Apple-tab-span" style="white-space: pre;"> </span>Multinomial<br />
181<span class="Apple-tab-span" style="white-space: pre;"> </span>Negative<br />
182<span class="Apple-tab-span" style="white-space: pre;"> </span>NonNegative<br />
183<span class="Apple-tab-span" style="white-space: pre;"> </span>NonPositive<br />
184<span class="Apple-tab-span" style="white-space: pre;"> </span>NumberFieldDiscriminant<br />
185<span class="Apple-tab-span" style="white-space: pre;"> </span>NumberFieldFundamentalUnits<br />
186<span class="Apple-tab-span" style="white-space: pre;"> </span>NumberFieldIntegralBasis<br />
187<span class="Apple-tab-span" style="white-space: pre;"> </span>NumberFieldNormRepresentatives<br />
188<span class="Apple-tab-span" style="white-space: pre;"> </span>NumberFieldRegulator<br />
189<span class="Apple-tab-span" style="white-space: pre;"> </span>NumberFieldRootsOfUnity<br />
190<span class="Apple-tab-span" style="white-space: pre;"> </span>NumberFieldSignature<br />
191<span class="Apple-tab-span" style="white-space: pre;"> </span>Numerator<br />
192<span class="Apple-tab-span" style="white-space: pre;"> </span>OddQ<br />
193<span class="Apple-tab-span" style="white-space: pre;"> </span>Out<br />
194<span class="Apple-tab-span" style="white-space: pre;"> </span>ParabolicCylinderD<br />
195<span class="Apple-tab-span" style="white-space: pre;"> </span>PartitionsP<br />
196<span class="Apple-tab-span" style="white-space: pre;"> </span>PartitionsQ<br />
197<span class="Apple-tab-span" style="white-space: pre;"> </span>Plus<br />
198<span class="Apple-tab-span" style="white-space: pre;"> </span>Pochhammer<br />
199<span class="Apple-tab-span" style="white-space: pre;"> </span>PolyGamma<br />
200<span class="Apple-tab-span" style="white-space: pre;"> </span>PolyLog<br />
201<span class="Apple-tab-span" style="white-space: pre;"> </span>PolynomialGCD<br />
202<span class="Apple-tab-span" style="white-space: pre;"> </span>PolynomialLCM<br />
203<span class="Apple-tab-span" style="white-space: pre;"> </span>Positive<br />
204<span class="Apple-tab-span" style="white-space: pre;"> </span>PossibleZeroQ<br />
205<span class="Apple-tab-span" style="white-space: pre;"> </span>Power<br />
206<span class="Apple-tab-span" style="white-space: pre;"> </span>PowerMod<br />
207<span class="Apple-tab-span" style="white-space: pre;"> </span>Prime<br />
208<span class="Apple-tab-span" style="white-space: pre;"> </span>PrimePi<br />
209<span class="Apple-tab-span" style="white-space: pre;"> </span>PrimeQ<br />
210<span class="Apple-tab-span" style="white-space: pre;"> </span>PrimitiveRoot<br />
211<span class="Apple-tab-span" style="white-space: pre;"> </span>ProductLog<br />
212<span class="Apple-tab-span" style="white-space: pre;"> </span>QBinomial<br />
213<span class="Apple-tab-span" style="white-space: pre;"> </span>QFactorial<br />
214<span class="Apple-tab-span" style="white-space: pre;"> </span>QGamma<br />
215<span class="Apple-tab-span" style="white-space: pre;"> </span>QPochhammer<br />
216<span class="Apple-tab-span" style="white-space: pre;"> </span>QPolyGamma<br />
217<span class="Apple-tab-span" style="white-space: pre;"> </span>QuadraticIrrationalQ<br />
218<span class="Apple-tab-span" style="white-space: pre;"> </span>QuantityVariableCanonicalUnit<br />
219<span class="Apple-tab-span" style="white-space: pre;"> </span>QuantityVariableDimensions<br />
220<span class="Apple-tab-span" style="white-space: pre;"> </span>QuantityVariableIdentifier<br />
221<span class="Apple-tab-span" style="white-space: pre;"> </span>QuantityVariablePhysicalQuantity<br />
222<span class="Apple-tab-span" style="white-space: pre;"> </span>Quotient<br />
223<span class="Apple-tab-span" style="white-space: pre;"> </span>QuotientRemainder<br />
224<span class="Apple-tab-span" style="white-space: pre;"> </span>Range<br />
225<span class="Apple-tab-span" style="white-space: pre;"> </span>Re<br />
226<span class="Apple-tab-span" style="white-space: pre;"> </span>RealDigits<br />
227<span class="Apple-tab-span" style="white-space: pre;"> </span>RealExponent<br />
228<span class="Apple-tab-span" style="white-space: pre;"> </span>ReIm<br />
229<span class="Apple-tab-span" style="white-space: pre;"> </span>RemoveScheduledTask<br />
230<span class="Apple-tab-span" style="white-space: pre;"> </span>Resultant<br />
231<span class="Apple-tab-span" style="white-space: pre;"> </span>RiemannSiegelTheta<br />
232<span class="Apple-tab-span" style="white-space: pre;"> </span>RiemannSiegelZ<br />
233<span class="Apple-tab-span" style="white-space: pre;"> </span>RootApproximant<br />
234<span class="Apple-tab-span" style="white-space: pre;"> </span>RootOfUnityQ<br />
235<span class="Apple-tab-span" style="white-space: pre;"> </span>Round<br />
236<span class="Apple-tab-span" style="white-space: pre;"> </span>Sec<br />
237<span class="Apple-tab-span" style="white-space: pre;"> </span>Sech<br />
238<span class="Apple-tab-span" style="white-space: pre;"> </span>Sign<br />
239<span class="Apple-tab-span" style="white-space: pre;"> </span>Sin<br />
240<span class="Apple-tab-span" style="white-space: pre;"> </span>Sinc<br />
241<span class="Apple-tab-span" style="white-space: pre;"> </span>Sinh<br />
242<span class="Apple-tab-span" style="white-space: pre;"> </span>SphericalBesselJ<br />
243<span class="Apple-tab-span" style="white-space: pre;"> </span>SphericalBesselY<br />
244<span class="Apple-tab-span" style="white-space: pre;"> </span>SphericalHankelH1<br />
245<span class="Apple-tab-span" style="white-space: pre;"> </span>SphericalHankelH2<br />
246<span class="Apple-tab-span" style="white-space: pre;"> </span>SphericalHarmonicY<br />
247<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalEigenvalue<br />
248<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalPS<br />
249<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalPSPrime<br />
250<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalQS<br />
251<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalQSPrime<br />
252<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalS1<br />
253<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalS1Prime<br />
254<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalS2<br />
255<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalS2Prime<br />
256<span class="Apple-tab-span" style="white-space: pre;"> </span>Sqrt<br />
257<span class="Apple-tab-span" style="white-space: pre;"> </span>StirlingS1<br />
258<span class="Apple-tab-span" style="white-space: pre;"> </span>StirlingS2<br />
259<span class="Apple-tab-span" style="white-space: pre;"> </span>StopScheduledTask<br />
260<span class="Apple-tab-span" style="white-space: pre;"> </span>StringByteCount<br />
261<span class="Apple-tab-span" style="white-space: pre;"> </span>StringLength<br />
262<span class="Apple-tab-span" style="white-space: pre;"> </span>StringReverse<br />
263<span class="Apple-tab-span" style="white-space: pre;"> </span>StruveH<br />
264<span class="Apple-tab-span" style="white-space: pre;"> </span>StruveL<br />
265<span class="Apple-tab-span" style="white-space: pre;"> </span>Subtract<br />
266<span class="Apple-tab-span" style="white-space: pre;"> </span>Surd<br />
267<span class="Apple-tab-span" style="white-space: pre;"> </span>Tan<br />
268<span class="Apple-tab-span" style="white-space: pre;"> </span>Tanh<br />
269<span class="Apple-tab-span" style="white-space: pre;"> </span>Times<br />
270<span class="Apple-tab-span" style="white-space: pre;"> </span>ToExpression<br />
271<span class="Apple-tab-span" style="white-space: pre;"> </span>Together<br />
272<span class="Apple-tab-span" style="white-space: pre;"> </span>ToHeldExpression<br />
273<span class="Apple-tab-span" style="white-space: pre;"> </span>ToLowerCase<br />
274<span class="Apple-tab-span" style="white-space: pre;"> </span>ToUpperCase<br />
275<span class="Apple-tab-span" style="white-space: pre;"> </span>TrigFactor<br />
276<span class="Apple-tab-span" style="white-space: pre;"> </span>TrigToExp<br />
277<span class="Apple-tab-span" style="white-space: pre;"> </span>UnitBox<br />
278<span class="Apple-tab-span" style="white-space: pre;"> </span>UnitDimensions<br />
279<span class="Apple-tab-span" style="white-space: pre;"> </span>Unitize<br />
280<span class="Apple-tab-span" style="white-space: pre;"> </span>UnitSimplify<br />
281<span class="Apple-tab-span" style="white-space: pre;"> </span>UnitStep<br />
282<span class="Apple-tab-span" style="white-space: pre;"> </span>UnitTriangle<br />
283<span class="Apple-tab-span" style="white-space: pre;"> </span>WhittakerM<br />
284<span class="Apple-tab-span" style="white-space: pre;"> </span>WhittakerW<br />
285<span class="Apple-tab-span" style="white-space: pre;"> </span>Zeta<br />
<br />
<br />
<b>Constant</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>Catalan<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>Degree<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>E<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>EulerGamma<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>Glaisher<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>GoldenAngle<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>GoldenRatio<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>Khinchin<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>MachinePrecision<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>Pi<br />
<br />
<br />
<b>NumericFunction</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>Abs<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>AiryAi<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>AiryAiPrime<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>AiryBi<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>AiryBiPrime<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcCos<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcCosh<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcCot<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcCoth<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcCsc<br />
11<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcCsch<br />
12<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcSec<br />
13<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcSech<br />
14<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcSin<br />
15<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcSinh<br />
16<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcTan<br />
17<span class="Apple-tab-span" style="white-space: pre;"> </span>ArcTanh<br />
18<span class="Apple-tab-span" style="white-space: pre;"> </span>Arg<br />
19<span class="Apple-tab-span" style="white-space: pre;"> </span>ArithmeticGeometricMean<br />
20<span class="Apple-tab-span" style="white-space: pre;"> </span>BarnesG<br />
21<span class="Apple-tab-span" style="white-space: pre;"> </span>BesselI<br />
22<span class="Apple-tab-span" style="white-space: pre;"> </span>BesselJ<br />
23<span class="Apple-tab-span" style="white-space: pre;"> </span>BesselK<br />
24<span class="Apple-tab-span" style="white-space: pre;"> </span>BesselY<br />
25<span class="Apple-tab-span" style="white-space: pre;"> </span>Beta<br />
26<span class="Apple-tab-span" style="white-space: pre;"> </span>BetaRegularized<br />
27<span class="Apple-tab-span" style="white-space: pre;"> </span>Binomial<br />
28<span class="Apple-tab-span" style="white-space: pre;"> </span>BSplineBasis<br />
29<span class="Apple-tab-span" style="white-space: pre;"> </span>Ceiling<br />
30<span class="Apple-tab-span" style="white-space: pre;"> </span>ChebyshevT<br />
31<span class="Apple-tab-span" style="white-space: pre;"> </span>ChebyshevU<br />
32<span class="Apple-tab-span" style="white-space: pre;"> </span>Clip<br />
33<span class="Apple-tab-span" style="white-space: pre;"> </span>Conjugate<br />
34<span class="Apple-tab-span" style="white-space: pre;"> </span>Cos<br />
35<span class="Apple-tab-span" style="white-space: pre;"> </span>Cosh<br />
36<span class="Apple-tab-span" style="white-space: pre;"> </span>Cot<br />
37<span class="Apple-tab-span" style="white-space: pre;"> </span>Coth<br />
38<span class="Apple-tab-span" style="white-space: pre;"> </span>Csc<br />
39<span class="Apple-tab-span" style="white-space: pre;"> </span>Csch<br />
40<span class="Apple-tab-span" style="white-space: pre;"> </span>CubeRoot<br />
41<span class="Apple-tab-span" style="white-space: pre;"> </span>DedekindEta<br />
42<span class="Apple-tab-span" style="white-space: pre;"> </span>DiracComb<br />
43<span class="Apple-tab-span" style="white-space: pre;"> </span>DiscreteDelta<br />
44<span class="Apple-tab-span" style="white-space: pre;"> </span>Divide<br />
45<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticE<br />
46<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticF<br />
47<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticK<br />
48<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticPi<br />
49<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticTheta<br />
50<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticThetaPrime<br />
51<span class="Apple-tab-span" style="white-space: pre;"> </span>Erf<br />
52<span class="Apple-tab-span" style="white-space: pre;"> </span>Erfc<br />
53<span class="Apple-tab-span" style="white-space: pre;"> </span>Erfi<br />
54<span class="Apple-tab-span" style="white-space: pre;"> </span>Exp<br />
55<span class="Apple-tab-span" style="white-space: pre;"> </span>ExpIntegralE<br />
56<span class="Apple-tab-span" style="white-space: pre;"> </span>ExpIntegralEi<br />
57<span class="Apple-tab-span" style="white-space: pre;"> </span>Factorial<br />
58<span class="Apple-tab-span" style="white-space: pre;"> </span>Factorial2<br />
59<span class="Apple-tab-span" style="white-space: pre;"> </span>FactorialPower<br />
60<span class="Apple-tab-span" style="white-space: pre;"> </span>Fibonacci<br />
61<span class="Apple-tab-span" style="white-space: pre;"> </span>Floor<br />
62<span class="Apple-tab-span" style="white-space: pre;"> </span>FractionalPart<br />
63<span class="Apple-tab-span" style="white-space: pre;"> </span>Gamma<br />
64<span class="Apple-tab-span" style="white-space: pre;"> </span>GammaRegularized<br />
65<span class="Apple-tab-span" style="white-space: pre;"> </span>GegenbauerC<br />
66<span class="Apple-tab-span" style="white-space: pre;"> </span>Gudermannian<br />
67<span class="Apple-tab-span" style="white-space: pre;"> </span>HankelH1<br />
68<span class="Apple-tab-span" style="white-space: pre;"> </span>HankelH2<br />
69<span class="Apple-tab-span" style="white-space: pre;"> </span>HarmonicNumber<br />
70<span class="Apple-tab-span" style="white-space: pre;"> </span>Haversine<br />
71<span class="Apple-tab-span" style="white-space: pre;"> </span>HeavisideLambda<br />
72<span class="Apple-tab-span" style="white-space: pre;"> </span>HeavisidePi<br />
73<span class="Apple-tab-span" style="white-space: pre;"> </span>HermiteH<br />
74<span class="Apple-tab-span" style="white-space: pre;"> </span>HurwitzLerchPhi<br />
75<span class="Apple-tab-span" style="white-space: pre;"> </span>HurwitzZeta<br />
76<span class="Apple-tab-span" style="white-space: pre;"> </span>Hypergeometric0F1<br />
77<span class="Apple-tab-span" style="white-space: pre;"> </span>Hypergeometric0F1Regularized<br />
78<span class="Apple-tab-span" style="white-space: pre;"> </span>Hypergeometric1F1<br />
79<span class="Apple-tab-span" style="white-space: pre;"> </span>Hypergeometric1F1Regularized<br />
80<span class="Apple-tab-span" style="white-space: pre;"> </span>Hypergeometric2F1<br />
81<span class="Apple-tab-span" style="white-space: pre;"> </span>Hypergeometric2F1Regularized<br />
82<span class="Apple-tab-span" style="white-space: pre;"> </span>HypergeometricU<br />
83<span class="Apple-tab-span" style="white-space: pre;"> </span>Im<br />
84<span class="Apple-tab-span" style="white-space: pre;"> </span>IntegerPart<br />
85<span class="Apple-tab-span" style="white-space: pre;"> </span>InverseGudermannian<br />
86<span class="Apple-tab-span" style="white-space: pre;"> </span>InverseHaversine<br />
87<span class="Apple-tab-span" style="white-space: pre;"> </span>JacobiP<br />
88<span class="Apple-tab-span" style="white-space: pre;"> </span>JacobiZeta<br />
89<span class="Apple-tab-span" style="white-space: pre;"> </span>KelvinBei<br />
90<span class="Apple-tab-span" style="white-space: pre;"> </span>KelvinBer<br />
91<span class="Apple-tab-span" style="white-space: pre;"> </span>KelvinKei<br />
92<span class="Apple-tab-span" style="white-space: pre;"> </span>KelvinKer<br />
93<span class="Apple-tab-span" style="white-space: pre;"> </span>KroneckerDelta<br />
94<span class="Apple-tab-span" style="white-space: pre;"> </span>LaguerreL<br />
95<span class="Apple-tab-span" style="white-space: pre;"> </span>LegendreP<br />
96<span class="Apple-tab-span" style="white-space: pre;"> </span>LegendreQ<br />
97<span class="Apple-tab-span" style="white-space: pre;"> </span>LerchPhi<br />
98<span class="Apple-tab-span" style="white-space: pre;"> </span>Log<br />
99<span class="Apple-tab-span" style="white-space: pre;"> </span>Log10<br />
100<span class="Apple-tab-span" style="white-space: pre;"> </span>Log2<br />
101<span class="Apple-tab-span" style="white-space: pre;"> </span>LogBarnesG<br />
102<span class="Apple-tab-span" style="white-space: pre;"> </span>LogGamma<br />
103<span class="Apple-tab-span" style="white-space: pre;"> </span>LogIntegral<br />
104<span class="Apple-tab-span" style="white-space: pre;"> </span>LogisticSigmoid<br />
105<span class="Apple-tab-span" style="white-space: pre;"> </span>LucasL<br />
106<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuC<br />
107<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCharacteristicA<br />
108<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCharacteristicB<br />
109<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCharacteristicExponent<br />
110<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCPrime<br />
111<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuS<br />
112<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuSPrime<br />
113<span class="Apple-tab-span" style="white-space: pre;"> </span>Max<br />
114<span class="Apple-tab-span" style="white-space: pre;"> </span>Min<br />
115<span class="Apple-tab-span" style="white-space: pre;"> </span>Minus<br />
116<span class="Apple-tab-span" style="white-space: pre;"> </span>Mod<br />
117<span class="Apple-tab-span" style="white-space: pre;"> </span>Multinomial<br />
118<span class="Apple-tab-span" style="white-space: pre;"> </span>ParabolicCylinderD<br />
119<span class="Apple-tab-span" style="white-space: pre;"> </span>Plus<br />
120<span class="Apple-tab-span" style="white-space: pre;"> </span>Pochhammer<br />
121<span class="Apple-tab-span" style="white-space: pre;"> </span>PolyGamma<br />
122<span class="Apple-tab-span" style="white-space: pre;"> </span>PolyLog<br />
123<span class="Apple-tab-span" style="white-space: pre;"> </span>Power<br />
124<span class="Apple-tab-span" style="white-space: pre;"> </span>QBinomial<br />
125<span class="Apple-tab-span" style="white-space: pre;"> </span>QFactorial<br />
126<span class="Apple-tab-span" style="white-space: pre;"> </span>QGamma<br />
127<span class="Apple-tab-span" style="white-space: pre;"> </span>QHypergeometricPFQ<br />
128<span class="Apple-tab-span" style="white-space: pre;"> </span>QPochhammer<br />
129<span class="Apple-tab-span" style="white-space: pre;"> </span>QPolyGamma<br />
130<span class="Apple-tab-span" style="white-space: pre;"> </span>Quotient<br />
131<span class="Apple-tab-span" style="white-space: pre;"> </span>QuotientRemainder<br />
132<span class="Apple-tab-span" style="white-space: pre;"> </span>Re<br />
133<span class="Apple-tab-span" style="white-space: pre;"> </span>Rescale<br />
134<span class="Apple-tab-span" style="white-space: pre;"> </span>RiemannSiegelTheta<br />
135<span class="Apple-tab-span" style="white-space: pre;"> </span>RiemannSiegelZ<br />
136<span class="Apple-tab-span" style="white-space: pre;"> </span>Round<br />
137<span class="Apple-tab-span" style="white-space: pre;"> </span>Sec<br />
138<span class="Apple-tab-span" style="white-space: pre;"> </span>Sech<br />
139<span class="Apple-tab-span" style="white-space: pre;"> </span>Sign<br />
140<span class="Apple-tab-span" style="white-space: pre;"> </span>Sin<br />
141<span class="Apple-tab-span" style="white-space: pre;"> </span>Sinc<br />
142<span class="Apple-tab-span" style="white-space: pre;"> </span>Sinh<br />
143<span class="Apple-tab-span" style="white-space: pre;"> </span>SphericalBesselJ<br />
144<span class="Apple-tab-span" style="white-space: pre;"> </span>SphericalBesselY<br />
145<span class="Apple-tab-span" style="white-space: pre;"> </span>SphericalHankelH1<br />
146<span class="Apple-tab-span" style="white-space: pre;"> </span>SphericalHankelH2<br />
147<span class="Apple-tab-span" style="white-space: pre;"> </span>SphericalHarmonicY<br />
148<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalEigenvalue<br />
149<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalPS<br />
150<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalPSPrime<br />
151<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalQS<br />
152<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalQSPrime<br />
153<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalS1<br />
154<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalS1Prime<br />
155<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalS2<br />
156<span class="Apple-tab-span" style="white-space: pre;"> </span>SpheroidalS2Prime<br />
157<span class="Apple-tab-span" style="white-space: pre;"> </span>Sqrt<br />
158<span class="Apple-tab-span" style="white-space: pre;"> </span>StruveH<br />
159<span class="Apple-tab-span" style="white-space: pre;"> </span>StruveL<br />
160<span class="Apple-tab-span" style="white-space: pre;"> </span>Subtract<br />
161<span class="Apple-tab-span" style="white-space: pre;"> </span>Surd<br />
162<span class="Apple-tab-span" style="white-space: pre;"> </span>Tan<br />
163<span class="Apple-tab-span" style="white-space: pre;"> </span>Tanh<br />
164<span class="Apple-tab-span" style="white-space: pre;"> </span>Times<br />
165<span class="Apple-tab-span" style="white-space: pre;"> </span>UnitBox<br />
166<span class="Apple-tab-span" style="white-space: pre;"> </span>UnitStep<br />
167<span class="Apple-tab-span" style="white-space: pre;"> </span>UnitTriangle<br />
168<span class="Apple-tab-span" style="white-space: pre;"> </span>WhittakerM<br />
169<span class="Apple-tab-span" style="white-space: pre;"> </span>WhittakerW<br />
170<span class="Apple-tab-span" style="white-space: pre;"> </span>Zeta<br />
<br />
<br />
<b>Locked</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>False<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>I<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>List<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>Locked<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>Remove<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>Removed<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>Symbol<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>TooBig<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>True<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>$Aborted<br />
11<span class="Apple-tab-span" style="white-space: pre;"> </span>$BatchOutput<br />
12<span class="Apple-tab-span" style="white-space: pre;"> </span>$CommandLine<br />
13<span class="Apple-tab-span" style="white-space: pre;"> </span>$CreationDate<br />
14<span class="Apple-tab-span" style="white-space: pre;"> </span>$InitialDirectory<br />
15<span class="Apple-tab-span" style="white-space: pre;"> </span>$Input<br />
16<span class="Apple-tab-span" style="white-space: pre;"> </span>$InputStreamMethods<br />
17<span class="Apple-tab-span" style="white-space: pre;"> </span>$LinkSupported<br />
18<span class="Apple-tab-span" style="white-space: pre;"> </span>$MachineType<br />
19<span class="Apple-tab-span" style="white-space: pre;"> </span>$MinorReleaseNumber<br />
20<span class="Apple-tab-span" style="white-space: pre;"> </span>$Off<br />
21<span class="Apple-tab-span" style="white-space: pre;"> </span>$OperatingSystem<br />
22<span class="Apple-tab-span" style="white-space: pre;"> </span>$OutputStreamMethods<br />
23<span class="Apple-tab-span" style="white-space: pre;"> </span>$PipeSupported<br />
24<span class="Apple-tab-span" style="white-space: pre;"> </span>$PrintForms<br />
25<span class="Apple-tab-span" style="white-space: pre;"> </span>$PrintLiteral<br />
26<span class="Apple-tab-span" style="white-space: pre;"> </span>$ProcessorType<br />
27<span class="Apple-tab-span" style="white-space: pre;"> </span>$ProductInformation<br />
28<span class="Apple-tab-span" style="white-space: pre;"> </span>$ReleaseNumber<br />
29<span class="Apple-tab-span" style="white-space: pre;"> </span>$ScriptCommandLine<br />
30<span class="Apple-tab-span" style="white-space: pre;"> </span>$System<br />
31<span class="Apple-tab-span" style="white-space: pre;"> </span>$SystemID<br />
32<span class="Apple-tab-span" style="white-space: pre;"> </span>$SystemMemory<br />
33<span class="Apple-tab-span" style="white-space: pre;"> </span>$SystemWordLength<br />
34<span class="Apple-tab-span" style="white-space: pre;"> </span>$TimeUnit<br />
35<span class="Apple-tab-span" style="white-space: pre;"> </span>$Version<br />
36<span class="Apple-tab-span" style="white-space: pre;"> </span>$VersionNumber<br />
<br />
<br />
<b>HoldFirst</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>AddTo<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>AppendTo<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>AssociateTo<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>AutoRefreshed<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>Catch<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>ClearAttributes<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>CloudEvaluate<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>CloudSave<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>CloudSubmit<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>Context<br />
11<span class="Apple-tab-span" style="white-space: pre;"> </span>Control<br />
12<span class="Apple-tab-span" style="white-space: pre;"> </span>CreateScheduledTask<br />
13<span class="Apple-tab-span" style="white-space: pre;"> </span>Debug<br />
14<span class="Apple-tab-span" style="white-space: pre;"> </span>Decrement<br />
15<span class="Apple-tab-span" style="white-space: pre;"> </span>Delayed<br />
16<span class="Apple-tab-span" style="white-space: pre;"> </span>DialogReturn<br />
17<span class="Apple-tab-span" style="white-space: pre;"> </span>DisplayWithRef<br />
18<span class="Apple-tab-span" style="white-space: pre;"> </span>DivideBy<br />
19<span class="Apple-tab-span" style="white-space: pre;"> </span>Dynamic<br />
20<span class="Apple-tab-span" style="white-space: pre;"> </span>Inactivate<br />
21<span class="Apple-tab-span" style="white-space: pre;"> </span>Inactive<br />
22<span class="Apple-tab-span" style="white-space: pre;"> </span>Increment<br />
23<span class="Apple-tab-span" style="white-space: pre;"> </span>KeyDropFrom<br />
24<span class="Apple-tab-span" style="white-space: pre;"> </span>Message<br />
25<span class="Apple-tab-span" style="white-space: pre;"> </span>MessageName<br />
26<span class="Apple-tab-span" style="white-space: pre;"> </span>MessagePacket<br />
27<span class="Apple-tab-span" style="white-space: pre;"> </span>NCache<br />
28<span class="Apple-tab-span" style="white-space: pre;"> </span>Pattern<br />
29<span class="Apple-tab-span" style="white-space: pre;"> </span>PreDecrement<br />
30<span class="Apple-tab-span" style="white-space: pre;"> </span>PreIncrement<br />
31<span class="Apple-tab-span" style="white-space: pre;"> </span>PrependTo<br />
32<span class="Apple-tab-span" style="white-space: pre;"> </span>Reap<br />
33<span class="Apple-tab-span" style="white-space: pre;"> </span>RefBox<br />
34<span class="Apple-tab-span" style="white-space: pre;"> </span>Refresh<br />
35<span class="Apple-tab-span" style="white-space: pre;"> </span>RepeatedTiming<br />
36<span class="Apple-tab-span" style="white-space: pre;"> </span>ResponseForm<br />
37<span class="Apple-tab-span" style="white-space: pre;"> </span>RuleCondition<br />
38<span class="Apple-tab-span" style="white-space: pre;"> </span>RunScheduledTask<br />
39<span class="Apple-tab-span" style="white-space: pre;"> </span>Set<br />
40<span class="Apple-tab-span" style="white-space: pre;"> </span>SetAttributes<br />
41<span class="Apple-tab-span" style="white-space: pre;"> </span>Stack<br />
42<span class="Apple-tab-span" style="white-space: pre;"> </span>SubtractFrom<br />
43<span class="Apple-tab-span" style="white-space: pre;"> </span>TableViewBox<br />
44<span class="Apple-tab-span" style="white-space: pre;"> </span>TimesBy<br />
45<span class="Apple-tab-span" style="white-space: pre;"> </span>Unset<br />
46<span class="Apple-tab-span" style="white-space: pre;"> </span>UpSet<br />
47<span class="Apple-tab-span" style="white-space: pre;"> </span>UsingFrontEnd<br />
48<span class="Apple-tab-span" style="white-space: pre;"> </span>WaitUntil<br />
<br />
<br />
<b>HoldRest</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>Assuming<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>Button<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>DumpSave<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>DynamicWrapper<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>DynamicWrapperBox<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>FirstCase<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>FirstPosition<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>If<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>MenuItem<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>PatternTest<br />
11<span class="Apple-tab-span" style="white-space: pre;"> </span>Quantity<br />
12<span class="Apple-tab-span" style="white-space: pre;"> </span>RuleDelayed<br />
13<span class="Apple-tab-span" style="white-space: pre;"> </span>Save<br />
14<span class="Apple-tab-span" style="white-space: pre;"> </span>SelectFirst<br />
15<span class="Apple-tab-span" style="white-space: pre;"> </span>Switch<br />
<br />
<br />
<b>HoldAll</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>AbortProtect<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>AbsoluteTiming<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>And<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>Animate<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>Arrow3DBox<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>ArrowBox<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>Attributes<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>BezierCurve3DBox<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>BezierCurveBox<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>Block<br />
11<span class="Apple-tab-span" style="white-space: pre;"> </span>BlockRandom<br />
12<span class="Apple-tab-span" style="white-space: pre;"> </span>BSplineCurve3DBox<br />
13<span class="Apple-tab-span" style="white-space: pre;"> </span>BSplineCurveBox<br />
14<span class="Apple-tab-span" style="white-space: pre;"> </span>BSplineSurface3DBox<br />
15<span class="Apple-tab-span" style="white-space: pre;"> </span>CancelButton<br />
16<span class="Apple-tab-span" style="white-space: pre;"> </span>Check<br />
17<span class="Apple-tab-span" style="white-space: pre;"> </span>CheckAbort<br />
18<span class="Apple-tab-span" style="white-space: pre;"> </span>CheckAll<br />
19<span class="Apple-tab-span" style="white-space: pre;"> </span>ChoiceButtons<br />
20<span class="Apple-tab-span" style="white-space: pre;"> </span>CircleBox<br />
21<span class="Apple-tab-span" style="white-space: pre;"> </span>Clear<br />
22<span class="Apple-tab-span" style="white-space: pre;"> </span>ClearAll<br />
23<span class="Apple-tab-span" style="white-space: pre;"> </span>Compile<br />
24<span class="Apple-tab-span" style="white-space: pre;"> </span>CompiledFunction<br />
25<span class="Apple-tab-span" style="white-space: pre;"> </span>CompoundExpression<br />
26<span class="Apple-tab-span" style="white-space: pre;"> </span>Condition<br />
27<span class="Apple-tab-span" style="white-space: pre;"> </span>ConeBox<br />
28<span class="Apple-tab-span" style="white-space: pre;"> </span>ConicHullRegion3DBox<br />
29<span class="Apple-tab-span" style="white-space: pre;"> </span>ConicHullRegionBox<br />
30<span class="Apple-tab-span" style="white-space: pre;"> </span>ConsoleMessage<br />
31<span class="Apple-tab-span" style="white-space: pre;"> </span>ContinuedFractionK<br />
32<span class="Apple-tab-span" style="white-space: pre;"> </span>ContinuousTask<br />
33<span class="Apple-tab-span" style="white-space: pre;"> </span>ContourPlot<br />
34<span class="Apple-tab-span" style="white-space: pre;"> </span>ContourPlot3D<br />
35<span class="Apple-tab-span" style="white-space: pre;"> </span>ControlActive<br />
36<span class="Apple-tab-span" style="white-space: pre;"> </span>ControllerManipulate<br />
37<span class="Apple-tab-span" style="white-space: pre;"> </span>CuboidBox<br />
38<span class="Apple-tab-span" style="white-space: pre;"> </span>CylinderBox<br />
39<span class="Apple-tab-span" style="white-space: pre;"> </span>DefaultButton<br />
40<span class="Apple-tab-span" style="white-space: pre;"> </span>DefaultValues<br />
41<span class="Apple-tab-span" style="white-space: pre;"> </span>Defer<br />
42<span class="Apple-tab-span" style="white-space: pre;"> </span>Definition<br />
43<span class="Apple-tab-span" style="white-space: pre;"> </span>DensityPlot<br />
44<span class="Apple-tab-span" style="white-space: pre;"> </span>Dialog<br />
45<span class="Apple-tab-span" style="white-space: pre;"> </span>DialogInput<br />
46<span class="Apple-tab-span" style="white-space: pre;"> </span>DiskBox<br />
47<span class="Apple-tab-span" style="white-space: pre;"> </span>Do<br />
48<span class="Apple-tab-span" style="white-space: pre;"> </span>DownValues<br />
49<span class="Apple-tab-span" style="white-space: pre;"> </span>DynamicBox<br />
50<span class="Apple-tab-span" style="white-space: pre;"> </span>DynamicModule<br />
51<span class="Apple-tab-span" style="white-space: pre;"> </span>DynamicModuleBox<br />
52<span class="Apple-tab-span" style="white-space: pre;"> </span>Exists<br />
53<span class="Apple-tab-span" style="white-space: pre;"> </span>FileName<br />
54<span class="Apple-tab-span" style="white-space: pre;"> </span>FilledCurveBox<br />
55<span class="Apple-tab-span" style="white-space: pre;"> </span>FindArgMax<br />
56<span class="Apple-tab-span" style="white-space: pre;"> </span>FindArgMin<br />
57<span class="Apple-tab-span" style="white-space: pre;"> </span>FindMaximum<br />
58<span class="Apple-tab-span" style="white-space: pre;"> </span>FindMaxValue<br />
59<span class="Apple-tab-span" style="white-space: pre;"> </span>FindMinimum<br />
60<span class="Apple-tab-span" style="white-space: pre;"> </span>FindMinValue<br />
61<span class="Apple-tab-span" style="white-space: pre;"> </span>FindRoot<br />
62<span class="Apple-tab-span" style="white-space: pre;"> </span>For<br />
63<span class="Apple-tab-span" style="white-space: pre;"> </span>ForAll<br />
64<span class="Apple-tab-span" style="white-space: pre;"> </span>FormatValues<br />
65<span class="Apple-tab-span" style="white-space: pre;"> </span>FullDefinition<br />
66<span class="Apple-tab-span" style="white-space: pre;"> </span>Function<br />
67<span class="Apple-tab-span" style="white-space: pre;"> </span>GeometricTransformation3DBox<br />
68<span class="Apple-tab-span" style="white-space: pre;"> </span>GeometricTransformationBox<br />
69<span class="Apple-tab-span" style="white-space: pre;"> </span>Graphics3DBox<br />
70<span class="Apple-tab-span" style="white-space: pre;"> </span>GraphicsBox<br />
71<span class="Apple-tab-span" style="white-space: pre;"> </span>GraphicsComplex3DBox<br />
72<span class="Apple-tab-span" style="white-space: pre;"> </span>GraphicsComplexBox<br />
73<span class="Apple-tab-span" style="white-space: pre;"> </span>GraphicsGroup3DBox<br />
74<span class="Apple-tab-span" style="white-space: pre;"> </span>GraphicsGroupBox<br />
75<span class="Apple-tab-span" style="white-space: pre;"> </span>GraphPropertyDistribution<br />
76<span class="Apple-tab-span" style="white-space: pre;"> </span>HexahedronBox<br />
77<span class="Apple-tab-span" style="white-space: pre;"> </span>Hold<br />
78<span class="Apple-tab-span" style="white-space: pre;"> </span>HoldForm<br />
79<span class="Apple-tab-span" style="white-space: pre;"> </span>HoldPattern<br />
80<span class="Apple-tab-span" style="white-space: pre;"> </span>ImplicitRegion<br />
81<span class="Apple-tab-span" style="white-space: pre;"> </span>Information<br />
82<span class="Apple-tab-span" style="white-space: pre;"> </span>Inset3DBox<br />
83<span class="Apple-tab-span" style="white-space: pre;"> </span>InsetBox<br />
84<span class="Apple-tab-span" style="white-space: pre;"> </span>Interpretation<br />
85<span class="Apple-tab-span" style="white-space: pre;"> </span>JoinedCurveBox<br />
86<span class="Apple-tab-span" style="white-space: pre;"> </span>KnownUnitQ<br />
87<span class="Apple-tab-span" style="white-space: pre;"> </span>Line3DBox<br />
88<span class="Apple-tab-span" style="white-space: pre;"> </span>LineBox<br />
89<span class="Apple-tab-span" style="white-space: pre;"> </span>LineIntegralConvolutionPlot<br />
90<span class="Apple-tab-span" style="white-space: pre;"> </span>Literal<br />
91<span class="Apple-tab-span" style="white-space: pre;"> </span>LogLinearPlot<br />
92<span class="Apple-tab-span" style="white-space: pre;"> </span>LogLogPlot<br />
93<span class="Apple-tab-span" style="white-space: pre;"> </span>LogPlot<br />
94<span class="Apple-tab-span" style="white-space: pre;"> </span>Manipulate<br />
95<span class="Apple-tab-span" style="white-space: pre;"> </span>MatchLocalNameQ<br />
96<span class="Apple-tab-span" style="white-space: pre;"> </span>MaxMemoryUsed<br />
97<span class="Apple-tab-span" style="white-space: pre;"> </span>MemoryConstrained<br />
98<span class="Apple-tab-span" style="white-space: pre;"> </span>Messages<br />
99<span class="Apple-tab-span" style="white-space: pre;"> </span>Module<br />
100<span class="Apple-tab-span" style="white-space: pre;"> </span>Monitor<br />
101<span class="Apple-tab-span" style="white-space: pre;"> </span>Nand<br />
102<span class="Apple-tab-span" style="white-space: pre;"> </span>NIntegrate<br />
103<span class="Apple-tab-span" style="white-space: pre;"> </span>Nor<br />
104<span class="Apple-tab-span" style="white-space: pre;"> </span>NProduct<br />
105<span class="Apple-tab-span" style="white-space: pre;"> </span>NSum<br />
106<span class="Apple-tab-span" style="white-space: pre;"> </span>NValues<br />
107<span class="Apple-tab-span" style="white-space: pre;"> </span>Off<br />
108<span class="Apple-tab-span" style="white-space: pre;"> </span>On<br />
109<span class="Apple-tab-span" style="white-space: pre;"> </span>Or<br />
110<span class="Apple-tab-span" style="white-space: pre;"> </span>OwnValues<br />
111<span class="Apple-tab-span" style="white-space: pre;"> </span>ParametricPlot<br />
112<span class="Apple-tab-span" style="white-space: pre;"> </span>ParametricPlot3D<br />
113<span class="Apple-tab-span" style="white-space: pre;"> </span>ParametricRegion<br />
114<span class="Apple-tab-span" style="white-space: pre;"> </span>Piecewise<br />
115<span class="Apple-tab-span" style="white-space: pre;"> </span>Play<br />
116<span class="Apple-tab-span" style="white-space: pre;"> </span>Plot<br />
117<span class="Apple-tab-span" style="white-space: pre;"> </span>Plot3D<br />
118<span class="Apple-tab-span" style="white-space: pre;"> </span>Point3DBox<br />
119<span class="Apple-tab-span" style="white-space: pre;"> </span>PointBox<br />
120<span class="Apple-tab-span" style="white-space: pre;"> </span>PolarPlot<br />
121<span class="Apple-tab-span" style="white-space: pre;"> </span>Polygon3DBox<br />
122<span class="Apple-tab-span" style="white-space: pre;"> </span>PolygonBox<br />
123<span class="Apple-tab-span" style="white-space: pre;"> </span>PrismBox<br />
124<span class="Apple-tab-span" style="white-space: pre;"> </span>Product<br />
125<span class="Apple-tab-span" style="white-space: pre;"> </span>Protect<br />
126<span class="Apple-tab-span" style="white-space: pre;"> </span>PyramidBox<br />
127<span class="Apple-tab-span" style="white-space: pre;"> </span>Quiet<br />
128<span class="Apple-tab-span" style="white-space: pre;"> </span>Raster3DBox<br />
129<span class="Apple-tab-span" style="white-space: pre;"> </span>RasterBox<br />
130<span class="Apple-tab-span" style="white-space: pre;"> </span>RectangleBox<br />
131<span class="Apple-tab-span" style="white-space: pre;"> </span>RegionPlot<br />
132<span class="Apple-tab-span" style="white-space: pre;"> </span>RegionPlot3D<br />
133<span class="Apple-tab-span" style="white-space: pre;"> </span>Remove<br />
134<span class="Apple-tab-span" style="white-space: pre;"> </span>RevolutionPlot3D<br />
135<span class="Apple-tab-span" style="white-space: pre;"> </span>SampledSoundFunction<br />
136<span class="Apple-tab-span" style="white-space: pre;"> </span>ScheduledTask<br />
137<span class="Apple-tab-span" style="white-space: pre;"> </span>ScheduledTaskObject<br />
138<span class="Apple-tab-span" style="white-space: pre;"> </span>SetDelayed<br />
139<span class="Apple-tab-span" style="white-space: pre;"> </span>SphereBox<br />
140<span class="Apple-tab-span" style="white-space: pre;"> </span>SphericalPlot3D<br />
141<span class="Apple-tab-span" style="white-space: pre;"> </span>StackBegin<br />
142<span class="Apple-tab-span" style="white-space: pre;"> </span>StackComplete<br />
143<span class="Apple-tab-span" style="white-space: pre;"> </span>StackInhibit<br />
144<span class="Apple-tab-span" style="white-space: pre;"> </span>StreamDensityPlot<br />
145<span class="Apple-tab-span" style="white-space: pre;"> </span>StreamPlot<br />
146<span class="Apple-tab-span" style="white-space: pre;"> </span>SubValues<br />
147<span class="Apple-tab-span" style="white-space: pre;"> </span>Sum<br />
148<span class="Apple-tab-span" style="white-space: pre;"> </span>SurvivalModel<br />
149<span class="Apple-tab-span" style="white-space: pre;"> </span>Table<br />
150<span class="Apple-tab-span" style="white-space: pre;"> </span>TagSet<br />
151<span class="Apple-tab-span" style="white-space: pre;"> </span>TagSetDelayed<br />
152<span class="Apple-tab-span" style="white-space: pre;"> </span>TagUnset<br />
153<span class="Apple-tab-span" style="white-space: pre;"> </span>TetrahedronBox<br />
154<span class="Apple-tab-span" style="white-space: pre;"> </span>Text3DBox<br />
155<span class="Apple-tab-span" style="white-space: pre;"> </span>TextBox<br />
156<span class="Apple-tab-span" style="white-space: pre;"> </span>TimeConstrained<br />
157<span class="Apple-tab-span" style="white-space: pre;"> </span>Timing<br />
158<span class="Apple-tab-span" style="white-space: pre;"> </span>Trace<br />
159<span class="Apple-tab-span" style="white-space: pre;"> </span>TraceDialog<br />
160<span class="Apple-tab-span" style="white-space: pre;"> </span>TracePrint<br />
161<span class="Apple-tab-span" style="white-space: pre;"> </span>TraceScan<br />
162<span class="Apple-tab-span" style="white-space: pre;"> </span>TubeBezierCurveBox<br />
163<span class="Apple-tab-span" style="white-space: pre;"> </span>TubeBox<br />
164<span class="Apple-tab-span" style="white-space: pre;"> </span>TubeBSplineCurveBox<br />
165<span class="Apple-tab-span" style="white-space: pre;"> </span>Unprotect<br />
166<span class="Apple-tab-span" style="white-space: pre;"> </span>UpSetDelayed<br />
167<span class="Apple-tab-span" style="white-space: pre;"> </span>UpValues<br />
168<span class="Apple-tab-span" style="white-space: pre;"> </span>ValueQ<br />
169<span class="Apple-tab-span" style="white-space: pre;"> </span>VectorDensityPlot<br />
170<span class="Apple-tab-span" style="white-space: pre;"> </span>VectorPlot<br />
171<span class="Apple-tab-span" style="white-space: pre;"> </span>VectorPlot3D<br />
172<span class="Apple-tab-span" style="white-space: pre;"> </span>WhenEvent<br />
173<span class="Apple-tab-span" style="white-space: pre;"> </span>Which<br />
174<span class="Apple-tab-span" style="white-space: pre;"> </span>While<br />
175<span class="Apple-tab-span" style="white-space: pre;"> </span>With<br />
176<span class="Apple-tab-span" style="white-space: pre;"> </span>$ConditionHold<br />
177<span class="Apple-tab-span" style="white-space: pre;"> </span>$Failed<br />
<br />
<br />
<b>HoldAllComplete</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>Assert<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>ColorQ<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>DebugTag<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>DisplayWith<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>DynamicImage<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>EvaluationData<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>GenerateHTTPResponse<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>HoldComplete<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>InterpretationBox<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>Lookup<br />
11<span class="Apple-tab-span" style="white-space: pre;"> </span>MakeBoxes<br />
12<span class="Apple-tab-span" style="white-space: pre;"> </span>ParametricFunction<br />
13<span class="Apple-tab-span" style="white-space: pre;"> </span>Parenthesize<br />
14<span class="Apple-tab-span" style="white-space: pre;"> </span>PreemptProtect<br />
15<span class="Apple-tab-span" style="white-space: pre;"> </span>SystemException<br />
16<span class="Apple-tab-span" style="white-space: pre;"> </span>Unevaluated<br />
<br />
<br />
<b>NHoldFirst</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticTheta<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticThetaPrime<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>FrontEndValueCache<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuC<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCharacteristicA<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCharacteristicB<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCPrime<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuS<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuSPrime<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>QPolyGamma<br />
<br />
<br />
<b>NHoldFirst</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticTheta<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>EllipticThetaPrime<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>FrontEndValueCache<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuC<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCharacteristicA<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCharacteristicB<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuCPrime<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuS<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>MathieuSPrime<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>QPolyGamma<br />
<br />
<br />
<b>NHoldRest</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>Drop<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>Extract<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>GraphicsComplex<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>HeldPart<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>Indexed<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>Overscript<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>Part<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>Quantity<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>Subscript<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>Subsuperscript<br />
11<span class="Apple-tab-span" style="white-space: pre;"> </span>Superscript<br />
12<span class="Apple-tab-span" style="white-space: pre;"> </span>Take<br />
13<span class="Apple-tab-span" style="white-space: pre;"> </span>TakeDrop<br />
14<span class="Apple-tab-span" style="white-space: pre;"> </span>Underoverscript<br />
15<span class="Apple-tab-span" style="white-space: pre;"> </span>Underscript<br />
<br />
<br />
<b>NHoldAll</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>AlgebraicNumber<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>BarabasiAlbertGraphDistribution<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>BernoulliGraphDistribution<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>C<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>CompiledFunction<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>Cycles<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>DateObject<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>DegreeGraphDistribution<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>Derivative<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>DifferenceRoot<br />
11<span class="Apple-tab-span" style="white-space: pre;"> </span>DifferentialRoot<br />
12<span class="Apple-tab-span" style="white-space: pre;"> </span>DivisorSigma<br />
13<span class="Apple-tab-span" style="white-space: pre;"> </span>DivisorSum<br />
14<span class="Apple-tab-span" style="white-space: pre;"> </span>Graph<br />
15<span class="Apple-tab-span" style="white-space: pre;"> </span>Graph3D<br />
16<span class="Apple-tab-span" style="white-space: pre;"> </span>InverseFunction<br />
17<span class="Apple-tab-span" style="white-space: pre;"> </span>LibraryFunction<br />
18<span class="Apple-tab-span" style="white-space: pre;"> </span>OptimumFlowData<br />
19<span class="Apple-tab-span" style="white-space: pre;"> </span>PathGraph<br />
20<span class="Apple-tab-span" style="white-space: pre;"> </span>PriceGraphDistribution<br />
21<span class="Apple-tab-span" style="white-space: pre;"> </span>Root<br />
22<span class="Apple-tab-span" style="white-space: pre;"> </span>ShortestPathFunction<br />
23<span class="Apple-tab-span" style="white-space: pre;"> </span>Slot<br />
24<span class="Apple-tab-span" style="white-space: pre;"> </span>SlotSequence<br />
25<span class="Apple-tab-span" style="white-space: pre;"> </span>SpatialGraphDistribution<br />
26<span class="Apple-tab-span" style="white-space: pre;"> </span>SurvivalModel<br />
27<span class="Apple-tab-span" style="white-space: pre;"> </span>TemporalData<br />
28<span class="Apple-tab-span" style="white-space: pre;"> </span>TimeObject<br />
29<span class="Apple-tab-span" style="white-space: pre;"> </span>TreeGraph<br />
30<span class="Apple-tab-span" style="white-space: pre;"> </span>UniformGraphDistribution<br />
31<span class="Apple-tab-span" style="white-space: pre;"> </span>WattsStrogatzGraphDistribution<br />
<br />
<br />
<b>SequenceHold</b><br />
<b><br /></b>
1<span class="Apple-tab-span" style="white-space: pre;"> </span>AbsoluteTiming<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>RepeatedTiming<br />
3<span class="Apple-tab-span" style="white-space: pre;"> </span>Rule<br />
4<span class="Apple-tab-span" style="white-space: pre;"> </span>RuleDelayed<br />
5<span class="Apple-tab-span" style="white-space: pre;"> </span>Set<br />
6<span class="Apple-tab-span" style="white-space: pre;"> </span>SetDelayed<br />
7<span class="Apple-tab-span" style="white-space: pre;"> </span>TagSet<br />
8<span class="Apple-tab-span" style="white-space: pre;"> </span>TagSetDelayed<br />
9<span class="Apple-tab-span" style="white-space: pre;"> </span>Timing<br />
10<span class="Apple-tab-span" style="white-space: pre;"> </span>UpSet<br />
11<span class="Apple-tab-span" style="white-space: pre;"> </span>UpSetDelayed<br />
<br />
<br />
<b>Temporary</b><br />
<br />
1<span class="Apple-tab-span" style="white-space: pre;"> </span>Null$<br />
2<span class="Apple-tab-span" style="white-space: pre;"> </span>\[FormalX]$<br />
<br />
<br />
<b>Stub</b><br />
<b><br /></b>
{}<br />
<br />
<br />
<br /></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-27413196065818469692016-01-18T17:40:00.001-05:002016-01-18T17:40:06.965-05:00Rule & Pattern Programming Example: Run-Length Encoding<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
In Sal Mangano's excellent <i>Mathematica Cookbook</i>, he says this is one of his favorite functions due to its concise use of rule-based pattern-matching programming.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>runLengthEncode@l_List:=Map[{#,1}&,l]//.{head___,{x_,n_},{x_,m_},tail___}:>{head,{x,n+m},tail}</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>runLengthEncode@{1,1,2,2,2,1,3,3,3,3}</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{{1,2},{2,3},{1,1},{3,4}}</span><br />
<br />
How does this concise rule & pattern program work? The "Map" clause puts a template for the run-length encoding format, {symbol, run-length}, at every expression in the List, then the ReplaceRepeated "//." clause works its magic by repeatedly detecting duplicate consecutive symbols and incrementing their run-length counter until no consecutive duplicate is detected, at which point it moves to the next symbol.<br />
<br />
How can we see this? A critical step is where the {symbol, run-length} initial template is set up for each symbol in the List , which is simply this fundamental operation of Function (here in its abbreviated form):<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>{#,1}&@n</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{n,1}</span><br />
<br />
Trace is helpful but can be tedious to parse. One way to reveal one-liner mechanisms is to use a symbolic input. A second way, just as with longer programs, is to break them apart and step through them. You just have to figure out how to divide up the key steps. Here is the first key step for this one, mapping the initial template at each symbol:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Map[{#,1}&,{1,1,2,2,2,1,3,3,3,3}]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{{1,1},{1,1},{2,1},{2,1},{2,1},{1,1},{3,1},{3,1},{3,1},{3,1}}</span><br />
<br />
And the second key step is the consolidation of the counts:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>%//.{head___,{x_,n_},{x_,m_},tail___}:>{head,{x,n+m},tail}</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{{1,2},{2,3},{1,1},{3,4}}</span><br />
<br />
And here is the Trace.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>runLengthEncode@{1,1,2,2,2,1,3,3,3,3}//Trace</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{runLengthEncode[{1,1,2,2,2,1,3,3,3,3}],({#1,1}&)/@{1,1,2,2,2,1,3,3,3,3}//. {head___,{Removed[x]:_,n_},{Removed[x]:_,m_},tail___}:>{head,{Removed[x],n+m},tail},{({#1,1}&)/@{1,1,2,2,2,1,3,3,3,3},{({#1,1}&)[1],({#1,1}&)[1],({#1,1}&)[2],({#1,1}&)[2],({#1,1}&)[2],({#1,1}&)[1],({#1,1}&)[3],({#1,1}&)[3],({#1,1}&)[3],({#1,1}&)[3]},{({#1,1}&)[1],{1,1}},{({#1,1}&)[1],{1,1}},{({#1,1}&)[2],{2,1}},{({#1,1}&)[2],{2,1}},{({#1,1}&)[2],{2,1}},{({#1,1}&)[1],{1,1}},{({#1,1}&)[3],{3,1}},{({#1,1}&)[3],{3,1}},{({#1,1}&)[3],{3,1}},{({#1,1}&)[3],{3,1}},{{1,1},{1,1},{2,1},{2,1},{2,1},{1,1},{3,1},{3,1},{3,1},{3,1}}},{{head___,{Removed[x]:_,n_},{Removed[x]:_,m_},tail___}:>{head,{Removed[x],n+m},tail},{head___,{Removed[x]:_,n_},{Removed[x]:_,m_},tail___}:>{head,{Removed[x],n+m},tail}},{{1,1},{1,1},{2,1},{2,1},{2,1},{1,1},{3,1},{3,1},{3,1},{3,1}}//. {head___,{Removed[x]:_,n_},{Removed[x]:_,m_},tail___}:>{head,{Removed[x],n+m},tail},{{1,2},{2,3},{1,1},{3,4}}}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ss&ref=ss_til&ad_type=product_link&tracking_id=concordpoetry-20&marketplace=amazon&region=US&placement=0596520999&asins=0596520999&linkId=D26NEBYLP6E4CJLA&show_border=true&link_opens_in_new_window=true" style="height: 240px; width: 120px;">
</iframe></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-86757788817651296102015-12-20T13:11:00.004-05:002016-08-15T10:48:54.253-04:00Apply a List of Functions to a Corresponding List of Arguments<div dir="ltr" style="text-align: left;" trbidi="on">
Here are two ways to apply a List of functions to a List of arguments. The first method, from Maeder, uses Inner. Note the use of a purely symbolic example to reveal what Inner is doing.<br />
<br />
<b style="font-family: 'courier new', courier, monospace;">Inner[#@#2&,{f1,f2,f3,f4},{arg1,arg2,arg3,arg4},List]</b><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: "courier new" , "courier" , monospace;">{f1[arg1],f2[arg2],f3[arg3],f4[arg4]}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>In #1@# &, Slot1 (#1 or abbreviated #) pulls an argument from the first List, which are the functions, and Slot2 (#2 where you do need the "2") pulls an argument from the second List, which are the arguments.<br />
<br />
If you wanted to apply a second function, g, to the results rather than just listing them, Inner provides for that:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Inner[#@#2&,{f1,f2,f3,f4},{arg1,arg2,arg3,arg4},g]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: "courier new" , "courier" , monospace;">g[f1[arg1],f2[arg2],f3[arg3],f4[arg4]]</span><br />
<br />
The second method, from my <i>Mathematica </i>teacher Harry Calkins, uses MapThread, which requires wrapping the function List and the argument List together in a List:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>(arguments={{a,b,c},{d,e,f},{r,s,t},{u,v,w}});</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span><span style="font-family: "courier new" , "courier" , monospace;"><b>(functions={3 #&,3+#&,#/2&,Plus@@@Partition[#,2,1,{1,1},#]&});</b></span><br />
<br />
He gave an example using some built-in functions and structured the functions and arguments in matrices.By enclosing the assignments in parentheses he showed them as matrices without inadvertently making the assignment to the MatrixForm-formatted List.<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span><span style="font-family: "courier new" , "courier" , monospace;"><b>arguments</b><b>//MatrixForm</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>functions</b><b>//MatrixForm</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>(results=MapThread[#1@#2&,{functions,arguments}])//MatrixForm</b></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-3cppCzinRGA/VnbtanxGKZI/AAAAAAAAD5g/2LjqGIhXHNM/s1600/Apply_a_List_of_Functions_to_a_Corresponding_List_of_Arguments.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://4.bp.blogspot.com/-3cppCzinRGA/VnbtanxGKZI/AAAAAAAAD5g/2LjqGIhXHNM/s1600/Apply_a_List_of_Functions_to_a_Corresponding_List_of_Arguments.png" /></a></div>
<div>
<br /></div>
</div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-2105888615904641392015-12-11T14:19:00.003-05:002015-12-11T14:25:09.468-05:00String Processing: Validate Email Address Format, Part 1<div dir="ltr" style="text-align: left;" trbidi="on">
Here are three approaches to predicates validating that an email address has an "@" sign and a period ".". A true email address validator is much more complicated, so these functions are merely to illustrate some String processing techniques. That said, I did use the first approach to validate thousands of email addresses and flush out bad ones.<br />
<br />
The first predicate uses StringMatchQ and the essential idea is to give StringMatchQ a String pattern representing:<br />
<ol style="text-align: left;">
<li>An "@" wildcard for at least one but an unknown number of characters</li>
<li>Followed by the "@" sign as used in an email address to separate localpart from domain</li>
<li>Followed by the wildcard again</li>
<li>Followed by the period "." used to separate the mail server name from the top-level domain</li>
<li>Followed by the wildcard</li>
</ol>
Note that an asterisk wildcard ("*") would not be suitable since each position in the pattern has at least one character.<br />
<br />
The first variation illustrates the use of Verbatim, which tells <i>Mathematica</i> to treat the middle "@" sign as an "@" sign (read it "verbatim") and not as a pattern wildcard.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@emailAddressQ1;emailAddressQ1@aString_String:=StringMatchQ[aString,"@"~~Verbatim@"@"~~"@.@"]</b></span><br />
<br />
The second variation of StringMatchQ does the same thing but more concisely, using a double backslash. The first backslash tells <i>Mathematica</i> to treat the second one as an 'escape' character, which then tell <i>Mathematica</i> to treat the "@" sign as an "@" sign and not as a wildcard.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@emailAddressQ1a;emailAddressQ1a@aString_String:=StringMatchQ[aString,"*\\@*.*"]</b></span><br />
<br />
The second basic approach uses StringContainsQ to detect the presence of the "@" sign and period "." in the address. Since it doesn't require additional characters in the correct positions as does the first approach, it is not as good a validator.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@emailAddressQ2;emailAddressQ2@aString_String:=StringContainsQ[aString,"@"]&&StringContainsQ[aString,"."]</b></span><br />
<br />
The third approach uses StringFreeQ to see if the address has no "@" sign and period ".", and some logic, and suffers the same limitation as the second approach.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@emailAddressQ3;emailAddressQ3@aString_String:=Not[StringFreeQ[aString,"@"]&&StringFreeQ[aString,"."]]</b></span><br />
<br />
<h3 style="text-align: left;">
Test Cases</h3>
<br />
The test cases are 1) valid email format, 2) missing "@" sign, 3) missing "." and 4) missing both "@" and ".".<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>testCases={"abc@dwxy.anything","abcdwxy.anything","abc@dwxyanything","abcdwxyanything"};</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>emailAddressQ1/@testCases</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{True,False,False,False}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>emailAddressQ1a/@testCases</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{True,False,False,False}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>emailAddressQ2/@testCases</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{True,False,False,False}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>emailAddressQ3/@testCases</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{True,True,True,False}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
Aha! The test cases flushed out a logic error. The way the emailAddressQ3 function is written with the AND (&&) conjunction between the two clauses, only if both StringMatchQ tests are FALSE will AND return FALSE and be negated by NOT into TRUE. We need to change the AND to OR so that if either "@" or "." are missing, the OR returns TRUE and is negated by NOT into FALSE.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@emailAddressQ4;emailAddressQ4@aString_String:=Not[StringFreeQ[aString,"@"]||StringFreeQ[aString,"."]]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>emailAddressQ4/@testCases</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{True,False,False,False}</span><br />
<br /></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-30288030290425270542015-12-03T23:01:00.001-05:002015-12-06T10:20:55.734-05:00Grid - Partition - Identify Primes with Formatting<div dir="ltr" style="text-align: left;" trbidi="on">
Starting with an example from Mangano, Mathematica Cookbook, and the Doc Center, here are examples of using Partition with Grid and formatting to highlight the values of interest.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Grid@Partition[If[PrimeQ@#,Framed[#,FrameStyle->Red],#]&/@Range@200,20]</b></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-he5-pcMWhGs/VmQGKrqWHzI/AAAAAAAAD48/cYqV_wJX1-0/s1600/Grid-Partition-Identify%2BAll%2BPrimes%2BUp%2Bto%2B500.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-he5-pcMWhGs/VmQGKrqWHzI/AAAAAAAAD48/cYqV_wJX1-0/s1600/Grid-Partition-Identify%2BAll%2BPrimes%2BUp%2Bto%2B500.png" /></a></div>
<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Grid@Partition[If[PrimeQ@#,Style[#,FontColor->Red],#]&/@Range@200,20]</b></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-57iPWTGamR4/VmEMLpiIbII/AAAAAAAAD4A/NjHAhTNh7hk/s1600/Grid-Partition-Identify%2BAll%2BPrimes%2BUp%2Bto%2B500-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-57iPWTGamR4/VmEMLpiIbII/AAAAAAAAD4A/NjHAhTNh7hk/s1600/Grid-Partition-Identify%2BAll%2BPrimes%2BUp%2Bto%2B500-2.png" /></a></div>
<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Grid@Partition[If[PrimeQ@#,Style[#,FontColor->Red,FontWeight->Bold],Style[#,FontColor->Gray]]&/@Range@200,20]</b></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-Biq2Lw4oSLo/VmEMsgiW7BI/AAAAAAAAD4I/MqTzxRAIK6U/s1600/Grid-Partition-Identify%2BAll%2BPrimes%2BUp%2Bto%2B500-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-Biq2Lw4oSLo/VmEMsgiW7BI/AAAAAAAAD4I/MqTzxRAIK6U/s1600/Grid-Partition-Identify%2BAll%2BPrimes%2BUp%2Bto%2B500-3.png" /></a></div>
<br />
<br />
This sets up a clickable square from which you can interactively choose a color.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@highlightColor;ColorSetter@Dynamic@highlightColor</b></span><br />
<br />
Then the selected color is used here:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Grid@Partition[If[PrimeQ@#,Style[#,FontColor->highlightColor,FontSize->16,FontWeight->Bold],Style[#,FontColor->Gray]]&/@Range@200,20]</b></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-V79YJA4l6SI/VmENUGzudTI/AAAAAAAAD4U/6UlsdomZ34U/s1600/Grid-Partition-Identify%2BAll%2BPrimes%2BUp%2Bto%2B500-4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-V79YJA4l6SI/VmENUGzudTI/AAAAAAAAD4U/6UlsdomZ34U/s1600/Grid-Partition-Identify%2BAll%2BPrimes%2BUp%2Bto%2B500-4.png" /></a></div>
<br />
<b><span style="font-family: "courier new" , "courier" , monospace;">Grid@Partition[If[!PrimeQ@#,Style[#,FontColor->White],#]&/@Range@200,20]</span></b><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-fkTKeyQWXdo/VmEOg7iHVnI/AAAAAAAAD4c/D5VfCAG6CdY/s1600/Grid-Partition-Identify%2BAll%2BPrimes%2BUp%2Bto%2B500-5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-fkTKeyQWXdo/VmEOg7iHVnI/AAAAAAAAD4c/D5VfCAG6CdY/s1600/Grid-Partition-Identify%2BAll%2BPrimes%2BUp%2Bto%2B500-5.png" /></a></div>
<br />
Change the Partition from 20 to 10 to accommodate larger numbers.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Grid@Partition[If[!PrimeQ@#,Style[#,FontColor->White],#]&/@Range[500000,500200],10]</b></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-RVsYf99d6uI/VmEO7ObVzJI/AAAAAAAAD4k/SyaV_MuniOk/s1600/Grid-Partition-Identify%2BAll%2BPrimes%2BUp%2Bto%2B500-6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-RVsYf99d6uI/VmEO7ObVzJI/AAAAAAAAD4k/SyaV_MuniOk/s1600/Grid-Partition-Identify%2BAll%2BPrimes%2BUp%2Bto%2B500-6.png" /></a></div>
<br /></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-27658463118410255302015-12-03T21:46:00.000-05:002015-12-06T05:01:27.522-05:00Run Wolfram BenchmarkReport to Test Your Computer's Peformance<div dir="ltr" style="text-align: left;" trbidi="on">
This is kind of neat. The report will compare your computer to a garden variety of others based on some benchmark tests. Your computer's results will be highlighted in blue. Interestingly I found that our more expensive and supposedly fastest computer ranked 7th compared to our standard desktops, which ranked 4th.<br />
<br />
The actual tests and code for them are very interesting — see the bottom of the report.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>?BenchmarkReport[]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">BenchmarkReport[] runs the WolframMark benchmark and produces a report in a separate notebook comparing this system to a selection of reference systems.</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">BenchmarkReport[system1,system2, ..., data1,data2,...] produces a custom report comparing the specified systems from $BenchmarkSystems and the specified data returned from Benchmark. >></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Needs@"Benchmarking`";</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>BenchmarkReport[]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<br />
<h2 style="text-align: left;">
<span style="font-family: inherit;">WolframMark Benchmark Report</span></h2>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">Machine Name:<span class="Apple-tab-span" style="white-space: pre;"> </span>w1bzzg6df934</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">System:<span class="Apple-tab-span" style="white-space: pre;"> </span>Microsoft Windows (64-bit)</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">Date:<span class="Apple-tab-span" style="white-space: pre;"> </span>December 3, 2015</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">Mathematica Version:<span class="Apple-tab-span" style="white-space: pre;"> </span>10.2.0</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">Benchmark Result:<span class="Apple-tab-span" style="white-space: pre;"> </span>1.33</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"></span><br />
<h3 style="text-align: left;">
<span style="font-family: inherit;">WolframMark Results</span></h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-mLbMgWbYHYE/VmD8MYizS6I/AAAAAAAAD3c/u24C7v28E3s/s1600/Wolfram%2BBenchmark-WolframMark%2BReport.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-mLbMgWbYHYE/VmD8MYizS6I/AAAAAAAAD3c/u24C7v28E3s/s1600/Wolfram%2BBenchmark-WolframMark%2BReport.png" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-Zyb66Jhb_Ac/VmD8OA7-8gI/AAAAAAAAD3k/AO_jrRH78Y0/s1600/Wolfram%2BBenchmark-WolframMark%2BReport2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-Zyb66Jhb_Ac/VmD8OA7-8gI/AAAAAAAAD3k/AO_jrRH78Y0/s1600/Wolfram%2BBenchmark-WolframMark%2BReport2.png" /></a></div>
<br />
<br />
<h3 style="text-align: left;">
WolframMark Sources</h3>
<h4 style="text-align: left;">
Test 1: Data Fitting</h4>
<br />
Module[{data},AbsoluteTiming[data=Flatten[Table[{x,y,z,Log[120 x]-Abs[Cos[z/300]/(140 y)]},{x,0.2`,10,0.22`},{y,0.2`,10,0.22`},{z,0.2`,10,0.22`}],2];FindFit[data,Log[a x]-Abs[Cos[b z]/(c y)],{a,b,c},{x,y,z},AccuracyGoal->6];]]<br />
<br />
<h4 style="text-align: left;">
Test 2: Digits of Pi</h4>
<br />
AbsoluteTiming[N[\[Pi],1000000];]<br />
<br />
<h4 style="text-align: left;">
Test 3: Discrete Fourier Transform</h4>
<br />
Module[{data},AbsoluteTiming[SeedRandom[1];data=RandomReal[{},{1200000}];Do[Fourier[data],{11}]]]<br />
<br />
<h4 style="text-align: left;">
Test 4: Eigenvalues of a Matrix</h4>
<br />
Module[{a,b,m},AbsoluteTiming[SeedRandom[1];a=RandomReal[{},{420,420}];b=DiagonalMatrix[RandomReal[{},{420}]];m=a.b.Inverse[a];Do[Eigenvalues[m],{6}]]]<br />
<br />
<h4 style="text-align: left;">
Test 5: Elementary Functions</h4>
<br />
Module[{m1,m2},AbsoluteTiming[SeedRandom[1];m1=RandomReal[{},{2.2`*^6}];m2=RandomReal[{},{2.2`*^6}];Do[Exp[m1];Sin[m1];ArcTan[m1,m2],{30}]]]<br />
<br />
<h4 style="text-align: left;">
Test 6: Gamma Function</h4>
<br />
Module[{a},AbsoluteTiming[SeedRandom[1];a=RandomInteger[{80000,90000},{55}];Gamma[a]]]<br />
<br />
<h4 style="text-align: left;">
Test 7: Large Integer Multiplication</h4>
<br />
Module[{a},AbsoluteTiming[SeedRandom[1];a=RandomInteger[{10^1100000,10^(1100000+1)},{}];Do[a (a+1),{20}]]]<br />
<br />
<h4 style="text-align: left;">
Test 8: Matrix Arithmetic</h4>
<br />
Module[{m},AbsoluteTiming[SeedRandom[1];m=RandomReal[{},{840,840}];Do[(1.` +0.5` m)^127,{50}];]]<br />
<br />
<h4 style="text-align: left;">
Test 9: Matrix Multiplication</h4>
<br />
Module[{m1,m2},AbsoluteTiming[SeedRandom[1];m1=RandomReal[{},{1050,1050}];m2=RandomReal[{},{1050,1050}];Do[m1.m2,{12}]]]<br />
<br />
<h4 style="text-align: left;">
Test 10: Matrix Transpose</h4>
<br />
Module[{m},AbsoluteTiming[SeedRandom[1];m=RandomReal[{},{2070,2070}];Do[Transpose[m],{40}]]]<br />
<br />
<h4 style="text-align: left;">
Test 11: Numerical Integration</h4>
<br />
AbsoluteTiming[NIntegrate[Sin[x^2+y^2],{x,-(2.6` \[Pi]),2.6` \[Pi]},{y,-(2.6` \[Pi]),2.6` \[Pi]}];]<br />
<br />
<h4 style="text-align: left;">
Test 12: Polynomial Expansion</h4>
<br />
AbsoluteTiming[Expand[Times@@Table[(c+x)^3,{c,350}]];]<br />
<br />
<h4 style="text-align: left;">
Test 13: Random Number Sort</h4>
<br />
Module[{a},AbsoluteTiming[SeedRandom[1];a=RandomInteger[{1,50000},{520000}];Do[Sort[a],{15}]]]<br />
<br />
<h4 style="text-align: left;">
Test 14: Singular Value Decomposition</h4>
<br />
Module[{m},AbsoluteTiming[SeedRandom[1];m=RandomReal[{},{860,860}];Do[SingularValueDecomposition[m],{2}]]]<br />
<br />
<h4 style="text-align: left;">
Test 15: Solving a Linear System</h4>
<br />
Module[{m,v},AbsoluteTiming[SeedRandom[1];m=RandomReal[{},{1150,1150}];v=RandomReal[{},{1150}];Do[LinearSolve[m,v],{16}]]]<br />
<br /></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-84720558130208529532015-12-02T20:56:00.000-05:002015-12-08T19:21:56.219-05:00The Basics of Slot (#) in Pure Functions<div dir="ltr" style="text-align: left;" trbidi="on">
Pure Function, as it's called, such as Function[x, x^2] that yields x<sup>2</sup> or the beautiful shorthand, #^2&, is extremely useful in <i>Mathematica</i>:<br />
<ol style="text-align: left;">
<li>For one-time functions</li>
<li>As an argument in many functional-style commands such as Map, Nest, Fold, Select, Count, etc</li>
<li>In the extended <a href="http://mathematica-guide.blogspot.com/2011/12/new-mathematica-programming-style-part.html" target="_blank">Postfix style of programming</a> I developed to eliminate hard-to-read nested functions</li>
<li>In <a href="http://mathematica-guide.blogspot.com/2012/01/predicates-tests-and-test-patterns-part_1730.html" target="_blank">predicates</a> including those used for argument type-checking: _?(# <= 1 &)</li>
<li>In the general pattern-matching predicate MatchQ</li>
<li>And the new use in Associations in version 10</li>
</ol>
<br />
Slot must be used with the pure Function operator &. They are designed to be the Head of a function:<br />
<br />
<b><span style="font-family: "courier new" , "courier" , monospace;">#1&[a,b,c]</span></b><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">a</span><br />
<br />
When you use the Postfix style just remember that Postfix causes the ampersand abbreviation for Function to wrap around an entire expression preceding it. Thus it has a low precedence of 90; here are its neighbors:<br />
<br />
<b style="font-family: 'courier new', courier, monospace;">Precedence/@{Set,Postfix,Colon,Function,TimesBy,Rule}</b><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;">{40.,70.,80.,90.,100.,120.}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
It can be confusing if there are nested used of Function, but using that principle, you can figure it out.<br />
<br />
<i>Important:</i> What trips up beginners is using Slot with <i>Mathematica's </i>universal container, List. This doesn't work:<br />
<br />
<b><span style="font-family: "courier new" , "courier" , monospace;">#1&{a,b,c}</span></b><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{a (#1&),b (#1&),c (#1&)}</span><br />
<br />
There are several solutions. Using Apply (@@) will return a Sequence:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>args=##&@@{a,b,c,d}</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">Sequence[a,b,c,d]</span><br />
<br />
A Sequence is a list designed to be fed to any function:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>func@args</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">func[a,b,c,d]</span><br />
<br />
You can wrap SlotSequence in List so it returns a List:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>{##}&[a,b,c,d]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">{a,b,c,d}</span><br />
<br />
Here are typical uses with Function as the Head or using Apply. Note that you cannot use negative position numbers with Slot or SlotSequence since that would conflict with using Subtract in pure Functions (like #-2&).<br />
<br />
<span style="font-family: inherit;">"First" (the default position argument for Slot is 1 so you don't need to specify it with "#1")</span><br />
<b><span style="font-family: "courier new" , "courier" , monospace;"><br /></span></b>
<b><span style="font-family: "courier new" , "courier" , monospace;">#&@@{a,b,c}</span></b><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">a</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: inherit;">Return the first two arguments:</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<b><span style="font-family: "courier new" , "courier" , monospace;">{#,#2}&@@{1,2,3,4}</span></b><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{1,2}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: inherit;">Return all arguments: ## is SlotSequence, which returns a Sequence, which is designed to be given to any function as its argument list.</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>##&[a,b,c,d]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">Sequence[a, b, c, d]</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>{##}&[a,b,c,d]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{a, b, c, d}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>##&@@@[a,b,c,d]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{a, b, c, d}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: inherit;">Return the first and fourth arguments:</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<b><span style="font-family: "courier new" , "courier" , monospace;">{#,#4}&@@{1,2,3,4}</span></b><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{1,4}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: inherit;">"Rest": Return the 2nd argument to the last:</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span><span style="font-family: "courier new" , "courier" , monospace;"><b>{##2}&[a,b,c,d]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"></span><br />
<span style="font-family: "courier new" , "courier" , monospace;">Sequence[b,c,d]</span><br />
<br />
As of version 10, there is an interesting new usage for Slot with Associations. Slot suffixed with any Key (name) of an Association will automatically return the Value associated with the Key.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>cityPopulationAssociation=Association["Tokyo"->"37 million","Jakarta"->"26 million","Seoul"->"17 million","Delhi"->"22 million","Shanghai"->"21 million"];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>#Delhi&@cityPopulationAssociation</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">22 million</span></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-73146483214638608862015-11-29T18:46:00.000-05:002015-12-03T22:31:20.096-05:00Estimate Pi Using Monte Carlo Sampling<div dir="ltr" style="text-align: left;" trbidi="on">
A classic use of the <a href="https://en.wikipedia.org/wiki/Monte_Carlo_method" target="_blank">Monte Carlo</a> random sampling technique is to <a href="http://www.eveandersson.com/pi/monte-carlo-circle" target="_blank">estimate Pi</a>. It's very simple.<br />
<br />
1. We construct a square by randomly selecting point in the interval (-1, 1).<br />
<br />
2. We select a subset of points that satisfy the predicate that places them on or within the unit circle:<br />
<br />
x^2 + y^2 < =1.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-_bgVMDi3WwU/VlxlDynWG-I/AAAAAAAAD2s/Y32Wd1D6JaM/s1600/Unit_Circle.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-_bgVMDi3WwU/VlxlDynWG-I/AAAAAAAAD2s/Y32Wd1D6JaM/s1600/Unit_Circle.png" /></a></div>
<br />
<br />
3. The area of the square extending from -1 to 1 is 2^2 = 4. The area of the unit circle is 1 (Pi*r^2 = Pi*1^2). Therefore we multiply the ratio of the number of points lying within the unit circle divided by the number of points within the square by 4.<br />
<br />
Here is an implementation. Below that is an implementation I found on the web that shows how newbies to <i>Mathematica</i> may transfer inefficient coding techniques from other languages to <i>Mathematica</i><i>.</i><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@circleRegionMonteCarlo;circleRegionMonteCarlo[numberSamplePoints_Integer]:=Module[{samplePoints=RandomReal[{-1,1},{numberSamplePoints,2}],</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>areaOfCirclePoints},</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>(* Select points within the unit circle using the parametric equation for a circle *)</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>areaOfCirclePoints=Select[samplePoints,First@#^2+Last@#^2<=1&];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Print@StringForm["Approximation to Pi using `` sample points is ``.",numberSamplePoints,4*Length@areaOfCirclePoints/numberSamplePoints//N];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>If[numberSamplePoints<50001,ListPlot[areaOfCirclePoints,AspectRatio->Automatic]]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>circleRegionMonteCarlo[50000]</b></span><br />
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: "courier new" , "courier" , monospace;"><b><a href="http://1.bp.blogspot.com/-aRNxvK7LBuA/VluIURGizOI/AAAAAAAAD2U/MhD0xztCSzw/s1600/Estimate%2BPi%2BUsing%2BMonte%2BCarlo%2BSampling.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://1.bp.blogspot.com/-aRNxvK7LBuA/VluIURGizOI/AAAAAAAAD2U/MhD0xztCSzw/s320/Estimate%2BPi%2BUsing%2BMonte%2BCarlo%2BSampling.png" width="303" /></a></b></span></div>
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">Approximation to Pi using 50000 sample points is 3.14104`.</span><br />
<br />
This represents an obsolete coding technique: 1) initializing the Pin (points inside the circle) and Pout (points outside the circle) arrays, 2) the For loop calling named random variable functions, 3) testing the distance predicate in the loop instead of all at once as is typical in functional programming, 4) having to take the Length of Pin and Pout in the loop (obviously you don't need to test the Length every time anyway), and 5) using Return instead of just leaving off the semi-colon after approx, are all obsolete techniques.<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>MonteCarloPi[n_]:=Module[{d,i},</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>n=n0;</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Pin=Pout={};</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>For[i=1,i<=n,i++,</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>x=RandomReal[];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>y=RandomReal[];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>d=x^2+y^2;</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>If[d<=1, Pin=Append[Pin,{x,y}],Pout=Append[Pout,{x,y}] ];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>n=Length@Pin;</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>m=Length@Pout;</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>\[Rho]=m/n;</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>approx=4.0;]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Return@approx</b></span><br />
<b><span style="font-family: "courier new" , "courier" , monospace;"></span></b><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>]</b></span></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-72930289939142887002015-09-23T18:06:00.002-04:002015-09-23T18:20:46.121-04:00How It Works: Union<div dir="ltr" style="text-align: left;" trbidi="on">
Here is a recursive version of the set-theoretic function, <a href="https://reference.wolfram.com/language/ref/Union.html" target="_blank">Union</a>, which returns the common elements of two or more sets (represented as Lists in <i>Mathematica</i>).<br />
<br />
There are two base cases: 1) The union of any set with the empty set is the set itself, and 2) The union of any set with a single element set is the single element set appended to the other set. The recursive case is: 3) The union of any two Lists is the union of the first List with the First element of the second List (i.e. the single element base case), which, calling itself, recurses down the Rest of the second List until it hits the empty set base case (an empty List), at which point it unwinds back out to produce the overall union.<br />
<br />
Union produces a set of unique elements — no duplicates — so we need to de-dupe the List. An easy way to do that is Sort it and use a replacement Rule (we could also use the built-in <a href="https://reference.wolfram.com/language/ref/DeleteDuplicates.html" target="_blank">DeleteDuplicates </a>or <a href="http://mathematica-guide.blogspot.com/2012/10/deleteduplicates.html" target="_blank">How It Works: DeleteDuplicates</a>).<br />
<br />
I show two ways to control the Precedence of the abbreviate operators for ReplaceRepeated vs Postfix. Since with Precedence of 110 ReplaceRepeated is a little 'stickier' than Postfix at 70 Sort will stick to the ReplaceRepeated function unless we do something. So we can either enclose the compound function in parentheses before applying ReplaceRepeated as in the 2<sup>nd</sup> base case or we can use Postfix with Slot (#) and pure Function (&) as typical in <a href="http://mathematica-guide.blogspot.com/2011/12/new-mathematica-programming-style-part.html" target="_blank">my extended Postfix syntax</a> as in the recursive case.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>Clear@myUnion;</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;"><b>myUnion[list1_List,{}]:=list1; (* 1st base case *)</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;"><b>myUnion[list1_List,element_]:=(If[MemberQ[list1,element],list1,list1/.{x___}->{x,element}] //Sort)//.{a___,b_,b_,c___}->{a,b,c}(* 2nd base case *)</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;"><b>myUnion[list1_List,list2_List]:=Module[{union},union=myUnion[myUnion[list1,First@list2],Rest@list2]//Sort//#//.{a___,b_,b_,c___}->{a,b,c}&</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b>] (* recursive case *)</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>myUnion[{1,2,3,4},{}]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span><span style="font-family: Courier New, Courier, monospace;">{1,2,3,4}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;"><b>myUnion[{1,2,3,4},5]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">{1,2,3,4,5}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>myUnion[{1,2,3,4},2]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;">{1,2,3,4}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
This shows the need to add a delete duplicates function:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>myUnion[{1,2,2,3},2]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;">{1,2,2,3}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
A simple replacement Rule does the job, but use ReplaceRepeated or only the first instance of a duplicate will be replaced:<br />
<br />
<b><span style="font-family: Courier New, Courier, monospace;">{1,2,2,3,4,4}/.{a___,b_,b_,c___}->{a,b,c}</span></b><br />
<div>
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span><span style="font-family: Courier New, Courier, monospace;">{1,2,3,4,4}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>{4,4,1,3,3,2,2}//.{a___,b_,b_,c___}->{a,b,c}</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
This works without the delete duplicates function.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>myUnion[{1,2,3,4},{3,4,5,6}]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">{1,2,3,4,5,6}</span><br />
<br />
But this would fail without it. First without delete duplicates.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>myUnion[{1,2,2,3,4},{3,4,5}]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">{1,2,2,3,4,5}</span><br />
<br />
And now with delete duplicates.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>myUnion[{1,2,2,3,4},{3,4,5}]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">{1,2,3,4,5}</span><br />
<br />
And the base case.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>myUnion[{3,2,1,2,2,3},3]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">{1,2,3}</span><br />
<br />
And the recursive case.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>myUnion[{1,2},{2,3,4}]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">{1,2,3,4}</span></div>
</div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-32700010972544296982015-07-10T14:58:00.002-04:002022-04-03T08:29:37.401-04:00How to See the Equivalence of Select and Cases<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
MatchQ and PatternTest Equate Cases and Select</h2>
Select and Cases are essential <i>Mathematica </i>filtering functions. Select filters expressions, usually Lists, with <a href="http://mathematica-guide.blogspot.com/2012/01/predicates-tests-and-test-patterns-part_1730.html" target="_blank">predicates</a>, such as ones that end with Q (evaluate ?*Q to see them) or those that don't, such as Greater, Less, and others that I list <a href="http://mathematica-guide.blogspot.com/2013/06/non-q-predicates-in-mathematica.html">here</a>. Cases uses patterns such as testing for a Head (e.g. _Integer) or a more general pattern (e.g. for a 2-element List, {x_,y_}.<br />
<div>
<div>
<br /></div>
<div>
Cases and Select are equivalent and a versatile <i>Mathematica </i>programmer knows how to use either one in any circumstance according to the need of the moment. The keys to seeing their equivalence are MatchQ, which translates a <i>pattern </i>into a <i>predicate</i>, and PatternTest (_?test), which translates a <i>predicate </i>into a <i>pattern</i>.</div>
<div>
<br /></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><b>MatchQ[4.1,_Real]</b></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">True</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><b>MatchQ[{2,2.1},{_Integer,_Real}]</b></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">True</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
Thus you can take any usage of Cases and translate it into Select.</div>
<div>
<br /></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Cases[{a,4,4.2,6,7.5,8},x_Integer/;x>4]</b></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">{6,8}</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><b>integerGreaterThan4Q@n_:=MatchQ[n,_Integer&&n>4];</b></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Select[{a,4,4.2,6,7.5,8},integerGreaterThan4Q]</b></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">{6,8}</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
And you can take any usage of Select and translate it into Cases.</div>
<div>
<br /></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Select[{1,2,4,7,6,2},EvenQ]</b></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">{2,4,6,2}</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Cases[{1,2,4,7,6,2},_?EvenQ]</b></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">{2,4,6,2}</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
If we built our own predicate for EvenQ using MatchQ, it works the same way.</div>
<div>
<br /></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Select[{1,2,3,4},MatchQ[#/2,_Integer]&]</b></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">{2,4}</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
However note the need for parentheses around the test, which is often the case with PatternTest - the no parens usage fails.</div>
<div>
<br /></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Cases[{1,2,3,4},_?(MatchQ[#/2,_Integer]&)]</b></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">{2,4}</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Cases[{1,2,3,4},_?MatchQ[#/2,_Integer]&]</b></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">{}</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
The reason is that Blank and PatternTest both have a higher Precedence ('stickiness') than Function, and so they stick together and PatternTest ends up inside the pure Function instead of using the pure Function as the pattern test. You don't need to worry about that — just as a rule of thumb put parens around any 'homemade' test.</div>
<div>
<br /></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Precedence/@{PatternTest,Blank,Function}</b></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">{680.,730.,90.}</span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<h3 style="text-align: left;">
The Q Predicates</h3>
<div>
<br /></div>
<div>
This is a handy way to use Partition, especially using {} so a final short sublist won't be dropped from a 'ragged' List. The syntax says<br />
<br />
Partition[list, sublist length, offset length, start Position, padding]<br />
<br />
and here means divide the List into Partitions of length 4, moving the window that same length 4 with each Partition so there is no overlap, start the List at Position 1, and the empty set {} for padding tells Partition to return the final sublist even if it's shorter than what is specified by the 2nd argument, and don't pad that final short list. Evaluate this code in your Notebook:</div>
<div>
<br /></div>
<div>
<b><span style="font-family: "courier new" , "courier" , monospace;">Qpredicates=Names@"*Q";</span></b></div>
<div>
<b><span style="font-family: "courier new" , "courier" , monospace;">Print@Length@Qpredicates;</span></b></div>
<div>
<b><span style="font-family: "courier new" , "courier" , monospace;">Partition[Qpredicates,4,4,1,{}]//TableForm</span></b></div>
<div>
<br /></div>
<div>
Here's the same result in a List.</div>
</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Names@"*Q"</b></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;">{AcyclicGraphQ,AlgebraicIntegerQ,AlgebraicUnitQ,AntihermitianMatrixQ,AntisymmetricMatrixQ,ArgumentCountQ,ArrayQ,AssociationQ,AtomQ,BinaryImageQ,BipartiteGraphQ,BooleanQ,BoundaryMeshRegionQ,BoundedRegionQ,BusinessDayQ,ColorQ,CompatibleUnitQ,CompleteGraphQ,CompositeQ,ConnectedGraphQ,ConstantRegionQ,ContinuousTimeModelQ,ControllableModelQ,CoprimeQ,DateObjectQ,DaylightQ,DayMatchQ,DeviceOpenQ,DiagonalizableMatrixQ,DigitQ,DirectedGraphQ,DirectoryQ,DiscreteTimeModelQ,DisjointQ,DispatchQ,DistributionParameterQ,DuplicateFreeQ,EdgeCoverQ,EdgeQ,EllipticNomeQ,EmptyGraphQ,EulerianGraphQ,EvenQ,ExactNumberQ,FileExistsQ,firedQ,FreeQ,GeoWithinQ,GraphQ,GroupElementQ,HamiltonianGraphQ,HermitianMatrixQ,HypergeometricPFQ,ImageQ,IndefiniteMatrixQ,IndependentEdgeSetQ,IndependentVertexSetQ,InexactNumberQ,integerGreaterThan4Q,IntegerQ,IntersectingQ,IntervalMemberQ,InverseEllipticNomeQ,IrreduciblePolynomialQ,IsomorphicGraphQ,KEdgeConnectedGraphQ,KeyExistsQ,KeyFreeQ,KeyMemberQ,KnownUnitQ,KVertexConnectedGraphQ,LeapYearQ,LegendreQ,LetterQ,LinkConnectedQ,LinkReadyQ,ListQ,LoopFreeGraphQ,LowerCaseQ,MachineNumberQ,ManagedLibraryExpressionQ,MandelbrotSetMemberQ,MarcumQ,MatchLocalNameQ,MatchQ,MatrixQ,MemberQ,MeshRegionQ,MixedGraphQ,MultigraphQ,NameQ,NegativeDefiniteMatrixQ,NegativeSemidefiniteMatrixQ,NormalMatrixQ,NumberQ,NumericQ,ObservableModelQ,OddQ,OptionQ,OrderedQ,OrthogonalMatrixQ,OutputControllableModelQ,PartitionsQ,PathGraphQ,PermutationCyclesQ,PermutationListQ,PlanarGraphQ,PolynomialQ,PositiveDefiniteMatrixQ,PositiveSemidefiniteMatrixQ,PossibleZeroQ,PrimePowerQ,PrimeQ,ProcessParameterQ,QHypergeometricPFQ,QuadraticIrrationalQ,QuantityQ,RegionQ,RegularlySampledQ,RootOfUnityQ,SameQ,SatisfiableQ,ScheduledTaskActiveQ,SimpleGraphQ,SquareFreeQ,SquareMatrixQ,StringFreeQ,StringMatchQ,StringQ,SubsetQ,SymmetricMatrixQ,SyntaxQ,TautologyQ,TensorQ,TreeGraphQ,TrueQ,UnateQ,UndirectedGraphQ,UnitaryMatrixQ,UnsameQ,UpperCaseQ,URLExistsQ,ValueQ,VectorQ,VertexCoverQ,VertexQ,WeaklyConnectedGraphQ,WeightedGraphQ}</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span></div>
</div>
<div> </div></div></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-1234965997363946152015-07-08T18:39:00.000-04:002015-10-04T12:08:37.153-04:00New in Mathematica 10: Associations as General-Purpose Associative Arrays<div dir="ltr" style="text-align: left;" trbidi="on">
Associations are the most important data structure introduced in <i>Mathematica </i>in years. As the Guide says:<br />
<br />
<blockquote class="tr_bq">
Along with lists, associations are fundamental constructs in the Wolfram Language. They associate keys with values, allowing highly efficient lookup and updating even with millions of elements. Associations provide generalizations of symbolically indexed lists, associative arrays, dictionaries, hashmaps, structs, and a variety of other powerful data structures. </blockquote>
<br />
They of course will underlie databases and artificial intelligence data structures. They are intended to replace less structured expressions such as pairs in Lists or Rules. The code written for Association functions has been highly optimized for speed. I suspect that Associations are the core data structure of the Wolfram Alpha natural language processor, which is the front end for the curated data collections in Alpha, just as the Notebook is the front end for the kernel.<br />
<br />
So when I needed a lookup table today I decided to try Associations. Here are some simple functions that define an axon's threshold in terms of the stimulating pulse seen at the axon, according to the <a href="https://en.wikipedia.org/wiki/Rheobase#Lapicque.27s_Equation" target="_blank">Lapicque equation</a> <span style="font-family: Courier New, Courier, monospace;">V<sub>th</sub> = V<sub>rh</sub>(1+τ<sub>ch</sub>/pw).</span><br />
<br />
(You don't need to understand these!)<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>absoluteRheobase@fiberDiameter_:=0.000589+0.01518 Exp[-fiberDiameter/2.3477]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;"><b>chronaxie@fiberDiameter_:=102.764 +162.46744 Exp[-fiberDiameter/5.53435];</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;"><b>absoluteThreshold=.;absoluteThreshold[pulseWidth_,fiberDiameter_]:=Module[{},absoluteRheobase@fiberDiameter(1+chronaxie@fiberDiameter/pulseWidth)]</b></span><br />
<br />
Now since fiber threshold is driven by their diameter and the pulse width of the stimulating pulse, we make sample tables of those. Esc + m + esc gives us the mu in microseconds and micrometers; no need to open a Palette.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>pulseWidthTable50to500=Table[pw,{pw,100,500,100}] (* in μs *);</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;"><b>fiberDiameters1to15=Table[diameters,{diameters,5,10}] (* in μm *);</b></span><br />
<br />
Now here is the function that creates the Associations. It took a bit of fiddling, but by making a Table of Rules in one step as should be done with good functional programming, it is then easy to Apply Association to the entire Table, simply replacing the Head, List, with Association, which converts the List of Rules into an Association. In the Table pulseWidth is the "i" iterator and fiberDiameter is the "j" iterator, and notice that we don't need to iterate numerically from 1 to Length@pulseWidthTable50to500, for example, we just directly iterate over the List itself, which is simpler.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>absoluteThresholdTable=Association@@Table[Rule[{pulseWidth,fiberDiameter},absoluteThreshold[pulseWidth,fiberDiameter]],{pulseWidth,pulseWidthTable50to500},{fiberDiameter,fiberDiameters1to15}]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><|{100,5}->0.00642849,{100,6}->0.00455515,{100,7}->0.00337826,{100,8}->0.00263167,{100,9}->0.00215327,{100,10}->0.00184348,{200,5}->0.00441095,{200,6}->0.00316135,{200,7}->0.00236852,{200,8}->0.00186172,{200,9}->0.00153533,{200,10}->0.00132348,{300,5}->0.00373844,{300,6}->0.00269675,{300,7}->0.00203194,{300,8}->0.00160507,{300,9}->0.00132935,{300,10}->0.00115015,{400,5}->0.00340218,{400,6}->0.00246445,{400,7}->0.00186364,{400,8}->0.00147675,{400,9}->0.00122636,{400,10}->0.00106348,{500,5}->0.00320043,{500,6}->0.00232507,{500,7}->0.00176267,{500,8}->0.00139975,{500,9}->0.00116456,{500,10}->0.00101149|></span><br />
<br />
Here are several versions of lookup functions. The first one just uses the same syntax as we'd use to access elements of an associative array made with function@value, such as we'd construct with a memo function.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>Clear@thresholdLookup; </b></span><br />
<b style="font-family: 'Courier New', Courier, monospace;">thresholdLookup[lookupTable_Association, pulseWidth_Integer, diameter_] := </b><b style="font-family: 'Courier New', Courier, monospace;">lookupTable@{pulseWidth, diameter}</b><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>absoluteThresholdTable@{100, 7}</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">0.00337826</span><br />
<br />
Likely it's safer and more elegant to use the new Lookup function instead.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>Clear@thresholdLookup2; </b></span><br />
<b><span style="font-family: Courier New, Courier, monospace;">thresholdLookup2[lookupTable_Association, pulseWidth_Integer, diameter_] := </span><span style="font-family: 'Courier New', Courier, monospace;">Lookup[lookupTable, {{pulseWidth, diameter}}]</span></b><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;"><b>thresholdLookup2[absoluteThresholdTable, 100, 7]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">{0.00337826}</span><br />
<br />
We see that using a List as the Key results in returning a List as the Value, like in solutions for equations returned by Solve, etc. So to access the Value we can use First@key to remove the List brackets, as we often do with solutions to equations. <br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>Clear@thresholdLookup3; </b></span><br />
<b><span style="font-family: Courier New, Courier, monospace;">thresholdLookup3[lookupTable_Association, pulseWidth_Integer, diameter_] := </span><span style="font-family: 'Courier New', Courier, monospace;">Lookup[lookupTable, {{pulseWidth, diameter}}] // First</span></b><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;"><b>thresholdLookup3[absoluteThresholdTable, 100, 7]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">0.00337826</span><br />
<br />
Years ago I talked to Stephen Wolfram at an artificial life conference about artificial intelligence and his views were kind of naive. Things have changed. I expect that <i>Mathematica </i>and its Wolfram Language are headed inexorably toward large-scale AI applications, approaching, and exceeding in some respects, human intelligence over the next two decades.</div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-18950197819890651032015-06-28T11:43:00.000-04:002015-06-28T14:59:14.114-04:00How to Find Memory Used in Computations<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
At some point you will need to — or just want to — push the limits of <i>Mathematica </i>and it may be helpful to measure memory consumed during a computation. Here are methods inspired by <a href="http://amzn.to/1CCo7pz" target="_blank">Wagon</a>, <i>Mathematica in Action</i> (2nd ed., pp 431 <i>et seq.</i>). (See also <a href="http://mathematica-guide.blogspot.com/2014/12/the-easiest-way-to-clear-memory.html" target="_blank">Memory Management Tools</a>.)<br />
<br />
The first method is simple; store the initial MemoryInUse in a variable, do your calc, then subtract it from the current MemoryInUse.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>currentMemory=MemoryInUse[];</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b>{(MemoryInUse[]-currentMemory),Plus@@(1./Range@1000000)}</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">{1368,14.3927}</span><br />
<br />
Second, suppose you want to monitor memory in several places in your code. Initialize the variable currentMemory, then sprinkle<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>Sow[-currentMemory+(currentMemory=MemoryInUse[])]</b></span><br />
<br />
through your code like Print statements, and the enclosing Reap will cause each one to output the net memory consumed in bytes between the previous use and the current one. I say 'net' memory consumed because Mathematica is designed to optimize memory use and so clears memory in use every chance it gets. Following the pattern of <a href="http://reference.wolfram.com/language/ref/Timing.html" target="_blank">Timing</a>, I reverse the output to give the memory results first, then the function's output.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>currentMemory=MemoryInUse[];</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b>(*initialize s*); </b></span><b style="font-family: 'Courier New', Courier, monospace;">s=0;</b><br />
<b style="font-family: 'Courier New', Courier, monospace;">Reap[Do[If[i<25,Sow[-currentMemory+(currentMemory=MemoryInUse[])]];s+=1./i,{i,1000}];s]//Reverse</b><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">{{{3016,11216,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},7.48547</span>}<br />
<br />
Did you notice, as Wagon points out, that Do uses minimal memory during a calculation? It cleans up after every iteration.<br />
<br />
Like Timing, this third method of checkMemory requires you to wrap your computation in checkMemory, access the result of your computation with First and if desired suppress the output with a semi-colon. Mimicking the structure of a built-in function is an example of a good programming technique. The designers of Mathematica are master programmers and they have created and debugged templates or paradigms of function structures. Often you can follow the structure of built-in functions to create sound ones of your own.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>Clear@checkMemory;</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b>checkMemory@computation_:=</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b>Module[</b></span><b style="font-family: 'Courier New', Courier, monospace;">{computation1,preComputationMemory},</b><br />
<span style="font-family: Courier New, Courier, monospace;"><b>preComputationMemory=MemoryInUse[];Print["Memory in use at start is ",preComputationMemory];</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b>computation1=computation;</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b>memoryUsedInComputation=MemoryInUse[]-preComputationMemory;</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b>Print["Memory in use at end is ",MemoryInUse[]];{memoryUsedInComputation,computation1}</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b>]</b></span><br />
<br />
Once it's done, this computation uses 32 bytes of memory and the result is 14.3927.<br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>checkMemory[Sum[1./i,{i,1000000}]]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">Memory in use at start is 31286024</span><br />
<span style="font-family: Courier New, Courier, monospace;">Memory in use at end is 31286056</span><br />
<span style="font-family: Courier New, Courier, monospace;">{32,14.3927}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
We find the memory use with the function output for a small Table.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>s1=0;checkMemory[Table[s1+=1./i,{i,10}]]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">Memory in use at start is 31289472</span><br />
<span style="font-family: Courier New, Courier, monospace;">Memory in use at end is 31289752</span><br />
<span style="font-family: Courier New, Courier, monospace;">{280,{1.,1.5,1.83333,2.08333,2.28333,2.45,2.59286,2.71786,2.82897,2.92897}}</span><br />
<br />
Then suppress output, with a semi-colon as is done in Timing, for a large Table.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>checkMemory[s1=Table[1./i,{i,10^7}];]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">Memory in use at start is 31340688</span><br />
<span style="font-family: Courier New, Courier, monospace;">Memory in use at end is 111344696</span><br />
<span style="font-family: Courier New, Courier, monospace;">{80003992,Null}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
I left off the summation of the Table to show MemoryInUse during the calc. If we add Total, we see the max MemoryInUse reclaimed (-80,000,024 bytes).<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>Timing[checkMemory[s1=Table[1./i,{i,10^7}]//Total]]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;">Memory in use at start is 31359736</span><br />
<span style="font-family: Courier New, Courier, monospace;">Memory in use at end is 31359864</span><br />
<span style="font-family: Courier New, Courier, monospace;">{0.343202,{128,16.6953}}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: inherit;">Compare memory used in a Do loop. Pretty interesting!</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>Timing[s1=0;checkMemory[Do[s1+=1./i,{i,10^7}];s1]]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;">Memory in use at start is 31364400</span><br />
<span style="font-family: Courier New, Courier, monospace;">Memory in use at end is 31364432</span><br />
<span style="font-family: Courier New, Courier, monospace;">{10.296066,{32,16.6953}}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;"><b>First@%/First@%%</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;">30.0000</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">So there you have it, Do takes 30 times as long as the functional command Table[...]//Total, but uses a minute fraction of the latter's memory.</span><br />
<br /></div>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ss&ref=ss_til&ad_type=product_link&tracking_id=concordpoetry-20&marketplace=amazon&region=US&placement=0387753664&asins=0387753664&linkId=A2DZYXTLEXNUDT3J&show_border=true&link_opens_in_new_window=true" style="height: 240px; width: 120px;">
</iframe></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-35016349200168831332015-06-26T16:53:00.000-04:002016-02-28T13:14:09.301-05:00How to Query 11 Different Search Engines<div dir="ltr" style="text-align: left;" trbidi="on">
You can query a search engine with URLFetch. For the URL you need a String that includes a standard prefix and a suffix that begins with something like "/?q=querykeywords". I have removed some unnecessary junk from most of the query Strings to make them as short and simple as possible.<br />
<br />
<span style="font-family: inherit;">There are several ways to functionally compose a query for a search engine. This one uses StringJoin. I use Which to handle the cases of 1) a single keyword, 2) multiple keywords, or 3) any other data type, which is an error. Using True as the third test in conditional statements is a standard way to handle 'all else' cases.</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>queryTemplateDuckDuckGo="https://duckduckgo.com/?q=";</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>keyword1="longevity";</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>keywords2={"machine","learning","algorithm"};</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@searchEngineQuery;</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>searchEngineQuery[searchEnginePrefix_String, keywords_] := </b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> Module[{url},</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> Which[</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> Head@keywords === String, </b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> url = StringJoin[searchEnginePrefix, keywords],</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> Head@keywords === List, </b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> url = StringJoin[searchEnginePrefix, </b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> Table[i <> "+", {i, Most@keywords}], Last@keywords],</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> True, Print@"Error: wrong data type."];</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> Print@url;</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> URLFetch@url</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b> ]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: inherit;">We test it on a single keyword (I omit the full output, which you can try at home).</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>searchEngineQuery@keyword1</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">https://duckduckgo.com/?q=longevity</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: inherit;">We try it on a List of keywords.</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>searchEngineQuery@keywords2</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">https://duckduckgo.com/?q=machine+learning+algorithm</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: inherit;">We try it on a wrong data type.</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>searchEngineQuery[queryTemplateDuckDuckGo, 5]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">Error: wrong data type.</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: inherit;">And here are sample fetches for the search engines. Again, I omit the full output but you can try them yourself. </span>I precede each sample with a rating the quality of 'cleanliness' of results by StringLength, the idea being that the shorter length results Strings have less junk in them and more of the actual results. By that measure DuckDuckGo, Blekko and Alhea give the 'cleanest' output for further processing. But don't misconstrue that measure as a quality rating of the results themselves.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>StringLength/@{%365,%366,%368,%370,%372,%374,%376,%378,%380,%382,%384}</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;">{42192,11496,80722,94714,164072,117642,19161,42104,14660,104627,21239}</span><br />
<span style="font-family: inherit;"><br /></span>
<br />
<h2 style="text-align: left;">
<span style="font-family: inherit;">11 Search Engines Queried</span></h2>
<span style="font-family: inherit;"><br /></span>
<br />
<h3 style="text-align: left;">
Google: 42,192</h3>
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>URLFetch["https://www.google.com/search?q=atherosclerosis"]</b></span><br />
<br />
<h3 style="text-align: left;">
DuckDuckGo: 11,496</h3>
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>URLFetch["https://duckduckgo.com/?q=atherosclerosis"]</b></span><br />
<br />
<h3 style="text-align: left;">
Bing: 80,722</h3>
<br />
<b><span style="font-family: "courier new" , "courier" , monospace;">URLFetch["http://www.bing.com/search?q=atherosclerosis"]</span></b><br />
<br />
<h3 style="text-align: left;">
Ask.com: 94,714</h3>
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>URLFetch["http://www.ask.com/web?qsrc=1&o=2545&l=dir&q=\</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>atherosclerosis"]</b></span><br />
<br />
<h3 style="text-align: left;">
AOL: 164,072</h3>
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>URLFetch["http://search.aol.com/aol/search?s_it=searchbox.webhome&v_t=\</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>na&q=atherosclerosis"]</b></span><br />
<br />
<h3 style="text-align: left;">
Wow: 117,642</h3>
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>URLFetch["http://www.wow.com/search?s_it=search-thp&v_t=na&q=\</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>atherosclerosis&s_qt=ac"]</b></span><br />
<br />
<h3 style="text-align: left;">
InfoSpace: 19,161</h3>
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>URLFetch["http://search.infospace.com/search/web?q=atherosclerosis&\</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>searchbtn=Search"]</b></span><br />
<br />
<h3 style="text-align: left;">
Info: 42,104</h3>
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>URLFetch["http://www.info.com/search?qcat=web&r_cop=xxx&qkw=\</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>atherosclerosis"]</b></span><br />
<br />
<h3 style="text-align: left;">
DogPile: 104,627</h3>
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>URLFetch["http://www.dogpile.com/info.dogpl/search/web?fcoid=417&fcop=\</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>topnav&fpid=27&q=atherosclerosis&ql="]</b></span><br />
<br />
<h3 style="text-align: left;">
Alhea: 21,239</h3>
<b><span style="font-family: "courier new" , "courier" , monospace;">URLFetch["http://www.alhea.com/search/web?fcoid=417&fcop=topnav&fpid=\</span></b><br />
<b><span style="font-family: "courier new" , "courier" , monospace;">27&q=atherosclerosis&ql="]</span></b><br />
<br />
<span style="font-family: inherit;"><br /></span></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-66237459030415361512015-06-25T17:59:00.000-04:002015-06-25T17:59:25.178-04:00Recursive Programming on Lists (Arrays): Map<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: inherit;">Here is a simple recursive mapping function. This is a recursion on Lists (arrays) with arbitrary argument types, not numbers.</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Recall that Map is a classic functional-style, 'structural' command since it leads us to think in terms of applying a function to an entire structure, such as an array (a List in Mathematica). The Map function saves us the trouble of 'deconstructing' the array with a Do or For loop as in procedural programming.</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">We define a base case and a recursive case:</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">1. Base case: If the source List is empty, just return it</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">2. Recursive case: Call itself on the Rest of each successively smaller sub-List</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>Clear@recursiveMap;</b></span><br />
<b style="font-family: 'Courier New', Courier, monospace;">recursiveMap[function_,aList_List]:=</b><br />
<b style="font-family: 'Courier New', Courier, monospace;">If[aList=={},{},</b><br />
<b style="font-family: 'Courier New', Courier, monospace;">Prepend[recursiveMap[function,Rest@aList],function@First@aList]]</b><br />
<br />
<span style="font-family: inherit;">We test the base case:</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>recursiveMap[f,{}]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;">{}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: inherit;">We test some recursive cases:</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>recursiveMap[f,{a,b,c}]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;">{f[a],f[b],f[c]}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>recursiveMap[f,Range@5]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><b><br /></b></span>
<span style="font-family: Courier New, Courier, monospace;">{f[1],f[2],f[3],f[4],f[5]}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: inherit;">How does it work? You can go through the Trace, but essentially by calling itself repeatedly on the Rest of list (via the first, recursive 'clause' of recursiveMap, recursiveMap[function,Rest@list]), it constructs successively smaller sub-Lists and eventually hits the empty List, which is the base case. </span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;">Then it begins 'unwinding' and Prepend and the second clause of recursiveMap is repeatedly invoked (function@First@list). Starting with the last List of a single element (c in this Trace), it applies the function f to the First element of each sub-List and Prepends it to a growing List of results until the First element of the entire list is Prepended.</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>Trace@recursiveMap[f,{a,b,c}]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">{recursiveMap[f,{a,b,c}],If[{a,b,c}=={},{},Prepend[recursiveMap[f,Rest[{a,b,c}]],f[First[{a,b,c}]]]],{{a,b,c}=={},False},If[False,{},Prepend[recursiveMap[f,Rest[{a,b,c}]],f[First[{a,b,c}]]]],Prepend[recursiveMap[f,Rest[{a,b,c}]],f[First[{a,b,c}]]],{{Rest[{a,b,c}],{b,c}},recursiveMap[f,{b,c}],If[{b,c}=={},{},Prepend[recursiveMap[f,Rest[{b,c}]],f[First[{b,c}]]]],{{b,c}=={},False},If[False,{},Prepend[recursiveMap[f,Rest[{b,c}]],f[First[{b,c}]]]],Prepend[recursiveMap[f,Rest[{b,c}]],f[First[{b,c}]]],{{Rest[{b,c}],{c}},recursiveMap[f,{c}],If[{c}=={},{},Prepend[recursiveMap[f,Rest[{c}]],f[First[{c}]]]],{{c}=={},False},If[False,{},Prepend[recursiveMap[f,Rest[{c}]],f[First[{c}]]]],Prepend[recursiveMap[f,Rest[{c}]],f[First[{c}]]],{{Rest[{c}],{}},recursiveMap[f,{}],If[{}=={},{},Prepend[recursiveMap[f,Rest[{}]],f[First[{}]]]],{{}=={},True},If[True,{},Prepend[recursiveMap[f,Rest[{}]],f[First[{}]]]],{}},{{First[{c}],c},f[c]},Prepend[{},f[c]],{f[c]}},{{First[{b,c}],b},f[b]},Prepend[{f[c]},f[b]],{f[b],f[c]}},{{First[{a,b,c}],a},f[a]},Prepend[{f[b],f[c]},f[a]],{f[a],f[b],f[c]}}</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: inherit;"><i>Source:</i> David Wagner</span><br />
<br />
<br /></div>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ss&ref=ss_til&ad_type=product_link&tracking_id=concordpoetry-20&marketplace=amazon&region=US&placement=007912237X&asins=007912237X&linkId=ORRHH4R2RQN6JUDK&show_border=true&link_opens_in_new_window=true" style="height: 240px; width: 120px;">
</iframe></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-88705935565633060202015-06-24T08:56:00.001-04:002017-09-15T17:15:18.811-04:00Using Recursion to Define a Periodic Function<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
I'm working my way through Heikki Ruskeepaa's book, <i>Mathematica Navigator</i> and found this elegant one-liner that shows how to define a periodic function with recursion. Note that the <a href="http://mathematica-guide.blogspot.com/2015/06/recursive-programming-general-principle.html">base case</a> required to stop the recursion is not a single value but the condition 0 <= t <= 2.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@sawtooth;sawtooth[time_,scale_:1]:=If[0<=time<=2,scale time,sawtooth[scale (time-2)]]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Plot[sawtooth@t,{t,0,10}]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-x0yEOLmS8vE/VYqoqcSOo5I/AAAAAAAADZk/aSduNxysjco/s1600/Using%2BRecursion%2Bto%2BDefine%2Ba%2BPeriodic%2BFunction-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="196" src="https://3.bp.blogspot.com/-x0yEOLmS8vE/VYqoqcSOo5I/AAAAAAAADZk/aSduNxysjco/s320/Using%2BRecursion%2Bto%2BDefine%2Ba%2BPeriodic%2BFunction-1.png" width="320" /></a></div>
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: inherit;">How does the recursion work? If t => 2, sawtooth keeps subtracting 2 from t recursively until t is back in the range 0 <= t <= 2 </span>and computes that value for y. We can see sample values of a function plotted with DiscretePlot.<br />
<br />
<b><span style="font-family: "courier new" , "courier" , monospace;">DiscretePlot[sawtooth@t,{t,0,6,0.2},PlotTheme->"Web"]</span></b><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-O4QaKKjdx8k/VYvrARMOP2I/AAAAAAAADaM/1K_ov12ZwdU/s1600/Using%2BRecursion%2Bto%2BDefine%2Ba%2BPeriodic%2BFunction-1-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="204" src="https://4.bp.blogspot.com/-O4QaKKjdx8k/VYvrARMOP2I/AAAAAAAADaM/1K_ov12ZwdU/s320/Using%2BRecursion%2Bto%2BDefine%2Ba%2BPeriodic%2BFunction-1-2.png" width="320" /></a></div>
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
Of course a faster way of defining the domain is to use Mod, but there is a lesson here. We don't need the speed of Mod, so either implementation is fine - using Mod for the most compact and fast function, or using an elegant new recursive technique to learn it. This function omits the values at multiples of 2, but is effectively the same function:<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Clear@sawtooth2;sawtooth2[time_,scale_:1]:=scale Mod[time,2]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<i>Mathematica</i> has built-in functions to produce various canonical waveforms such as SawtoothWave. Here are square and triangular wave examples.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;"><b>Plot[SquareWave[{-50,50},t],{t,0,10},ExclusionsStyle->Dotted,AxesLabel->{"time (mS)","mV"},PlotLabel->"Electric potential at the electrode"]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-mMdm_DgoGuo/VYqoxCbrGuI/AAAAAAAADZs/VTf3D_eG0yw/s1600/Using%2BRecursion%2Bto%2BDefine%2Ba%2BPeriodic%2BFunction-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="190" src="https://1.bp.blogspot.com/-mMdm_DgoGuo/VYqoxCbrGuI/AAAAAAAADZs/VTf3D_eG0yw/s320/Using%2BRecursion%2Bto%2BDefine%2Ba%2BPeriodic%2BFunction-2.png" width="320" /></a></div>
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><br /></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b>Plot[TriangleWave[{-40,10},t],{t,0,10},AxesLabel->{"time (mS)","mV"},PlotLabel->"Electric potential seen by the axon"]</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-QJLjTZL1jG8/VYqo3lWNcJI/AAAAAAAADZ0/Htpq4n5dSQs/s1600/Using%2BRecursion%2Bto%2BDefine%2Ba%2BPeriodic%2BFunction-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="190" src="https://4.bp.blogspot.com/-QJLjTZL1jG8/VYqo3lWNcJI/AAAAAAAADZ0/Htpq4n5dSQs/s320/Using%2BRecursion%2Bto%2BDefine%2Ba%2BPeriodic%2BFunction-3.png" width="320" /></a></div>
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span>
<span style="font-family: "courier new" , "courier" , monospace;"><b><br /></b></span></div>
<iframe frameborder="0" marginheight="0" marginwidth="0" scrolling="no" src="//ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&source=ss&ref=ss_til&ad_type=product_link&tracking_id=concordpoetry-20&marketplace=amazon&region=US&placement=0123741645&asins=0123741645&linkId=JPKYLA63JE4ZV26A&show_border=true&link_opens_in_new_window=true" style="height: 240px; width: 120px;">
</iframe></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-20361923219175849292015-06-20T17:49:00.000-04:002015-06-21T12:44:26.236-04:00Recursive Programming: The General Principle<div dir="ltr" style="text-align: left;" trbidi="on">
Recursion, where a function calls itself, is a fundamental programming method. Recursion is a different way of iterating over a List than using a loop. <i>Recurse </i>is from the Latin <i>recurrere</i>, to run back (I picture a dog retrieving a stick over and over).<br />
<br />
There are two principles of writing a recursive function, which is piecewise:<br />
<ol style="text-align: left;">
<li>Recursive case: Define a function f(n+1) recursively in terms of f(n), or equivalently, f(n) in terms of f(n-1)</li>
<li>Base case: Define one or more base cases, which are stopping points for the recursion, so that it doesn't become infinite. </li>
</ol>
An elementary example is exponentiation defined this way:<br />
<br />
x<sup>n </sup>= x•x<sup>(n-1)</sup><br />
<br />
First we define the base case, so that <i>Mathematica </i>will match it to prevent an infinite recursive loop. Let's just consider positive integers and zero. The base case is any integer raised to the 0<sup>th</sup> power equals 1.<br />
<br />
<b><span style="font-family: Courier New, Courier, monospace;">exponentiation[x_,0]:=1;</span></b><br />
<br />
The recursive case is:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>exponentiation[x_,n_Integer/;x>0]:=x exponentiation[x,n-1]</b></span><br />
<br />
Start testing a recursive function with the simplest examples:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>exponentiation[0,0]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">1</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>exponentiation[1,0]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">1</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>exponentiation[1,1]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">1</span><br />
<br />
Let's make sure the Condition requiring x > 0 works; it does.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>exponentiation[1,-1]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">exponentiation[1,-1]</span><br />
<br />
Trace shows the exponentiation hitting the base case and stopping.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>exponentiation[1,1]//Trace</b></span><br />
<span style="font-family: 'Courier New', Courier, monospace;">{exponentiation[1,1],1 exponentiation[1,1-1],{{1-1,0},exponentiation[1,0],1},1 1,1}</span><br />
<br />
To compute 2<sup>2</sup>, the function calls itself to computer 2<sup>2-1</sup> i.e. 2<sup>1</sup>, which in turn calls itself to compute 2<sup>0</sup>, which is the base case, 1. Once it has recursed down to the base case, it has a value to substitute in the preceding computations and the recursion 'unwinds.' All recursive functions work this way.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>exponentiation[2,2]//Trace</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">{exponentiation[2,2],2 exponentiation[2,2-1],{{2-1,1},exponentiation[2,1],2 exponentiation[2,1-1],{{1-1,0},exponentiation[2,0],1},2 1,2},2 2,4}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>exponentiation[2,10]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">1024</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>exponentiation[2,100]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">1267650600228229401496703205376</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>exponentiation[2,1000]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376</span><br />
<br />
<h3 style="text-align: left;">
Use Block for Large Recursions and Debugging</h3>
<br />
You may run into the built-in default recursion limit, $RecursionLimit, of 1024 when performing a large recursion.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>In[584]:= exponentiation[2,10000]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">During evaluation of In[584]:= $RecursionLimit::reclim: Recursion depth of 1024 exceeded. >></span><br />
<span style="font-family: Courier New, Courier, monospace;">Out[584]= Hold[exponentiation[2,8978-1]]</span><br />
<br />
The safe way to exceed the limit is using <a href="http://mathematica-guide.blogspot.com/2015/06/use-block-to-temporarily-block-global.html" target="_blank">Block</a>. Block temporarily changes the value of a Global or System variable. I've suppressed the output here since it is 3,011 digits long, but you <i>can </i>try this safely at home without "//IntegerDigits//Length".<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>Block[{$RecursionLimit=10050},exponentiation[2,10000]]//IntegerDigits//Length</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">3011</span><br />
<br />
<i>Mathematica </i>will warn you and stops an infinite recursion with a default recursion limit specified by $RecursionLimit ($IterationLimit is used similarly to stop infinite loops).<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>{$RecursionLimit,$IterationLimit}</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">{1024,4096}</span><br />
<br />
Just as you can use Block to temporarily exceed $RecursionLimit, you can use Block to temporarily 'tighten up' $RecursionLimit while writing a recursive function.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>In[592]:= Block[{$RecursionLimit=20},factorial@x_:=x*factorial[x-1];factorial@2]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">During evaluation of In[592]:= $RecursionLimit::reclim: Recursion depth of 20 exceeded. >></span><br />
<span style="font-family: Courier New, Courier, monospace;">Out[592]= Hold[factorial[-14-1]]</span><br />
<br />
Always remember to write the base case rule!<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>In[593]:= Block[{$RecursionLimit=20},factorial@x_:=x*factorial[x-1];factorial@0=1;factorial@2]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">Out[593]= 2</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: inherit;">Now we may safely compute the factorial of larger numbers:</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"><b>factorial@200</b></span><br />
<span style="font-family: Courier New, Courier, monospace;"></span><br />
<span style="font-family: Courier New, Courier, monospace;">788657867364790503552363213932185062295135977687173263294742533244359449963403342920304284011984623904177212138919638830257642790242637105061926624952829931113462857270763317237396988943922445621451664240254033291864131227428294853277524242407573903240321257405579568660226031904170324062351700858796178922222789623703897374720000000000000000000000000000000000000000000000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: inherit;">Note all the zeroes at the end. They must be from each time a multiple of 10 is incorporated into the factorial.</span></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0tag:blogger.com,1999:blog-1578495381497154301.post-38232001166580851762015-06-09T18:05:00.002-04:002015-06-11T08:57:18.327-04:00File Operations: Find and Print Files in Mathematica<div dir="ltr" style="text-align: left;" trbidi="on">
It's easy to find files in Mathematica with FindFiles and wildcards. The only thing you have to remember is that the 2nd argument, which specifies the directories to search must be a List even if you only specify one directory.<br />
<br />
What did I put in my init.m files to <a href="http://mathematica-guide.blogspot.com/2014/03/load-functions-at-startup-using.html" target="_blank">automatically load Packages</a>? Let's find and print init.m. A directory intended for a user's init.m file $UserBaseDirectory<>Kernel.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>folderToSearch=FileNameJoin@{$UserBaseDirectory,"Kernel"}</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">C:\Users\kwcarlso\AppData\Roaming\Mathematica\Kernel</span><br />
<br />
The wildcard will retrieve all files in the directory.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>filePath=FileNames["*",folderToSearch]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">{C:\Users\kwcarlso\AppData\Roaming\Mathematica\Kernel\init.m}</span><br />
<br />
We use FilePrint to print it. Use First@ or Sequence@@ to <a href="http://mathematica-guide.blogspot.com/2012/11/how-to-lose-list-brackets-in-mathematica.html" target="_blank">remove the unnecessary List brackets</a> around the filepath.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>FilePrint@First@filePath</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">(*</span><br />
<span style="font-family: Courier New, Courier, monospace;">(** User Mathematica initialization file **)</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">Print@"Hello World from your kernel init.m file! I'm located in:\n</span><br />
<span style="font-family: Courier New, Courier, monospace;">C:\\Users\\kwcarlso\\AppData\\Roaming\\Mathematica\\Kernel.\n"</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">Print@"Loading C:\\Users\\kwcarlso\\AppData\\Roaming\\Mathematica\\Scribble.m\n"</span><br />
<span style="font-family: Courier New, Courier, monospace;"><<"C:\\Users\\kwcarlso\\AppData\\Roaming\\Mathematica\\Scribble.m"</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">Print@"Loading C:\\Users\\kwcarlso\\Dropbox\\Mathematica\\Initialization\\Pre-Load Functions.txt.\n"</span><br />
<span style="font-family: Courier New, Courier, monospace;"><<"C:\\Users\\kwcarlso\\Dropbox\\Mathematica\\Initialization\\Pre-Load Functions.txt"</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">(* put this in Pre-Load Functions at some point? </span><br />
<span style="font-family: Courier New, Courier, monospace;">On[General::newsym] *)</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">Print@"Loading C:\\Program Files\\Wolfram Research\\Mathematica\\9.0\\AddOns\\ExtraPackages\\Utilities\\cleanSlate.m\n"</span><br />
<span style="font-family: Courier New, Courier, monospace;"><<"C:\\Program Files\\Wolfram Research\\Mathematica\\9.0\\AddOns\\ExtraPackages\\Utilities\\cleanSlate.m"</span><br />
<span style="font-family: Courier New, Courier, monospace;">*)</span><br />
<br />
Suppose we wanted to search for all files of a given type in Mathematica's default List of filepaths, $Path, like "init.m". Important! Note that $Path includes the root directory "." and my user root directory "C:\Users\kwcarlso." We don't want to search those so we find their Positions in $Path (need to add a backslash to the path separators since a single backslash tells Mathematica to treat the following character specially and a double backslash is treated as a single backslash).<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">omitPaths=Position[$Path,#]&/@{".","C:\\Users\\kwcarlso"}</span><br />
<span style="font-family: Courier New, Courier, monospace;">{{{8}},{{9}}}</span><br />
<br />
Using Drop to lose the directories at the two Positions we found, we search the remaining ones but still get far too many files. You can evaluate this command in your Notebook if you wish.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>tooManyFiles=FileNames["init.m",Drop[$Path,Flatten@omitPaths],Infinity];</b></span><br />
<br />
So let's just specify the directories that we want with the inner List in Part.<br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>desiredDirectories=$Path[[{2,3,5}]]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">{C:\Users\kwcarlso\AppData\Roaming\Mathematica\Kernel,C:\Users\kwcarlso\AppData\Roaming\Mathematica\Autoload,C:\ProgramData\Mathematica\Kernel}</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><b>autoloadFileNames=FileNames["*",desiredDirectories]</b></span><br />
<span style="font-family: Courier New, Courier, monospace;">{C:\ProgramData\Mathematica\Kernel\init.m,C:\Users\kwcarlso\AppData\Roaming\Mathematica\Autoload\PacletManager,C:\Users\kwcarlso\AppData\Roaming\Mathematica\Kernel\init.m}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: inherit;">To search all subdirectories in the directories, add a third argument, "Infinity", or an integer to limit the depth searched.</span><br />
<span style="font-family: inherit;"><br /></span>
<b style="font-family: 'Courier New', Courier, monospace;">autoloadFileNames=FileNames["*",desiredDirectories,Infinity];</b></div>
Krishttp://www.blogger.com/profile/00932979261710013619noreply@blogger.com0