## Posts

Showing posts from August, 2009

### 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 …

### 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…

### 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 `…

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 n…

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.…

### 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 …

### 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…