StackExchange sites proliferation

I am observing with great interest the development at Area51 for new Question/Answers sites to be opened with the StackExchange system. One thing that makes me cringe a bit is the very strong fragmentation. I think this stems either from the need of personal protagonism of each person (nothing bad with it, progress happens also thanks to personal protagonism), or by lack of notice that a similar proposal has already been done. I could be wrong though, and I accept criticism on this point.

Read More »

The Mandelbrot set, in python

This code is so fascinating

from PIL import Image

max_iteration = 1000
x_center = -1.0
y_center =  0.0
size = 300

im = Image.new("RGB", (size,size))
for i in xrange(size):
    for j in xrange(size):
        x,y = ( x_center + 4.0*float(i-size/2)/size,
                  y_center + 4.0*float(j-size/2)/size
                )

        a,b = (0.0, 0.0)
        iteration = 0

        while (a**2 + b**2 <= 4.0 and iteration < max_iteration):
            a,b = a**2 - b**2 + x, 2*a*b + y
            iteration += 1
        if iteration == max_iteration:
            color_value = 255
        else:
            color_value = iteration*10 % 255
        im.putpixel( (i,j), (color_value, color_value, color_value))

im.save("mandelbrot.png", "PNG")

If you execute the python code above, the result is this beautiful and mysterious picture:

Mandelbrot Set

Mandelbrot Set

What you see is a Fractal, a highly fractured geometric picture, and more specifically one of the most famous representatives: the Mandelbrot Set. I am not familiar at all with the mathematics behind fractals, so I won’t talk about them, or I will simply end up saying something wrong.

Such a highly featured and attractive picture is obtained from a really simple algorithm. It can be explained easily: take a grid of points on the plane, like for example a simple sheet of graph paper. Choose a scale for the axes. For every point (x,y) of the plane now do the following:

  1. start with an empty vector (a,b) containing (0.0, 0.0)
  2. create a new (a,b) vector as (a2 – b2 + x, 2ab + y)
  3. continue with the procedure given in 2. If the length of the vector (a,b) becomes larger than 2.0, plot the (x,y) point black or a shade of gray, depending how far you got in the iterations. Instead, if the length of the vector stays below 2.0 after a given maximum amount of iterations, plot the (x,y) point white.

This, as said, decides the color of one single point (hence, a pixel of the image). Repeat for all the pixels and what you obtain is the Mandelbrot set.

You can also think in terms of complex numbers, plotting on the complex plane. Instead of (a,b) we now have a single complex number z0, and instead of (x,y) we now have a complex number c. The repeated operation now can be described as

  1. z0 = 0.0
  2. c = current complex number expressed by the current pixel point on the complex plane
  3. repeatedly compute zn+1 = zn2 + c
  4. if the absolute value of z goes beyond 2.0, plot black or gray, otherwise plot white, as given before.

What if you change the starting point? What if we choose z0 = 1.0 instead of 0.0, or z0 = 1.0 i ? I tinkered with the program a bit. Here are the results. This image shows how the Mandelbrot Set changes when z0 goes from -3 to 3 (step 0.1). The set “blows away” towards the left, when going either towards -3 or +3.

If you change z0 along the imaginary axis, going from -3.0 i to 3.0 i, what you obtain is instead:

It blows away towards the right. So I said, what happens if I increase both the real part and the imaginary part together? will they “balance out” ? Not really. It burns away

I have absolutely no idea of what all this means. I thought it was just cool to try it out.

A Question/Answers site for Popular Science

The kind folks behind StackOverflow, a free Question/Answers website for programming questions, recently decided to open new Q/A websites for many additional interesting topics, from wine tasting and cooking to mathematics. The fundamental requisite for such new sites to be opened is a rather strict community review and development of a critical mass of contributors and interested people. On area51.stackexchange.com the proposals are collected and evaluated by the community.

I really enjoyed the proposal for a Popular Science Q/A site, and if the site is going to be opened, I will certainly be an active contributor. If you are interested, feel free to click on the link and then click “follow” on the proposal. This will largely increase the chances for such site to be opened. I am also positively interested and enthusiast for Q/A sites for Chemistry, Astronomy, Bioinformatics and, as a very old Dungeons and Dragons player, Role-Playing Games.

McNaught comet in the sky, and pics of Hale Bopp

The McNaught comet, or C/2009 R1,  is likely to be visible in the night sky starting tonight, for a week. You should be able to spot it near the constellation of Perseus as a fuzzy streak of light.

