Sunday, March 24, 2013

A new kind of square root


The postmodernism generator has been translated to mathematics. Now there is a program called Mathgen that outputs nonsensical papers on the advances of mathematics, complete with theorems and references. It has certain idiosynchrasies that makes it easy to recognize its papers. Authors are often drawn from among the most famous names of mathematics, but usually getting the first initial wrong. Theorems and conjectures are generously attributed to pairs of collegues across history, often using centuries old personalities as authors of brand new theories. Who has ever heard of the Conway-d'Alembert conjecture? Well, now we have.

The tone is exactly as condescending as one might fear: 'Clearly' such and such result follows; 'as every student knows …', and what follows is invariably clear as mud. Proofs are safely omitted because they are 'obvious'.

All this remarkable research, those 'little known results', are published safely beyond accessibility in Transactions of the Kenyan Mathematical Society, South Korean Journal of Integral Category Theory, Iranian Journal of Homological PDE, and the like. Surely most of these publications cannot be found at your local library anytime soon.

It is not hard to generate plain gibberish by TeX. Begin with listing a few elementary symbols and operators:

const char *alpha = "\\alpha";
const char *beta = "\\beta";
...
const char *r_arrow = "\\rightarrow";
const char *sqrt = "\\sqrt";
const char *sup = "^ ";
const char *sub = "_ ";

Put all the symbols in an array, so they can be easily accessed and picked at random. Concatenate several of the symbols into a string and print it. With some luck, the symbol sequence will not break the TeX syntax. This doesn't happen by itself, so next one might like to do something more structured. Elementary functions (program routines, that is) that generate small expressions like x ∈ ℂ2 or f : ℝ → ℝ are not hard to write.

This is a sample of the babbling that results from the mere concatenation of a few symbols and numbers without regard for syntactical rules:



Difficulties arise when operators are used, because these expect arguments. An expression should not end with, say, an empty square root with no argument, as the above formula seems to do. In fact it ends with \sqrt{%0^{\sum}}, but this is apparently beyond the wits of TeX.


The notorious mathgen paper Independent, Negative, Canonically Turing Arrows of Equations and Problems in Applied Formal PDE by M. Rathke contains a larger sortiment of abstruse mathematical symbols in hilarious combinations. Or what about the frequent use of various powers of zero? Already the first formula contains expressions such as 0-4, 05, and other meaningless entities such as tan(∞-1). A judicious use of elaborate idempotent expressions may even accidentally result in a true statement despite the funny appearance.


Tuesday, February 26, 2013

Sunday, February 17, 2013

Total variation


The total variation of a real valued function f on an interval I is defined as
taking the supremum over all possible partitions of I = [p0, pN]. Notably, if the function is (continuously) differentiable, the total variation becomes
but f does not have to be differentiable, and the total variation may be unbounded.

Sometimes the function itself may be evaluated at any point of the interval, although its derivative either does not exist or is far too complicated to deal with. Then the total variation may be estimated by sampling the function at several points and checking whether or not it converges to some limit as the mesh gets finer. If it doesn't, the curve may be a fractal, so its fractal dimension can be estimated from the procedure.

The length of a fractal curve is a function of the scale of measurement. As the scale of measurement ε varies, the measured length N varies according to N ~ ε −D, where D is the fractal dimension. The common procedure then is to fit a double logarithmic plot of N against ε and finding the slope. However, it would be a grave mistake to blindly accept any automatically calculated slope without checking the error of the fit.

Estimating the total variation at several arbitrary sampling resolutions can be inefficient, unless a clever trick is used. Suppose we begin with a fine resolution with uniform distance Δ = xi - xi-1 > 0 between the points. Then it is easy to obtain the total variation for subdivisions by nΔ, for n = 1, 2, … just by skipping so many points. Even better, one can take averages
so as to obtain estimates that do not depend (as much) on the particular chosen sample points.  

A somewhat related concept is arc length, which is, conceptually, the length of a string superposed on the graph of the function (assuming the function is continuous). The total variation is smaller than the arc length. For the straight line y = kx, 0 < x < t, the total variation squared is V2 = (kt)2 as compared to the arc length squared which is t2+(kt)2. Now suppose the function is monotonous over the interval under consideration. Then, if the function is deformed so as to become more curved, only the arc length will increase while the total variation remains the same. For example, if fn(x) = xn, 0 ≤ x ≤ 1 and n = 1, 2, ..., then the arc length approaches 2 as n increases, whereas the total variation remains 1.

