2009-08-30

Cool matrix (3)

Today's abstract

Let's talk about impossible multiplication. An impossible multiplication is just it doesn't make any sense.

``How much is 6 Euro pasta for 5 people?''

is 6 * 5 = 30 Euro. But,

``How much is 6 Euro pasta for 7 Euro salad?''

doesn't make any sense. If someone does 6 * 7 = 42. What does it mean? But it seems some people teach these stuffs to children. They make the students to hate mathematics. That's pity.

-
Main part

Here multiplication is only with a number. If we have some variables x and y, we can do 3 * x + 5 * y, but not x * y. You might wonder what kind of mathematics we can not do x * y, that is such a simple operation. But I would like to emphasize, we have not so much freedom to compute numbers in real world with meaning. We all learned that we sometimes can not multiply numbers, again in real world.

Let's think about in a restaurant as an example. For instance, x or y are a menu A and B's price, respectively. As more vivid example, this restaurant has only two menus, a pasta and a salad. We are five people and went to this restaurant. The pasta costed 6 Euro and the salad costed 7 Euro. The three ordered pasta and two ordered salad. Then total amount is:

3(persons) * 6 (price of pasta) + 2 (persons) * 7 (price of salad)

This is basic of linear operation since there are additions and multiplications. You can see that the multiplications of the price of pasta and price of salad, 6 * 7 = 42 has no meaning here. What is price times price? Namely,

``How much is 6 Euro pasta for 5 people?''

I could understand this question, but,

``How much is 6 Euro pasta for 7 Euro salad?''

has no meaning. At least I can not explain what it is. There are two things I could not explain in this question. The first one is this multiplication itself, and the second is the question ``how much?'' Multiplication can change the unit, this question is that. But the question stays the same unit.

For instance, we have ten strings, each is five meter long, then total length are 5m * 10 = 50m. But if we have a land 5m * 10m = 50 square meters. The question here is:

``How long (meters) is the length of land that has five meter width and 10 meter height?''

If the anser is 50 meters length land, I got a trouble. Let me high light the unit of the first question.

``How much (Euro) is 6 Euro pasta for 7 Euro salad?''

I do not get the meaning of the question. If someone sells me 50m (length) land, I have a problem. It could be 50m long and 1mm width, and the price is the same as the 50m^2. I recommended to know the basic mathematics not to be cheated like this.