The comet should be visible with a small binocular, or just with the naked eye. In particular, I recommend using the so-called averted vision: don’t look directly at the comet, but do it laterally, with your peripheral vision. This same technique can be used to watch any faint objects, such as galaxies and nebulae. You will also need a clear sky and low light pollution: leave the city and get in the countryside. I suggest also adapting your eyes to darkness for 10-15 minutes by not looking at anything bright, eventually bringing with you a flashlight with a dark red filter (which ruins your darkness vision much less than white light). If you have a telescope, prefer 25 or even 40 mm eyepieces, which give better contrast and a large field of view.

To find the constellation of Perseus, you have to know how to stargaze and orient yourself in the night sky. It should be in the Northeast, well into the night (2-3 am or even later). In the northern hemisphere, to approximately find the North look at the direction of sunset (West); at your right is the North, behind you is the East, and at your left is the South. Perseus can be found in a streak of sky between the big dipper (four almost rectangular bright stars and a curved handle made of three stars) and Cassiopeia, which has an unmistakable W shape. Both these constellations can be found in the North direction. Move your eyes towards East along this band of sky. Perseus looks like a Pi symbol (you will probably have to mentally rotate it), the size of your fist at arm’s length.

While we are into comets, I recently dug into old night sky pictures I took years ago of the great comet Hale Bopp in 1997. It was an impressive comet, inspiring awe for its beauty, size and colored double tail (and also comet panic and mass cult suicide. Rings some bell ?). In 1997, photography was still a chemical film affair, so I created the digital image by scanning the printed film and adjusting the colors with a little GIMP to remove the strong yellow/green hue resulting from light pollution and film composition effects. Pics have been taken with my camera, a Nikon Nikkormat with a 125 mm lens and a 400 ISO film, mounted in a “parallel scope” position on my telescope (a 114/1000 mm Newtonian) with a self-built connector. With such configuration I could take long shots (some second or even minutes) by taking the picture with the camera, while at the same time carefully following a reference star with the telescope. This technique allows to counteract the Earth’s rotation by hand, and obtain single spots of light instead of streaks. It takes some practice and tricks to setup the telescope mount properly and not introduce accidental vibrations, but the result is pleasing and (very important for a student) rather cheap. Unfortunately, only a really dark sky allows long exposure time and well contrasted result, and light pollution in Italy was (and still is) very high. This picture has been taken from the banks of a river, with some seconds of exposure time, then digitally imported and corrected

You can see a comparison against the original, non-corrected picture in the following image, on the right hand side. The strong yellow/green hue is evident, as well as the poor contrast and saturation

Another picture of the same subject, again with digital correction applied. I tried a nice shot with the cloud merging with the comet tail, a relatively successful attempt. I also got an airplane

Overall, not really great results (on the internet you will find much better pictures), but the original I took is much worse, and my skills with digital image correction techniques are basically nil. I also tried to remove light pollution by subtracting a blurred version of the image, but the result was unpleasant, resulting in a strong “halo effect” at the border between the trees and the sky.

Additional Links

The future of entertainment is here

Please take a look at this

Book

A book

This technology is probably the future of entertainment. It needs no batteries, has a nice resolution both for pictures and text, it can be easily bookmarked or annotated (although sometimes there’s not enough space). It can be bought both online and in a shop, brand new or used. It is relatively easy to use.

It has no Digital Rights Management, it does not force you to read through the preface if you don’t want to, there are no advertisements, you can read it in Japan even if you bought it in Europe, it does not disappear by itself if you take a break from reading it, or after you finished reading it. You can re-read it every time you want without having to pay more, it does not allow the editor to enter illegally into your apartment to check if you are a good citizen (and leaving the door open to others), you don’t have to buy authorized glasses and lightbulbs to read it. It does not call the editor back every time you open it, and you can still read it if the editor goes bankrupt.

It is cheap, made of pure 100 % recyclable support, and collectible to please all your hoarding needs. It is totally backward compatible, and there’s a huge collections of titles already available for fruition. You can borrow or lend it, give it to your friends or leave it to your children, and it will still be accessible. There are places where it can be obtained and accessed for free or exchanged in a peer-to-peer way without infringing the law.

I firmly believe this technology is the future of entertainment and dissemination of knowledge.

Linux dominates in supercomputing

Nothing new under the Sun, but the very interesting presentation makes it very cool to see. I just got to this article at BBC about the Top500 supercomputer list, where a very nice Treemap graph presents supercomputers according to their computational power. By selecting the Operating System, the dominance of Linux is staggering, confirming its status of de-facto standard for high-performance computing. Again, nothing new under the Sun, but it is interesting to see it in such strong visual representation.

Craig Venter programs a bacterium from scratch

