<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5336307408263929381</id><updated>2012-01-09T17:30:09.344-08:00</updated><category term='pattern matching'/><category term='mathematica'/><category term='Floyd-Warshall'/><category term='animation'/><category term='o&apos;reilly'/><category term='all pairs shortest paths'/><category term='graph theory'/><category term='sal mangano'/><category term='tutorial'/><category term='network'/><category term='bubble sort'/><category term='review'/><category term='book'/><title type='text'>Mathematica News</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mathematicanews.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5336307408263929381/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://mathematicanews.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Flying Frog Consultancy Ltd.</name><uri>http://www.blogger.com/profile/11059316496121100950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>4</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5336307408263929381.post-7470851423340008905</id><published>2010-07-30T14:06:00.000-07:00</published><updated>2010-07-30T14:07:01.104-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='bubble sort'/><category scheme='http://www.blogger.com/atom/ns#' term='pattern matching'/><title type='text'>Bubble sort in a Mathematica pattern</title><content type='html'>&lt;p&gt;The Mathematica programming language has many unusual characteristics, two of which are:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Everything is an expression.&lt;/li&gt;&lt;li&gt;Pattern-based rewrite rules are obscenely powerful.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These kinds of characteristics are the foundation of what makes Mathematica a powerful programming language. For example, the bubble sort algorithm can be implemented in a single line without a loop in Mathematica using a single conditional rewrite rule that exchanges adjacent elements when they are out of order:&lt;/p&gt;&lt;pre&gt;&lt;p&gt;bubble[xs___, x_, y_, ys___] := bubble[xs, y, x, ys] /; x &gt; y&lt;/p&gt;&lt;/pre&gt;&lt;p&gt;This definition causes a new rewrite rule to be injected into Mathematica's global table of rewrite rules. Mathematica then applies this rule to any subexpression it sees that has the form &lt;span style="font-family:courier new;"&gt;bubble[..]&lt;/span&gt;. The pattern on the left side of the rule searches for a pair of adjacent arguments (&lt;span style="font-family:courier new;"&gt;x&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;y&lt;/span&gt;) to &lt;span style="font-family:courier new;"&gt;bubble&lt;/span&gt; where &lt;span style="font-family:courier new;"&gt;x&gt;y&lt;/span&gt;. If the pattern matches then the expression is rewritten such that &lt;span style="font-family:courier new;"&gt;x&lt;/span&gt; and &lt;span style="font-family:courier new;"&gt;y&lt;/span&gt; are exchanged.&lt;/p&gt;&lt;p&gt;This example not only demonstrates the remarkable expressiveness of the Mathematica programming language but also some of the ensuing problems. We have no idea how efficiently Mathematica's pattern matcher will find adjacent elements that are out of order and it is unlikely that Mathematica will optimize this down to an in-place swap. Consequently, we cannot begin to predict how much time or space this function will require. A quick benchmark shows that sorting 100 small integers this way takes a whopping 0.63 seconds!&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5336307408263929381-7470851423340008905?l=mathematicanews.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mathematicanews.blogspot.com/feeds/7470851423340008905/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mathematicanews.blogspot.com/2010/07/bubble-sort-in-mathematica-pattern.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5336307408263929381/posts/default/7470851423340008905'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5336307408263929381/posts/default/7470851423340008905'/><link rel='alternate' type='text/html' href='http://mathematicanews.blogspot.com/2010/07/bubble-sort-in-mathematica-pattern.html' title='Bubble sort in a Mathematica pattern'/><author><name>Flying Frog Consultancy Ltd.</name><uri>http://www.blogger.com/profile/11059316496121100950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5336307408263929381.post-5901860393319951742</id><published>2010-07-30T11:38:00.000-07:00</published><updated>2010-07-30T11:49:08.467-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='graph theory'/><category scheme='http://www.blogger.com/atom/ns#' term='all pairs shortest paths'/><category scheme='http://www.blogger.com/atom/ns#' term='network'/><category scheme='http://www.blogger.com/atom/ns#' term='Floyd-Warshall'/><title type='text'>All pairs shortest paths</title><content type='html'>&lt;p&gt;The all-pairs shortest paths algorithm from graph theory computes the shortest paths from every vertex in a graph to every other vertex. The graph may be directed or undirected and may have weighted edges and even negative weights. The algorithm used is called Floyd-Warshall and it takes O(n&lt;sup&gt;3&lt;/sup&gt;) time and O(n&lt;sup&gt;2&lt;/sup&gt;) space where n is the number of vertices in the graph.&lt;/p&gt;&lt;p&gt;Although Wolfram Research &lt;a href="http://numb3rs.wolfram.com/413/"&gt;cheekily worked this example into the Numb3rs TV show&lt;/a&gt;, Mathematica does not actually provide a complete implementation of the algorithm required to obtain the shortest paths but, rather, is only able to return the path lengths and further information that can be used to derive the paths themselves.&lt;/p&gt;&lt;p&gt;After considerable effort, we arrived at the following program to solve the all-pairs shortest paths problem for an example 1,005-vertex graph:&lt;/p&gt;&lt;p&gt;&lt;a href="http://2.bp.blogspot.com/_NMRkpon4Ps0/TFMdr_ZVmSI/AAAAAAAAAIg/DK6q83Sz9j0/s1600/AllPairsShortestPaths.png"&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 270px; DISPLAY: block; HEIGHT: 400px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5499772211538794786" border="0" alt="" src="http://2.bp.blogspot.com/_NMRkpon4Ps0/TFMdr_ZVmSI/AAAAAAAAAIg/DK6q83Sz9j0/s400/AllPairsShortestPaths.png" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;The errors are an unfortunate consequence of running Mathematica 7.0.1 on a two-socket 8-core 2.0GHz Intel E5405 Xeon machine because this causes half of Mathematica's kernels to die when trying to make use of parallelism (so half of the machine's power is wasted!). As you can see, the program took 13.9s to run.&lt;/p&gt;&lt;p&gt;Hopefully this program will help anyone else who wants to solve this problem using Mathematica.&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5336307408263929381-5901860393319951742?l=mathematicanews.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mathematicanews.blogspot.com/feeds/5901860393319951742/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mathematicanews.blogspot.com/2010/07/all-pairs-shortest-paths.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5336307408263929381/posts/default/5901860393319951742'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5336307408263929381/posts/default/5901860393319951742'/><link rel='alternate' type='text/html' href='http://mathematicanews.blogspot.com/2010/07/all-pairs-shortest-paths.html' title='All pairs shortest paths'/><author><name>Flying Frog Consultancy Ltd.</name><uri>http://www.blogger.com/profile/11059316496121100950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_NMRkpon4Ps0/TFMdr_ZVmSI/AAAAAAAAAIg/DK6q83Sz9j0/s72-c/AllPairsShortestPaths.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5336307408263929381.post-1384262037741402407</id><published>2010-07-30T11:29:00.000-07:00</published><updated>2010-07-30T11:30:09.451-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='animation'/><category scheme='http://www.blogger.com/atom/ns#' term='tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='mathematica'/><title type='text'>Animations explaining Mathematica functions</title><content type='html'>&lt;p&gt;Here's &lt;a href="http://documents.wolfram.com/flash/"&gt;a fun web page&lt;/a&gt; from Wolfram Research that has animations for a bunch of Mathematica's built-in functions.&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5336307408263929381-1384262037741402407?l=mathematicanews.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mathematicanews.blogspot.com/feeds/1384262037741402407/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mathematicanews.blogspot.com/2010/07/animations-explaining-mathematica.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5336307408263929381/posts/default/1384262037741402407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5336307408263929381/posts/default/1384262037741402407'/><link rel='alternate' type='text/html' href='http://mathematicanews.blogspot.com/2010/07/animations-explaining-mathematica.html' title='Animations explaining Mathematica functions'/><author><name>Flying Frog Consultancy Ltd.</name><uri>http://www.blogger.com/profile/11059316496121100950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5336307408263929381.post-7701755805075987662</id><published>2010-07-30T11:27:00.000-07:00</published><updated>2010-07-30T11:28:22.417-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='o&apos;reilly'/><category scheme='http://www.blogger.com/atom/ns#' term='review'/><category scheme='http://www.blogger.com/atom/ns#' term='sal mangano'/><category scheme='http://www.blogger.com/atom/ns#' term='mathematica'/><category scheme='http://www.blogger.com/atom/ns#' term='book'/><title type='text'>Book review: Mathematica Cookbook by Sal Mangano</title><content type='html'>&lt;p&gt;O'Reilly just published a new book, the &lt;a href="http://oreilly.com/catalog/9780596521004"&gt;Mathematica Cookbook&lt;/a&gt;, about Wolfram Research's flagship product. This book contains many interesting examples from various different disciplines. Most of these are derived from freely available examples written by other people (primarily from Wolfram Research's original Mathematica Book and also the excellent &lt;a href="http://demonstrations.wolfram.com/"&gt;Wolfram Demonstrations Project&lt;/a&gt;) but the author has simplified some of the programs to make them more accessible.&lt;/p&gt;&lt;p&gt;However, the density of the information in this book is incredibly low. Most pages are filled with superfluous Mathematica output that is often not even described in the text:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Dozens of triples on page 15.&lt;/li&gt;&lt;li&gt;Page 58 lists hundreds of numbers but the text does not even describe their significance.&lt;/li&gt;&lt;li&gt;Page 205 lists all of the words with a subset of the letters "thanksgiv".&lt;/li&gt;&lt;li&gt;Page 226 is raw XML data.&lt;/li&gt;&lt;li&gt;Pages 264-265 are solid code that renders a snowman with circles and some dots for snow (all in black and white).&lt;/li&gt;&lt;li&gt;Pages 303-304 are two more pages of code to plot a snowman in 3D.&lt;/li&gt;&lt;li&gt;Page 321 lists all of the properties in Mathematica's polyhedron database and page 322 draws 20 polyhedra before page 324 enumerates exactly the same polyhedron properties again.&lt;/li&gt;&lt;li&gt;Pages 334-335 enumerate image data numerically (three times).&lt;/li&gt;&lt;li&gt;Page 359 displays quadrant swapping with 25x more matrix elements than necessary.&lt;/li&gt;&lt;li&gt;Page 360 is the Fourier transform of an image and page 361 is an apparently identical one.&lt;/li&gt;&lt;li&gt;Page 507 lists every chemical element and page 571 lists every property of them.&lt;/li&gt;&lt;li&gt;Page 553 lists every property available for financial data and page 554 lists them all over again.&lt;/li&gt;&lt;li&gt;Page 572 contains an empty graph.&lt;/li&gt;&lt;li&gt;and so on...&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Many pages are devoted to &lt;span style="font-family:courier new;"&gt;TreeForm&lt;/span&gt; plots of trees that convey no useful information, e.g. the trees drawn on page 129 in the section about red-black trees:&lt;/p&gt;&lt;p&gt;&lt;a href="http://4.bp.blogspot.com/_NMRkpon4Ps0/TDt8TqBEVOI/AAAAAAAAAIM/UDLa8XYMp24/s1600/TreeForm.png"&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 361px; DISPLAY: block; HEIGHT: 400px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5493120847646577890" border="0" alt="" src="http://4.bp.blogspot.com/_NMRkpon4Ps0/TDt8TqBEVOI/AAAAAAAAAIM/UDLa8XYMp24/s400/TreeForm.png" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Would have been nice to see red and black colored nodes or even learn how to do that using Mathematica (assuming it is possible). In particular, half of page 115 is a &lt;span style="font-family:courier new;"&gt;TreeForm&lt;/span&gt; view so badly laid out by Mathematica that it is unreadable.&lt;/p&gt;&lt;p&gt;There are also some problems with the technical content itself. For example, the section on red-black trees is a simple translation from Okasaki's excellent book "Purely functional data structures". The only new functionality Sal Mangano added is a &lt;span style="font-family:courier new;"&gt;remove&lt;/span&gt; function but his implementation is completely wrong.&lt;/p&gt;&lt;p&gt;The book is chocked full of advice about optimization. This is both good and bad. Good because Mathematica users need all the help they can get with performance because Mathematica is so slow. Bad because the best advice for a Mathematica user when performance is even vaguely relevant is to ditch Mathematica in favor of a more modern tool with better performance. For example, section 14.10 "Compiling an Implementation of Explicit Trinomial for Fast Pricing of American Options" states that "You need a very fast pricer for American options" but the fastest Mathematica code given can be &lt;a href="http://fsharpnews.blogspot.com/2010/07/f-vs-mathematica-even-faster-pricer-for.html"&gt;a whopping 960× slower than a comparably-simple F# solution&lt;/a&gt;. Furthermore, it turns out that this was not written by Sal Mangano (the author of the book) but by &lt;a href="http://216.80.120.13:8080/webMathematica/LC/explicit.jsp"&gt;Andreas Lauschke&lt;/a&gt; (a Mathematica and Java consultant) and it is a translation of MATLAB code written by Ansgar Jüngel (an academic).&lt;/p&gt;&lt;p&gt;There are several multi-page program listings written as plain Mathematica code with embedded comments that are difficult to read (they are not even spaced out, let alone typeset properly!) instead of prose. Page 265 is a block of code, for example:&lt;/p&gt;&lt;a href="http://2.bp.blogspot.com/_NMRkpon4Ps0/TDuHaOGkcHI/AAAAAAAAAIU/orl8FiMl8eM/s1600/MathematicaCookbookPage265.jpg"&gt;&lt;img style="TEXT-ALIGN: center; MARGIN: 0px auto 10px; WIDTH: 306px; DISPLAY: block; HEIGHT: 400px; CURSOR: hand" id="BLOGGER_PHOTO_ID_5493133055040450674" border="0" alt="" src="http://2.bp.blogspot.com/_NMRkpon4Ps0/TDuHaOGkcHI/AAAAAAAAAIU/orl8FiMl8eM/s400/MathematicaCookbookPage265.jpg" /&gt;&lt;/a&gt; &lt;p&gt;Although the book does contain a frustrating amount of blatant filler, it is very cheap (O'Reilly) and does contain several thought-provoking examples. Whether you use Mathematica or not, you'll probably learn something useful about the state-of-the-art in the Mathematica world by skimming this book. On a higher level, you will probably learn a lot more about business if you consider what this book and the army of Mathematica devotees behind it represent. After all, there is a lot of money in starting a religion!&lt;/p&gt;&lt;p&gt;FWIW, here are the interesting references from the book to original sources:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.cs.utep.edu/interval-comp/"&gt;Interval Computations&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/algoen.htm"&gt;Sequential and parallel sorting algorithms&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;&lt;a href="http://nova.umuc.edu/~jarc/idsv/lesson1.html"&gt;Interactive data structure visualizations&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;&lt;a href="http://norvig.com/spell-correct.html"&gt;How to write a spelling corrector&lt;/a&gt; by Peter Norvig (of Google).&lt;/li&gt;&lt;li&gt;&lt;a href="http://library.wolfram.com/conferences/devconf99/lichtblau/"&gt;Data structures and efficient algorithms in Mathematica&lt;/a&gt; by Daniel Lichtblau.&lt;/li&gt;&lt;li&gt;&lt;a href="http://pdos.csail.mit.edu/~baford/packrat/"&gt;Packrat parsing&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;&lt;a href="http://blog.wolfram.com/2009/09/11/twisted-architecture/"&gt;Twisted architecture&lt;/a&gt; by Chris Carlson.&lt;/li&gt;&lt;li&gt;&lt;a href="http://fourier.eng.hmc.edu/e161/lectures/contrast_transform/node3.html"&gt;Histogram equalization&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;&lt;a href="http://cvc.yale.edu/projects/yalefaces/yalefaces.html"&gt;The Yale face database&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.cs.otago.ac.nz/cosc453/student_tutorials/principal_components.pdf"&gt;A tutorial on Principal Components Analysis&lt;/a&gt; by Lindsay I Smith.&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.math.upenn.edu/~wilf/gfology2.pdf"&gt;Generatingfunctionology&lt;/a&gt; by Hilbert S Wilf.&lt;/li&gt;&lt;li&gt;&lt;a href="http://demonstrations.wolfram.com/PredatorPreyDynamicsWithTypeTwoFunctionalResponse/"&gt;Predator-Prey dynamics with type-2 functional response&lt;/a&gt; by Wilfried Gabriel.&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.sv.vt.edu/classes/MSE2094_NoteBook/97ClassProj/num/midkiff/theory.html"&gt;Theory of Finite Element Analysis&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.weber-und-partner.com/resources/index.htm"&gt;Finance-related Mathematica resources&lt;/a&gt; from Weber &amp;amp; Partner.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5336307408263929381-7701755805075987662?l=mathematicanews.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mathematicanews.blogspot.com/feeds/7701755805075987662/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://mathematicanews.blogspot.com/2010/07/book-review-mathematica-cookbook-by-sal.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5336307408263929381/posts/default/7701755805075987662'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5336307408263929381/posts/default/7701755805075987662'/><link rel='alternate' type='text/html' href='http://mathematicanews.blogspot.com/2010/07/book-review-mathematica-cookbook-by-sal.html' title='Book review: Mathematica Cookbook by Sal Mangano'/><author><name>Flying Frog Consultancy Ltd.</name><uri>http://www.blogger.com/profile/11059316496121100950</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_NMRkpon4Ps0/TDt8TqBEVOI/AAAAAAAAAIM/UDLa8XYMp24/s72-c/TreeForm.png' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