We do not do such multiplication since this is nonsense. We can always multiply the numbers themselves, i.e., 6 * 7 = 42. But, there is a case we can not do that if we think about the meaning. I once read a book explaining -1 * -1 = 1 as debt times debt becomes money. This is a good example that the calculation is right, but the explanation is wrong. It is simply we can not debt * debt (what does it mean?). If you were explained like this, I understand you hate mathematics. It is better to not to give a chance to cheaters. However, some cheaters learn mathematics to cheat people, oh well. By the way, I like a movie, Paper moon (http://www.imdb.com/title/tt0070510). In this movie, there is a cheat like here, exchanging nonsense to calculating the numbers.

Cool matrix (2)

I am not sure it is a good idea that using music as an analogy of mathematics. But let me try it. Most of the music is combination of notes. These notes are not alone. We call a sound if it is alone. If we make sounds together in particular sequence, they become a music. Even I could make a C sound by a piano. But, music is different. Make a C sound by typing a key is an analogy to that we could add two numbers. We can't start the music or mathematics if we don't have this basis. These are fundamental, but, if we made a harmony or thought about vectors, they reach to another level. One sound and a music are different. One scaler operation and a matrix-vector operation are different as well. I think a deep insight of linear algebra comes from like that. Some of the music people might complain this analogy, but, some music are quite mathematical for me, like Bach's musical offering (inverse operation, recursive, infinite), I just think about the analogy.

Well, I would like to say please don't hate linear algebra or matrix because it sounds awkward. I found some kind of entrance of this harmony, so I am writing this article.

I think it is better to stop here and making a new section.

2009-08-28

Cool matrix (1)

First I would like to introduce a bit of linear algebra. Then, I want to talk about a cool matrix.

Here, a matrix is a mathematical object, not the movie's matrix. It becomes a long story about the matrix, but in short, this is about linear operator.

But this is just a word substitute from ``matrix'' to ``linear operator,'' it seems I just fuzzify you. It is like saying Cat is Neko (in Japanese). Just substitute the words does not make sense for the people who don't know about cats.

If I could add a bit more words, linear operator treats addition and multiplication only. It's bit strange when I said ``linear algebra,'' that sounds something great, especially in Japanese. I don't know why. Some people misunderstood that is lofty, this sometimes annoys me, oh well. On the other hand, linear operations are combination of addition and multiplication. These are the same, but, if I said ``I study addition and multiplication'' instead of saying ```linear algebra,'' sometimes people said, ``Do you seriously study addition and multiplication at your age?''

Addition and multiplication has deep insight. I think when the mathematics thought about not only a single number (scaler), but also a vector and add vectors, this deepness was added. For instance, it is 5km from my home to my company, 10 km from my home to a film theater, and 11 km from my company to the theater. If these buildings are on a line, we can add and subtract 5, 10, 11 to find the relationship of the distance, but that is rare. In such case, we need not only the distance, but also the direction. We should compute the these distance including their direction. Mathematics could represent them by vectors. These are some kind of ``extended(*)'' numbers, but we are happy if we could do addition and multiplication on them (Since we could calculate the distance from my company to the film theater), we can not make light of these addition and multiplication. But, the bottom line is that linear algebra is addition and multiplication.

It becomes longer than I expected, so this is for today.

* There is a problem to call a vector as an extended number since it is not clear how to compare the vectors and how to divide the vectors. We can compare or divide usual numbers like 3 or 7, so if number should have these property, vector is not a number. Here we confront the problem that what is the number? But this is not today's topic, so I stop this theme here. If you want to know about some kind of numbers, I have a series of blog about Peano number. Also there are many other number systems.

2009-08-23

Vote from abroad II

The role of the rest of four people is following: 1. the one checks my vote registration is genuine. There is the number and name are recorded. 2. the one distributes the voting papers and envelopes. Then I go to a booth to write the vote and seal the envelopes. 3. the one records I voted. 4. the one seals the envelope A and took my vote.

I asked how many people come to vote. The answer is almost 100 people. There is not so many Japanese lives in Berlin, but around 3000. The vote is not only from Berlin, I think the voting ratio is quite low. By the way, the embassy's people were so kind. There is no such reception in Germany even in a shop.

The merit of voting from abroad is I need not to hear the election campaign. There is no disturbance campaign in Germany. Most of Japanese election campaign using the microphon car and just say the candidates name all the day. Everytime I was disturbed by such annoying campaign car, I swore I will never vote this disturbance person. If one did not think about others disturbance, how can I vote that one. Also, I doubt the efficiency of this just shouting the name. (Maybe you do not understand this. In Japan, political party shout its name using advertizing cars. Like the cars run around with microphone, shout CDU! CDU! or SPD! SPD! something like that. When you visit to Japan in the election time, you can take a video and put them onto the YouTube.) If someone care the policy, then they read newspaper, watch the TV, or discuss with friends to decide the vote. If one does not care, does not matter shout the name or not. In Japan, there are a lot of motto, but I also doubt the effect. (Do not steal! or something like that. My imagination does not enough how this works.) But I am afraid that I voted to one who is doing the campaign? Germany is better at this point.

On the other hand, there is some campaign using notices in Germany. For example, one big political party puts ``Wir haben die Kraft.'' I think this in Japanse, then ``Oretachi niha chikara ga aru. (We have the power.)'' This words usually followed by ``dakara omaetachi oretachi ni sakarattemo muda nanndayo.'' (Deshalb, Wiederstand ist zwecklos. (Therefore, the registance is futile.)) So, I wonder, Merkel becomes a dictator? I hope not. Maybe here ``wir'' is not CDU, but Germany. But, still I am afraid as an foreigner. Everyday, I saw them, I wonder what does it mean. This words, we have the power, could encourage the weak people, however, when this words come from the people who have the power, usually connects with too much pride. I don't recall an example that went good end.

Vote from abroad I

There is an election in Japan at August 30th, 45th Syuugiin sousenkyo (the House of representative). I don't live in Japan, but recently I can vote from the outside of Japan. Recently means it is possible after 2000. This was only for proportional representation, but after 2007, I can vote for small electoral district at my last Japanese address. There was a judgment of this, the result is a Japanese can not vote for small electoral district is against the constitution low. I got benefit of this judgment and I thank to the people who worked on this. However, the last time I mistook the election date. I need to vote in advance since my vote will send to Japan by mail. So it goes...

I decided not to make the same mistake, I visited Japanese embassy 21st. If I made a mistake, I had still other days.

There was a sign of ``Here is election'' in front of Japanese embassy (in Japanese!). Great! But, the gatekeepers don't speak Japanese. I said, ``Ich komme hier fuer die Wahl.'' (I come here to vote.) But I am not sure this is correct, so I repeat, ``die Wahl, die Wahl (vote, vote).'' Then, the gatekeeper said, ``Haben Sie wahrscheinlich... (Do you have maybe, ..)'' I asked ``wahrscheinlich was? (maybe what?)'' However, I thought I need to show documents, so I show my passport and vote registration document. Then, he opened the gate. I realize a few seconds later, maybe he said, ``Haben Sie den Wahlschein? (Do you have the vote document)'' I never thought about this vote registration paper's name in German. Many of my friend don't believe I can not hear the L and R difference. I suddenly want to say to friends, ``See, I told you, I can't.'', but nobody was there. Oh, well.

There were five Japanese people in the voting room. The first lady explain me the overview of how to vote. There are two voting paper, here is for the proportional representation, here is for small electoral district. This is the envelope (A) to send the vote to Japan. Please write your vote registration number and sign on it... Wait a moment, then this shows I vote to whom. She continue to explain. There are four more envelopes. You need to use two envelopes (B:large, C:small) for each vote. When I wrote the vote, I put the paper into envelope C. Nothing is written on the envelope C. Then I seal the C, put it into B. I need to write my registration ID on B and sign it. Then, I put these two envelope Bs into envelope A. A is send to Japan. A and Bs are opened under observation, envelope Cs are mixed with other votes. This way, the secret of the vote is protected. Of course there could be broken, but, I trust them. (Anyway, I could tell whom I voted to to my friends.)

... will be continue.

2009-08-17

printf and va_args

Last time, I wrote about a problem with printf and size_t. However, I think it is better to say that this is caused by va_args. Because, a program needs to know what type of arguments are there when we use va_args. I think the promotion of arguments is invented to alleviate this problem.

I met an bug as follows recently. This bug only lives in 64bit environment.

Let's assume the following function using va_args.

---
void vafunction(const char* p_name, ...)
{
va_list ap;
va_start(ap, p_name);
while(p_name != 0){
// do something
p_name = va_arg(ap, const char*);
}
va_end(ap);
}
---

If I call this function as

vafunction("This sometimes doesn't work in 64bit.", 0); // (1)

then, this sometimes crashes. This does not always crash. When I traced this bug by a debugger, sometimes p_name never 0, then segmentation fault happens.

But, if I call this as

vafunction("This should always work in 64bit.", NULL); // (2)

always works. The difference here is that the last argument is 0 or NULL only.

Because, the vafunction assumes the arguments are (const char*), however, (1)'s last 0 is 32bit (int)0.

The reason of (2) has no problem is that NULL is defined as 64bit (void *)0. Therefore, this crash only happens in 32bit. In the case of (1), I observed sometimes extra 0 is inserted on the stack, but I think that is just coincident.

2009-08-08

printf with size_t (in C)

When you print out a size_t data with printf, 32bit and 64bit has an issue. This is described at, for instance,

http://www.mpi-inf.mpg.de/~hitoshi/otherprojects/tips/bugs/articles/11printftrap.shtml

The horror of this problem is that it is just a one character typo and the output becomes not only incorrect, but also it could crash the program. Especially under above pages condition, usual compiler can not detects the problem.

The conclusion is 'use stream,' then the problem itself does not happens unless you have a huge text data (but even so...).

But there is an another question for this. Why float and double have %g and %f only? One of my colleague (D.S.) asked this question.

The problem is caused by the size of size_t alters according to the environment, but the printf only see the format string and operates the stack memory (via va_args), therefore, if you have a mistake in the format string, the memory operation can't be right. Then, why float and double, their size of is 32bit and 64bit, respectively, have no problem?

Because, va_args has a concept of promotion in C language. If a function has va_args, char becomes int, float becomes double. This is called promotion. float is always becomes double before a function is called in va_args. This is explained in K&R books (at the explanation of va_arg). If you are interested in further, OpenBSD's man pages http://www.openbsd.org/cgi-bin/man.cgi?query=va_arg, or, see gcc's manual, Calling Variadic Functions (http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_28.html)

But the conclusion is the same, it is better to use stream. I think it is better to do if I could make the problem itself impossible.

The reason I wrote this is that: a DCC software called 3ds*** crashes under some condition because of this one character typo. I follows this conclusion, so this is not my code, but one of my job is debug this software. OK, this is my job, so maybe it is fine, I get some money for this. But, there are customers who paid to this software, if they know someone just lazy and do not care the robustness, that crashes their data, scene, and their time, ... I am afraid they got angry. I should not say this as a software developer: I want to make our software robust and stable instead of adding unstable new features. But our manages always say without unstable new features, customers never buy our software.