Sunday, June 26, 2005

Gorgeous method

If you are into primes, then you know of the Mersenne numbers: 2^n - 1. Here's my implementation of Integer>>mersenne, the answer of which is the receiver-th Mersenne number:


      ^self ones

Isn't that beautiful?

Friday, June 24, 2005

ADPCM beautiful solutions

Now it's the turn to rewrite my ADPCM codecs.

Couple things... these are lossless ADPCM codecs geared towards audio. My previous implementation accepted 8/16 bit, 1-256 independent channel inputs. It had plug-and-play delta strategies, and there were several more or less hard coded coding strategies.

Note to self: without knowing it, I experimented with Rice coding. What it does is to write 1 bit to tell if each delta you write has overflowed or not. But if your delta modeler is good, that means that most of the time there's no overflow, which means that most of the time you're penalizing each delta with 1 bit. B-b-b-b-bad to the bone!

It's much better to reserve the top and bottom values of your allowed delta interval to signal upper or lower overflow, and follow that with a special coding for the rest using the fact that you already know the minimum size of the overflow. Being able to represent 2^n - 2 values instead of 2^n is a much less expensive proposition than using 2^(n+1) values to represent 2^n values.

So how to reproduce all these features without writing a ton of messy code... first, I chose a 4 stage approach to coding/decoding. Coding consists of calculating a delta according to the delta strategy, then updating the coding strategy with the current delta strategy configuration, then encoding the delta using the coding strategy, followed by updating the delta strategy with the efficiency of the coding (this gives feedback to the delta strategy so it can avoid being too aggressive or too conservative). This means that an ADPCM codec has two strategies, which instantly means they are serializable objects which are written to disk via serializable parameters.

Decoding consists of reading a delta according to the coding strategy, calculating the original value and outputting to the destination, followed by updating the delta strategy with the observed coding efficiency. So far, so good.

To implement multiple channels, I decided to implement a mux / demux codec with a list of scheduled codecs (the list also becomes a parameter, its elements are serializable). To implement different bit depths, I decided to implement a stream splitter codec.

So a full ADPCM codec is a complex codec: stream splitter >> mux / demux >> basicAdpcm {with strategies}. Decoding is accomplished by directing data from the adpcm through the mux / demux through the splitter.

I like this stuff very very much.

Wednesday, June 22, 2005

Coding stuff news

My new version of codecs have seen their first successful code/decode/compare run. I'm very happy with this!

So far, I just have an identity codec that does nothing. The trouble up to this point was how to envelope the coded symbols in a self-explanatory way so that a generic decoder would be able to bootstrap the coder. Now I have a serialization mechanism capable of serializing cascaded codecs with all their parameters, in a definitely declarative approach (the serialization is not a file out that is later dependent on the runtime).

It's not a tough problem. But I wanted an elegant solution.

There are serializable objects. Codecs are serializable. Their parameters are SerializableParamater objects.

A serializable object typically starts its serialization by writing its class name in ascii-z format to the destination stream.

A serializable parameter object refers to an getter/setter message pair understood by its parent codec. Its serialization is its class name in ascii-z format, followed by the getter selector in ascii-z format, followed by the serialization of the referenced value.

If the referenced value is a codec, then its serialization is the serialization of its class name plus the serialization of all its parameters. Thus, when a codec envelope is written to disk, the write operation is cascaded through the first codec and then through its serializable parameters.

Different subclasses of SerializableParameter determine what is written/read at serialization/reification time.

The read order is the same as the write order. Hence, it's not necessary to keep track of the current reification context since objects are always reified in the implicit context --- which always happens to be correct one.

Envelope handling pollution is avoided by having EnvelopedCoded deal with kicking off/boostrapping the envelope writing/reading process.

The first successful serialization was:


Sunday, June 12, 2005

More Maradona stuff

I am happy because it's comparatively easy to find rare footage with the Internet.

Maradona videos are some of those available gems. It's great to watch his stuff and listen to radio broadcasts of his plays. Nobody else was or is as good. Incredible, amazing, mesmerizing, forcing you into disbelief, into a there-is-no-way-I-just-saw-that feeling that electrifies your skin.

Taking a step with his left foot while running, barely pushing forward and up a bouncing ball before planting the same foot on the ground, thus making a defender slide by in front of him getting just air, and then taking a little jump on the same foot he just planted to go over the rest of the sliding defender. A tenth of a second movement executed just like that, while keeping another defender still behind him.

If you know Maradona and you watched him play, you know what I am talking about. And then there's training session footage. The ball, still on his left shoe, is kicked upwards and towards his back. He turns around and with the same foot catches the falling ball in the same spot it was before, with the exact opposite force so that without any other movement the ball is laying perfectly still on his shoe --- just like before.

Then you see the amazing variety of juggling with his thighs, shoulders, chest, both legs, heels, keeping the ball still on his head while walking or jumping... then the same with oranges, lemons, pebbles, balls of crushed paper, half-filled bottles of mineral water, tennis balls, golf balls, and golf balls with dress shoes...