As you probably heard in the news, Craig Venter, the American biologist best known for starting up Celera Genomics and sequencing the human genome, achieved another big success. He created a fully working new bacterium, programming its DNA from scratch.

Like a computer having hardware and software, a bacterium has a set of components that execute the software written in the DNA to create proteins. For quite some time, the strategy was to put small pieces of new DNA into full genomes, so to add a new piece of genetic code to synthesize a new protein, typically a pharmaceutical drug. For example, people with diabetes must periodically use insulin, a small protein which is normally produced by a fully functional pancreas. If the pancreas does not produce insulin, then diabetes arises. A solution is to inject insulin from outside, but this small protein must be produced somehow. The technique used to produce it is the Recombinant DNA: A small piece of DNA specifying the code to produce insulin was inserted into a normal bacterium (Escherichia coli, the same that lives in your gut). The altered bacterium duplicates, and millions and millions of daughter cells now produce the proteins their genetic code specifies for, like they were small chemical laboratories. Since specification for insulin has been introduced in their DNA, these millions cells also produce the precious insulin, which is then extracted, purified and sold for diabetes treatment.

At the Craig Venter Institute, they went further. They didn’t add something new to a bacterium. They took all the DNA contained in one, throw it in the dumpster, put another DNA completely designed on a computer, and let it go. This has been done some time ago, but this artificial bacterium was not able to reproduce, until some time ago. Yesterday the paper has been finally published on Science: “Creation of a Bacterial Cell Controlled by a Chemically Synthesized Genome“, marking the fact that the hardware (the mechanism that synthesize proteins) can be programmed at will by totally replacing the software (the DNA). In the most superior example of computer programming skills, the JCVI now controls a chemical computer. Venter walks the path of Wohler, once again demonstrating that life has nothing magic, but it is just a chemical system, obeying the rules of chemistry in a fascinating self-sustaining, self-replicating system made of order and chaos.

What are the consequences of this achievement? What can we do with a totally programmable, reproductive chemical laboratory ? Well, it’s not that easy. Actually this achievement is great, a milestone that will probably earn Craig Venter the Nobel Prize very soon, but to go from this achievement to practical uses for humankind we are a bit far, although not that much far. Having such control will allow so endless possibilities that are almost difficult to imagine right now in their completeness, but we can start from:

  1. production of now expensive proteins to cure diseases, similar to the insulin case, reducing the cost and increasing the effectiveness of therapies.
  2. production of bacterial species able to consume and transform substances that are toxic for us
  3. bacterial species able to deliver a pharmacological payload near the source of the disease. Today we inject stuff in our body, for example to kill cancer, but we poison every single cell, even the good ones. What if a bacterial species is able to detect and attach to a tumor, and then start producing an anticancer drug right there ?
  4. production of electricity from biological sources. Take wood or sugar, let bacteria digest it and promote electricity creation (a so-called microbial fuel cell). It’s clean, renewable and easy to control. We already do something similar with Biosensors to evaluate the amount of glucose in blood.
  5. production of biofuels from garbage or pollutant, like used plastic.
  6. understand how a simple system like a bacterium works will give us the chance to understand more complex systems

Yes, some will probably be scared at the idea of such inane level of control: biological weapons, superbugs… danger! danger!… but if you really stop for a moment, check some history, and think deep, you realize that biological warfare is nothing new: people in the middle ages threw corpses hit by plague beyond castle walls to kill the opponents via biological warfare; humanity does not need to create a powerful bacterium as a weapon: a large amount of them are already available in nature, ready to be harvested, and they could go straight on the tip of some rocket ! Being scared that this new technology could be used by mad, aggressive people as a weapon is not an issue. Again: the biological weapon is already out there, since the very beginning. This is the reason why biological weapon stockpiling and production has been banned since 1972 (Biological Weapon Convention) and only defensive research is allowed and pursued.

In fact, if you think about it, understanding how bacteria work is actually the only way to find effective protection, and not only from human madness…There is a bigger menace out there to be worried about: the pure, crystalline natural cruelty, wiping thousands and thousands of species out with not a blink of compassion since 4 billions years. In 1918, the so called spanish flu wiped out 6% of the world population of that time. Six percent. We humans do not accept this harsh treatment from cruel nature, and we found a way to understand its mechanisms and use them at our own advantage. Our life today is twice as long and many times safer than the life of our ancestors, just 100 years ago: think about living in a world with no anesthesia, no penicillin, no anticancer drugs, no social security or medical assistance, with sounding remedies like skull trepanning, bloodletting, or Hirudotherapy.

Are you really scared of the 21th century ? I’m not.

Eight molecules that changed the rules of the game: Benzene

Rule changed: stimulated research to explain electronic resonance.

Benzene