Saturday, January 26, 2013

The derivative of products

An elementary proof 

Knowing some important formulas by heart can be very useful, but if one knows how to derive them, it is no longer necessary to remember the formula. From reading math textbooks (many — or most of them?), one can gain the false impression that the process of deriving a formula follows the same sequence as the proof.

Here is an elementary proof that nevertheless involves some not so obvious steps. 

Suppose that


then the formula for the derivative is 


but how do we prove this? Although the proof is straightforward, it is perhaps difficult to remember all the tricks that are required and when to apply them. Here is a standard proof. First, apply the definition of derivative to the product of the two functions:



The next step is the crucial operation, at once trivial and far from obvious. We are going to both subtract and add u(x)v(x+h) and rewrite the ratio as


Now, who would think of adding two terms that sum to 0 into such an expression? This is an idea that doesn't make much sense at this point. Indeed, one needs to look a few steps ahead and see what it is going to be needed for. What follows are just some simple factorizations of terms.


Break out some terms to get 


then take limits and replace derivatives, and we are done:




Here, the simple formula seems much easier to memorize than all the steps of the proof. (In fact, you may impress your friends far more if you memorize Hugo Ball's poem Karawane than if you learn to recite the steps of this proof.)

It is highly misleading when formulas such as the above are just plainly stated and then concisely proven. This is most likely not how the formulas were originally discovered. Rather, one would observe a few instances of derivatives of multiplied functions and conjecture a formula. Then, starting from the formula as well as the definition of derivative, one would work backwards and find all the arithmetic manipulations that make the proof work.

Instead of learning a fixed set of steps that are used in particular proofs, one would probably learn a bag of tricks that can be applied in various situations. Then, out of this bag one can grab various operations that can be tried out, until something is found that leads the proof in a promising direction.


Tuesday, January 15, 2013

Against gadgetry


Purportedly intelligent functionality increasingly finds its way into consumer electronics of all kinds. Consider video cameras as an example. Instead of manual brightness and focus controls, these can be handled automatically by pointing the camera at the right target. Fine, except that this makes it more difficult to gain control over the footage if the automation cannot be overridden.

In theory, it would be possible to have a function on your camera that finds out the name of a person whose face you point it at. Similar risks and annoyances are likely to crop up in all places where too much electronic connectivity is built into products.

Someone said that a good music instrument is one that allows you to play badly. It doesn't correct your mistakes, so you have to practice. If you have practiced and try playing a gadget that corrects your mistakes, it will only stand in your way.

There are many reasons to keep things simple and stupid. Open modular systems is one interesting trend offering the perfect antidote to these over-designed digital marvels.


Friday, January 11, 2013

Antropocene

An excellent resource for understanding the current understanding of climate change is the recent series of blog posts by John Baez. Whereas journalists oversimplify matters, diving straight into the research papers would be overwhelming. Baez is the ideal guide if you know some elementary mathematics (just the basics of ordinary differential equations will do). He begins by explaining concepts such as albedo and the energy balance due to incoming and reflected sunlight. Then some positive and negative feedback mechanisms are introduced, and there is a discussion of glacial cycles, bistable models and stochastic resonance. All of it is very accessibly explained; it is definitely worthwhile to take the time and digest this material.

It begins here with some slides and continues as a series of blog posts.

Another useful source of information is skeptical science, especially if one ever needs to debunk the myths that people pass on without checking the facts.

Sunday, December 23, 2012

Juggling with mutual recursion

Mutually recursive functions are not idiomatic in C, and can easily be avoided. However, they can be fun to play with. 

int f(int);
int g(int);

int f(int j)
{
   if (j > 0)
      return g(j-1);
   return 0;
}

int g(int j)
{
   if (j > 0)
      return f(j-2);
   return -1;
}

int main()
{
   return f(5);
}


Nothing remarkable here. The following, in contrast, doesn't work (at least not as expected).

int f(int j)
{
   if (j > 0)
      return g(j-1) - 2;   /* subtraction of -2 ignored */
}


As a proof of concept, here's a 2-D map which is iterated for as long as its coordinates stay in the first quadrant. In fact, the mutual recursion is here used for two alterating maps. It may appear that something strange such as this happens:

Actually, it's simpler:


void s(float x, float y);
void t(float x, float y);


void s(float x, float y)
{
   printf("s(%.5f, %.5f)\n", x, y);
   if(x >= 0.0 && y >= 0.0)
      
return t(x - 0.5, 1.2*y - .2*x);
}
void t(float x, float y)
{
   printf("t(%.5f, %.5f)\n", x, y);
  
if(x >= 0.0 && y >= 0.0)
      return s(1.2*x - .2*y, y-0.5);
}



This pair of functions differ by not using a return value as part of the recursion. Strange as it looks, it works.


Wednesday, December 5, 2012

Animation tutorial


Computer animation in C++ made easy.


Step 1. Write a sequence of frames to separate image files.
Step 2. Concatenate the frames into a video file.

No, there's no audio here.


For the first step, it is convenient to use a library such as pngwriter that takes care of storing the image in the correct file format  (however, this is neither the most flexible nor the most efficient solution). The frames should be named with an increasing series of numbers, e.g. img001.png, img002.png, img003.png and so on.

Then the frames can be converted to video using ffmpeg. Supposing the images reside in the folder imgfolder, a command like

ffmpeg -f image2 -r 25 -i imgfolder/img_%2d.png animfilm.avi

should do it. There are many other parameters to set, some of which need to be tweaked in order to obtain an acceptable quality. For the C++ program that generates the frames, the main loop may look somewhat as follows. (Note that these lines of code generate something slightly different than the video example above.)


int main()
{
const int W=720, H=576;
pngwriter pict(W, H, 0.0, "imgfolder/img.png");
char fname[32];
int i=0;
const int N = 100;
while(i++ < N)
 {
 float t = (float) i/N;
 pict.line(0, 2*N-i, W, 2*N-i/2, 0.5, 0.5, t);
 sprintf(fname, "imgfolder/img%03d.png", i);
 pict.pngwriter_rename(fname);
 pict.write_png();
}
pict.close();
}



To add audio to all of this (but why should you want to?), mux the video file with an audio file in ffmpeg.





ffmpeg -i soundfile.ogg -i animation.avi -acodec copy -vcodec copy muxedfilm.avi



Following all these steps, you have disqualified yourself to contribute to the monochrome video contest (black only, and no sound track).

Sunday, December 2, 2012

Sunday, November 25, 2012

Open access

The benefits of open-access publishing are widely acknowledged. The arXiv is a splendid site for keeping up-to-date on physics, mathematics, computer science and a few other fields. Just pick your specialization!

arXiv: adaptation and self-organization. This is where they compute with slime and synchronize oscillators. The Kuramoto model shows up every now and then. It seems to be tackled from ever more complicated angles each time.

arXiv: math, history and overview. Unlike more specialized fields, some papers in this section may be partially comprehensible even to lay people with an interest in mathematics.

While the arXiv offers its readers free access, their endorsement system does not allow everyone to publish with them. That is presumably why there is a site like vixra, which has no peer review at all and where anyone can submit papers. And so they do! Crackpots solve all the mysteries of the universe, and no one believes them. (Well, perhaps the truth is far too many believe them.) There is even a name for this sort of behaviour, it is called the Dunning-Kruger effect: incompetent individuals are not even able to realize that they are incompetent.

Then there are all these new open access journals with absurdly broad scope that often cannot be taken seriously.

Ubuweb is a different matter. Being included in their collection should be viewed as the equivalent of winning a prestigious prise, although some copyright holders may disagree. If they do, they should think twice. But ubuweb may not be with us forever.

Monday, November 19, 2012

Beyond Rorchach

What's in it?
Yet another thread.


  •  

Call for works:

Monochrome videos (black only), no sound track. Be creative and do something different!


Friday, November 16, 2012

Ambiguation

Concerning the origins of pataphysics

There is still the Collège de 'Pataphysique (the apostrophe is preferably dropped in non-french languages). Now, over a decade après l'Occultation, they are even more secretive than ever. As for Ubu-quity, the official college describes the all-pervasive character of pataphysics:
Nous trouvons la Pataphysique dans les Sciences Exactes ou Inexactes (ce qu’on n'ose avouer), dans les Beaux-Arts et les Laids, dans les Activités et Inactivités Littéraires de toutes sortes.
In short, pataphysics is found everywhere. The approximate sciences and the foul arts deserve some closer attention. Both of them appear to have some connection with so-called practice based research in art. And what about literary passivity? If everyone wants to become a famous author (with phynances galore), then who is going to read all their books?

Pardon the ambiguation, but this blog is not about pataphysics, although that is clearly impossible. My previous attempt in that direction had to be abandoned.

Sunday, November 11, 2012

Applied mathematics


Yes, but applied to what?


In material terms: Ink, pencil, chalk, spilled tea, thread and tape on paper. Applied to the back of an envelope.

Saturday, November 10, 2012

Editorial neglect

The Nonlinear Workbook 

by Willi-Hans Steeb. 

World Scientific 2011, 5th edition.


Beginning with chaos and dynamic systems, from one-dimensional maps and fractals to ordinary differential equations, the usual topics are presented succinctly in the first half of the book. Short chapters on chaos control and synchronization are also included. Then, the second half deals with topics that should be more familiar to computer scientists, such as neural networks, genetic algorithms, optimization, wavelets and fuzzy logic. This is a huge span of topics that cannot be covered in depth in a single volume. According to Steeb, most of these disparate fields are interrelated. If so, there is a valid motivation for presenting them in the same book and highlighting their relations. However, many interesting and often difficult fields are only presented in glimpses. The chapter on wavelets is a case in point; that material is not used in the rest of the book so the chapter might as well have been left out.

To be clear, this is not a book for beginners. It serves better as a complement to other literature, and to some extent it offers a different point of view than many other sources.

The book claims to balance a theoretical exposition with practical computer code. Several short stand-alone programs written in C++, Java and Symbolic C++ (the latter being a library developed by the author) form the backbone of the text. There is even a short routine in assembler. 
The treatment of chaotic systems is different from many other comparable texts in that exact numerical algorithms are used to study the iterations of maps. The SymbolicC++ library is used for this, but unfortunately this code is neither included nor explained in the book despite the many programs relying upon it.

The solution of ODEs is for a large part done with the Lie series technique, which is not very accessibly explained. Another frequently used technique is the Runge-Kutta-Fehlberg method, which makes use of a set of coefficients that are copied and pasted into each code snippet where they are needed. Needless to say, this makes for a lot of redundancy, which could easily have been avoided by placing this part of the code in an include file. In Chapter 11, where the integration techniques for ODEs should presumable be explained, the same mysterious coefficients appear again without any hint as to how they are derived (there is just a reference to the literature). This avoidance of explanations stands in stark contrast to the style of another, excellent source on scientific computation — the Numerical Recipes by Press et al. Although the Nonlinear Workbook is not at all on a par with Numerical Recipes regarding stylistic issues, clarity of presentation, and general usefulness, it does contain much material that cannot be found there (at least not in the third printed edition).

Already in its fifth edition, one would think that the Nonlinear Workbook has all kinds of editorial flaws sorted out by now. Unfortunately, this is not the case. The text suffers from a lack of efforts to organize the material. Skimming through the text, there appears to be no single illustration; in fact there are less than a dozen across its more than six hundred pages, but they are not very visually striking. Most books about chaos theory and matters cognate will include a number of elegant pictures of attractors or fractals; this one does not, except for the one on its cover. Certainly most readers will have already seen an assortment of representative fractals and attractors and do not need them printed in yet another book; better yet, using the code in the book one should be able to generate and experiment with them for oneself. However, a few explanatory diagrams would often make ideas in the text more accessible to the reader. Or how about trying to explain a Poincaré section in words and formulae, with no illustrations? That is surely a recipe for making simple things look hard.

On the whole, the book suffers from editorial neglect. Code examples are often given without any indentation, making nested routines hard to read. 
The copy-and-paste manner of coding does not make things any better. The prose is awkward in many places, such as the following:
If we want to compare two hidden Markov models then we need a measure for the distance between two hidden Markov models.
There is very little cross-referencing inside the book and the equations are almost never numbered. On the positive side, one never needs to turn the pages to find some equation that was introduced earlier. 

The level of exposition is also a bit uneven. Some sections assume rather much mathematical background, whereas others are quite accessible. Presumably someone who already is at ease with Lie series, exterior products and what not will have little need for the guidance provided by the code examples. Some programs are rather trivial and probably pose no difficulty to a first semester student of computer science. A few programs are far from trivial, however, and the lack of explanatory comments in the code as well as in the main text make them hard to understand. There are almost as little exercises as there are illustrations. Why should a text book have exercises at all, though? The intelligent reader will find his or her own problems to solve, spurred by puzzling remarks in the text or unproven propositions. 

To round up, this workbook provides glimpses into many fascinating topics, albeit presented in a less than ideal way. The text is too tersely written to serve as an introduction to any of the many fields that it covers, but may be valuable to someone who has studied the theory before.

See for yourself, sample chapters are available for free.