Then you watch his plays. Going by a goalkeeper and confusing a panicked defender so much that he slams himself with the goal post between the legs as Maradona simply pushes the ball to score. More defenders ripping patches of grass up in the air trying to catch up, trying not to break their bodies as they stop and stretch, but always too late. Goalkeepers staring at the ball in frustration, disbelief and shame --- scoring from the middle circle right after a kick off, or from 40 yards out, or after running half of the field and finding the keeper too far removed from the goal.

Then his most famous stuff in the match against England in the 1986 world cup. 5 minutes in the second half, game tied 0-0, he gets rid of 4 defenders, then passes to a team mate, a defender kicks the ball up in the air, the goalkeeper runs to get the ball in the box, but Maradona is there. And somehow he manages to jump higher than the goalkeeper and pushes the ball into the goal to score. A beautiful play because of his dribbling, because of how he managed to be in the right place at the right time to beat the goalkeeper's jump. You realize how much skill it takes to do that.

But there is a catch --- the referees did not see that he did that with his left hand, not his head. It's hard to see even on TV.

The english players are furious with the referees, and with good reason. This time however, there's much, much more to that. Because England stole the Falkland Islands from Argentina on 1830 or so. In a complicated series of twisted events, and after 150 years of diplomatic complaints tainted with duplicity, the crazy generals of a US-supported dictatorship who had "disappeared" 30,000 people or so decided to do something patriotic for a change and kicked the English out in 1982. Argentina lost the following war against England with the help of US weapons. An extremely humiliating affair.

A couple things are evident. First, crazy people desperate to stay in power start wars even when they cannot win. Second, poor countries will always take cheap shots from rich countries which stole everything from them to begin with --- because those in the poor countries are always too few, always too poor, always too alone, isolated and helpless as their rights are stripped away from them over and over again, since the beginning and until the end of time.

So with emotions running so high, you are given an illegitimate hand goal against those "thieves" from that other rich country. Even though you know most people from England had nothing to do with the Falklands being stolen, you just conclude "too bad". You won't prosecute the offender this time because the history you know and the emotions you feel don't let you. And at least once, something unfair went your way. Even if it is frivolous, you owe Maradona the satisfaction of knowing that in some other country, they are the ones who are incensed and helpless at the unfairness of the situation right now.

So you'd think enough is enough, and you are satisfied with this alone. Regardless of the fact that you've been robbed so much more than a hand goal, you feel the sweet taste of revenge --- even if you know that after all is said and done it's insignificant.

But Maradona is so much more than a smart ass cheat. He is a one-of-a-kind artist as well. And so that there's further humiliation, he does something even more amazing not even five minutes later. He legally accomplishes what nobody else has ever done.

Taking the ball in his own field, he turns, steps on the ball, and leaves 2 opponents behind. One of them is left in such stupor that he does not run after him. As if taking some ballet step, Maradona controls the ball and with a quick change of direction he goes between 2 other opponents and now the count is 4. The sweeper waits for him at the edge of the penalty area, but Maradona makes him number 5, leaving him as if attached to the ground after a quick direction change and a little jump. The goalkeeper comes trying to keep him from scoring, but he becomes number 6 as he is left spread on the grass after a deliciously subtle shot fake.

Then Maradona slows down ever so slightly so that he's back on his left footing, so he can score with his magic left foot. And even after giving this advantage to the last defender who fouls him from behind, not even this 7th challenge keeps the greatest goal in soccer history from happening as a final defender gets to the goal too late to contest the soft shot.

And now you realize you owe Maradona way too much, and that there is no way in which you can possibly pay him back. First he cheated, stealing from them in their faces, yet forcing you to ignore his infraction. On top of that he has done something that through your eyes and skin has become imprinted on your mind forever, that made millions of soccer-savvy fans drop tears, crying in disbelief and amazement at his greatest artistic expression. Because in those ten magic seconds, Maradona's number 10 became further associated with the best.

From us, those who appreciate art in soccer: thank you so very much Diego. Thank you for your soccer, for the joy the unique beauty with which you play gives us, and especially for this Argentina 2 - England 0.

Tuesday, June 07, 2005

Success tax

The basic idea of writing a computer program is replicating communication relationships between distinctions in the computer.

Then why would you do anything to tax communication between objects? In this sense, Java is a bureaucracy, as below:

An administrative system in which the need or inclination to follow rigid or complex procedures impedes effective action: innovative ideas that get bogged down in red tape and bureaucracy.

Let's respect each other, shall we?

Why in hell should I pay $800 to go to the emergency room because e.g. I have blood in my urine, just because I only have Medicare?

We think we have it so good... and as many other third-world countries, we just garbage collect people who can't increase the disparity in the distribution of wealth.

But all is great as long as it doesn't happen personally to us, right? Such bullshit.