Benzene

Except for its nice regular hexagonal shape, benzene is not a nice compound. It is toxic, carcinogen, highly flammable, burns with a very dirty and smoky flame, and if it is not enough, it made chemists go crazy for one hundred years. The latter point is interesting for our discussion. Why, you may ask ? It has to do with its structure and a bunch of data that didn’t add up for quite a long time, starting from its discovery, in 1825. It took more than one hundred years to finally understand what was going on, and it required the development of a whole new scientific discipline: quantum chemistry.

Read More »

About class attributes, semantics and microformats

I just got to this post by Richard le Guen via the referrals to my blog, and I feel it’s important to clarify my point.

So, let’s describe the problem. In HTML, you describe the layout of your information. How the information will look like is “presentation” and is managed via a so called Cascading Style Sheet, or CSS. Change the CSS, the visual aspect changes.

To bind the entities you describe in HTML with how they will appear, you use a standardized attribute, the class. An example is:

<div class="info">This is a message</div>

In this example, the info label is the class assigned to the content of the <div> HTML tag. Now you can change its appearance with a CSS directive like

.info {
   color: blue;
   font-size: 13px;
}

if you want the text to appear blue and of a given size. So far so good.

One of the problems in todays’ web is to give semantic meaning to things, so that a computer can extract the information and do smart things with it. Unfortunately there’s no clear way to perform this (well, there is, but we would get into an argument too complex to be described here).

Enter microformats: the point of microformats is to grant semantics through ad-hoc class names that are not only used as a representational reference into the css, but also are assigned to a well-defined meaning. Example:

 <div>
   <div>Joe Doe</div>
   <div>The Example Company</div>
   <div>604-555-1234</div>
   <a href="http://example.com/">http://example.com/</a>
 </div>

can be endowed with semantic meaning if you use the hCard microformat

 <div class="vcard">
   <div class="fn">Joe Doe</div>
   <div class="org">The Example Company</div>
   <div class="tel">604-555-1234</div>
   <a class="url" href="http://example.com/">http://example.com/</a>
 </div>

With this solution, a computer can now understand meaning out of the class attribute, and do smart things like aggregating data, and allow searching on it.

Some time ago, on Jeff Atwood blog, coding horror, a point was made about microformats and their problems. In particular to the fact that (citing Jeff) “the crux of microformats is overloading CSS classes“, and I tended to agree, considering technically wrong to overload CSS classes with meaning. Richard objected that the very definition at the W3 consortium about class attributes is also “For general purpose processing by user agents”, which convincingly includes hCard scrapping tools.

On this, Richard is right, and I’m torn on my previous stance. The point is that the class attribute is indeed specified as a general purpose tool, which specifically and most frequently is used for stylization purposes. Microformats are, from the formal point of view, a totally legitimate use of the class attribute. Nevertheless, when you overload classes with meaning you can incur in all the problems Jeff Atwood points out, and you should be very, very careful, or chaos will ensue. Formal approval for a usage is not always indicative of a safe practice, but in this case the problem arises from the fact that we tend to think at class names as something that has a meaning only within our web application. With microformats, this meaning extends outside the boundaries of our self-contained world, and this conflictual view can produce problems.

Edit : Another issue worth reporting is namespacing. The fact that you grant semantic meaning to a given class attribute means that a given string, say “vcard” conveys a specific meaning which is unique. If you take every possible available string in the world, they belong to a unique, flat namespace. Now, RDF-based semantics approach uses namespacing to distinguish different meanings granted to the same string by using, instead of a trivial string, a URI. In microformats, and in the approach used by microformats, you don’t have namespacing, but you have containment. For example, the class “tel” in the vcard microformat can be distinguished by another “tel” (for example, indicating a table cell on the same webpage) by the fact that the one in the microformat matches the selector “.vcard .tel”. It’s sort of namespacing, although with a different mechanism, and it’s done and built through the containment relationships among HTML elements.

It’s mind bending if you think about it, but once you see how it works, it’s kind of smart. It’s not as complex and demanding as RDF, not as powerful as OWL-based ontology description, but it can work for simple to medium complexity semantic data.

Translations!

I decided to add a rather demanding additional requirement to my blogging activities: I added multiple language support. From now on, posts will also be available in Italian, by selecting the proper option on the top-right corner of the page.

I will not post only when both translations are available. Instead, I will continue blogging in English and progressively translate bottom-up the English posts, until I catch my current flow. Under no circumstances I will delay a post in order to get it in both languages. It would become too demanding. I will keep translating efforts for low inspiration times. This post, however, represents an exception. It is in both languages from the start.

InspectorWordpress has prevented 1 attacks.