Sententia cdsmithus

March 30, 2008

How to Be a Jerk and Get Away With It

Filed under: Uncategorized — cdsmith @ 1:55 pm

In modern society, being a jerk has been raised to an art form. Moral offenses that would shock most of us in plain view can be excused if you know how to play your hand. Here, I cover the basics of getting away with being an immoral jerk.

Step 1: Pick on the Right Victim

The most part of successfully being a jerk is to pick on the right people. If you’re going to mug someone, you wouldn’t pick the Queen of England as your victim. You also shouldn’t go for a successful businessman or politician. Instead, choose victims with whom the general public won’t sympathize. Here are some more specific rules:

First, your victim should be poor. Rich people are trusted, visible, and most importantly have access to the press and political representation. These all work against you. It may seem like it’s better to take money from people who have it to begin with. You would be wrong. Seriously, can anyone imagine Walmart getting away with what it does if its average employees (or even customers) came from upper middle class and wealthy families? Because most of power structure in the world likes to blame poor people for being poor, and doesn’t trust them, it’s actually easier to take $100 each from 10,000 poor people than it is to take a million dollars from a rich person.

Second, your victim should be a racial minority. For some background reading on the importance of picking on racial minorities, see here. You’d be surprised what you can do without getting much attention. Modern sentiment being what it is, having Arabic ancestry is like asking to be victimized. The United States federal government has got this figured out. You may as well take advantage, too.

Whether to victimize men or women is a tricky question. The answer depends on what kind of jerk you plan to become. Although women are disadvantaged in general, you are better off concentrating on which gender that will most reinforce more negative stereotypes about themselves by resisting. If you want to do physical violence, or take someone’s children away, your victim should be male. If you want to deny someone equal pay, a job, or a leadership position of any kind, women are ripe for the picking.

Targeting children is risky, but can pay off. Stay away from children under 12, as they elicit too much sympathy from others. Teenagers, though, are demonized for for their rebellious natures and their irrational “angst”. If you manipulate the situation in the right way, and especially if you can put yourself in a position of authority (which is not too hard; even a bus driver job will do), your inexcusable behavior will be dismissed in the name of preserving order.

As you can see, there are some subtleties here. It’s worth it in the end, though. Assuming you don’t leave definite evidence of having broken the law, the only reasonable way anyone can stop you from being a jerk is to elicit enough sympathy that large numbers of people stand up to you. Choosing the right victims can almost eliminate that unlikely event.

Step 2: Appeal to Written Policy

If you played the first step well, few other people will care about your victim, but your victim will care about him/her-self. There is no more effective way to deal with such victims’ complaints than an appeal to written policy. You can even write the policy yourself, but it’s better if you can arrange to have the policy written by some nameless unidentifiable person, whom no one can blame as a result. As odd as this may sound, it will rarely occur to anyone to blame you for enforcing a ridiculous policy or failing to change it.

This is a remarkably effective strategy. Average people are very receptive to the argument that if someone doesn’t like your policies, they should have never done business with you. Strangely, this remains true when you are getting tax breaks, driving others out of business, and basically providing people with no other choices. Remarkably, it even remains true when you’re able to get the government to pass laws requiring people to do business with you.

Step 3: Blame the Victim

If you’ve still got significant opposition, then you have clearly failed to pick a victim that no one sympathizes with. No worries. You just have to stop people from sympathizing. This will get ugly, though.

Guilt by association is an especially effective tactic here. All you need to do is make enough public statements lumping your victim in with undesirable sorts, and your victim will lose all of their remaining sympathy. For this reason, it’s a good idea to drag in a few genuinely evil people, if possible. That way, you can throw the name of your real victims in the middle of a long list of terrorists, criminals, gang members, and so on. People will conclude that your victims are all bad people anyway.

If guilt by association doesn’t work, you’ll have to engage in a direct game of character assassination. Fortunately, this is easier than it sounds. Most people are not accustomed to receiving the kind of abuse you plan on giving out. They will make mistakes. Perhaps some foul language, or even violence. Maybe they will phrase something improvidently. Unless you’ve made the grave error of picking media-saavy victims, they will certainly say things in public that you can take out of context. With some care, you should be able to make sure the public hates your victim in no time at all, and any scrutiny you’re under should dry up quickly as a result.

Step 4: Use Others’ Common Sense as a Weapon

Now things are getting serious. If you can’t blame the victim, then people must have found real evidence for suspecting you. This is no time to panic, though. Most people aren’t willing to believe outrageous things, and you can use that in your favor. If what you did is completely outrageous, no one will believe your accusers, and you’ll get away free.

You are already at an advantage here, because you’re reading a web page on how to get away with being a jerk. Most people would find that beyond the bounds of common sense. But you need to go further. Never, ever, under any circumstances, should you do pick a victim who has harmed you in any way. You should also not pick a victim that you’ve publicly argued with. These things create “motive”, which helps random people believe that you are guilty. Instead, you should pick random victims, do unbelievable things to them, and then just calmly laugh and ask whether we really believe that such a ridiculous story is true.

Step 5: Tell People Everyone Does It

Now things are really bad. You have no chance of convincing people you are innocent. So what do you do? Easy: make it sound like it’s no big deal.

Here’s the idea. People are going to be angry. You can either let them be angry at you (bad idea) or you can encourage them to just be disgusted with the state of the world as a whole. To accomplish the latter, you imply that you aren’t out of the ordinary, and that everyone does what you did.

Occasionally, you may not want to be on the record as saying something that outrageous. Then a weaker form of this strategy is called for. You can merely imply that everyone does it, by unabashedly and calmly making a public statement about what you are doing. If you word things right, you can make it seem like the most natural thing in the world for you to, say, openly defy a court order.

Step 6: Procrastinate Admission of Guilt

The most important step in avoiding responsibility for your actions is to wait until no one is looking to admit what you did.

A common beginner mistake is to avoid admitting guilt at all. For small matters, this can work. If you’re being enough of a major-league jerk to reach this point, though, people will launch investigations. No, you have to admit what you’ve done. but do it on your time frame.

At this point, get a lawyer. You can be assured that any lawyer worth his salt will advise you not to talk about the case. If he doesn’t, you should specifically request it. This gives you an excuse for not commenting. Later, you can wait until media fervor has died down, and quietly admit what you’ve done once the story is old and stale. Oddly enough, the media will almost certainly play their part, holding off on the worst accusations because they can’t get “both sides” of the story. They will forget that it’s you, whether under legal advice or not, preventing them from getting your side of the story.

Should the story resurrect itself later when you make your admission, you can always appeal to the stuck in the past line to avoid talking about it then.

Step 7: Cry Terrorism

It’s your last shot. Now people are openly protesting against you in the streets. There’s only one thing left to do: call them terrorists.

[Of course this isn't serious. I am, though, looking for more links to add. If you've seen something that should be linked from here, please mention it in the comments.]

March 11, 2008

Just For Fun: Autostereograms in Haskell

Filed under: Uncategorized — cdsmith @ 1:25 pm

I’ve added some code here, which I wrote last night, to generate autostereograms from depth maps. It’s written in Haskell, but that doesn’t mean you should blame Haskell for its shortcomings.

To use:

  1. Install GHC and gtk2hs. Any recent version should do.
  2. Copy this code into a file and build with ghc --make -O2 TheFile.hs.
  3. Generate a tiling background image of your choice. GIMP’s Filter -> Map -> Make Seamless helps a lot with this, and it has some nice options under Filter -> Render to generate nice-looking images. The important thing is for your image to be seamlessly tileable, and have lots of easily identifiable points. Save it as a PNG file.
  4. Generate a depth map, on the order of about 100 x 100 pixels. (Too much larger, and you’ll have to profile and optimize my code for me.) Save it as a PNG file again.
  5. Run the program with the depth map and the background image (in that order) as parameters.

This code basically works, and realistically that’s about all I am going to do right now. There are lots of things that could be improved about it. The big three are: lots of performance issues; should be able to write out to a file instead of just the screen; and there’s something funky in the drawing that causes the depth to slope outward rather gently to each side no matter what the depth map looks like. As far as performance, the problem is with a lot of fiddling with lists for control flow; I was able to do considerably better with Cairo; but unfortunately, Cairo’s matrices only allow for affine transformations, which doesn’t seem to be quite enough to scale between arbitrary trapezoids, so the result didn’t look great and I reverted to drawing pixel by pixel. The last problem may be a rather fundamental issue in how I’m approaching the problem; but the current code works well enough to get the point.

Here are some obligatory screen shots.

Autostereogram of a LambdaAutostereogram of a Chess BoardAutostereogram of a Human

March 7, 2008

Functions and Partial Orders

Filed under: Haskell, math — cdsmith @ 4:03 pm

In a few other blogs (especially here), there has been some discussion of the mathematical foundations of functions in programming languages, starting from topology. Just for fun, I will approach from the other direction, describing functions that can be defined in various languages in terms of partially ordered sets. Of course, for those of you who know this already, then you can go on and define topologies on these posets a la Dana Scott, so it amounts to the same thing. But this way has more pretty pictures.

Functions and Partial Information

Suppose we want to look at functions from the natural numbers to the natural numbers. (By the natural numbers, I mean non-negative integers.) There are, of course, infinitely many such functions. Let’s pick a few that are interesting:

  1. The constant function f(x) = 5.
  2. The identity function g(x) = x.
  3. The successor function h(x) = x + 1.
  4. The doubling function p(x) = 2x.
  5. The square function q(x) = x2.

That should give us a good start. These functions are all quite well-defined over the integers. Indeed, I can implement them all in my favorite programming language, and I’ll get exactly that (note: only because my favorite programming language does arbitrary precision integers, of course.)

The next question is this: what happens if I don’t know everything about the input to the function? What can I infer about the output given partial information about the input? Here’s some of the things I might ask of that sort:

x x = 2 x is even x is at least 5 x could be anything
f(x) f(x) = 5 f(x) = 5 f(x) = 5 f(x) = 5
g(x) g(x) = 2 g(x) is even g(x) is at least 5 g(x) could be anything
h(x) h(x) = 3 h(x) is odd h(x) is at least 6 h(x) is at least 1
p(x) p(x) = 4 p(x) is even p(x) is at least 10
p(x) is even
p(x) is even
q(x) q(x) = 4 q(x) is even
q(x) is a perfect square
q(x) is at least 25
q(x) is a perfect square
q(x) is a perfect square

Getting back this sort of partial information is trickier than implementing the function over totally known arguments. That’s what this blog post is about.

Partial Orders and Up-Sets

The trick is to build a partial order on the domain of the function. A partial order is some relation, ≤, that has three properties:

  • Reflexive: For all x, xx.
  • Anti-symmetric: If xy and yx, then x = y.
  • Transitive: If xy and yz, then xz.

Everyone is familiar with the ≤ that means “is no larger than.” But there are other perfectly good definitions as well. For example “is a factor of” is a perfectly good meaning for ≤. Now here’s where the pretty pictures come in. We can draw a diagram for a partial order, where there’s an upward path from x to y precisely when xy.

For example, here is part of the diagram for the familiar partial order “is no larger than” on the natural numbers:

Familiar Partial Order on the Naturals

And here is part of the diagram for “is a factor of”:

Divisibility Order on the Naturals

Each of these partial orders contains some information about the relationships between natural numbers. In particular, one can identify certain properties of the natural numbers as belonging to up-sets: sets that have the property that if they contain something, they also contain everything that it greater than it. So “at least 5″ is the up-set of naturals in the familiar order that contains 5 and everything above it. We can call this the up-set generated by 5. In the second (divisibility) order, the up-set generated by 5 can be described as “divisible by 5″.

To use these orders to get information about partial inputs to functions, we need two things:

  1. Up-sets that capture the partial information we have.
  2. Functions that preserve that order.

Let’s shoot for the first one. Looking at the kinds of partial information we had:

  • x is even. This is the up-set generated by 2 in the divisibility order.
  • x is at least 5. This is the up-set generated by 5 in the familiar order.
  • x could be anything. This is the up-set generated by the bottom element of any partial order we like, so long as it has a bottom element.
  • x is a perfect square. We’ll need a quite complicated order for this one. We can order the natural numbers by the divisibility order on the least common divisor of the exponents of their prime factorizations. It turns out this isn’t even a valid partial order (it violates anti-symmetry), but I can treat it as a partial order on equivalence classes, and things work out. Then perfect squares are the up-set generated by [2] (the equivalence class of numbers whose gcd of the exponents in their prime factorization is precisely 2) in this order.

Once we’ve chosen a partial order whose up-sets capture the information we want, we have to verify that the function actually preserves the order. That is, if we take an up-set generated by x, and pass everything in it through the function, will the result live in the up-set generated by f(x). The successor function h(x) = x + 1 that we defined earlier has this property in the familiar order. If I have a set of all numbers bigger than 4, and I add one to them all, I get all the numbers bigger than 5. However, h(x) does not preserve up-sets in the divisibility order. If I have all numbers divisible by 3, and I add one to them all, there’s no guarantee that the resulting numbers will be divisible by 4! So I have to be careful about using an order-preserving function, if I want any kind of partial information from up-sets.

What a mess! Sure, if I can define the right partial order, and then prove that the function preserves up-sets on the partial order, and sometimes pull this trick with equivalence classes, and then I get to say something about the behavior of my function on partial information. But that seems less than fulfilling somehow. It feels like I’m working too hard, and now I can’t even define some functions, depending on which order I choose.

Sorting Out the Mess

So what do we do with all of this?

The first thing to do is to pick an order and stick with it. We’ll lose some partial information, but we’ll get to keep other partial information. The logical choice for natural numbers is the familiar order. It’s fairly common for me to want to know that a number is at least 3. It’s somewhat less common for me to want to know that a number is a multiple of 3. But I won’t assume any choice, and in a future blog post, I’ll demonstrate how to build numeric data types in Haskell that parallel several possible choices, and exhibit different laziness characteristics as a result.

The next thing we want to do is recover the ability to define all functions again. The problem with defining some functions is that there’s something “greater than” the number we’re looking at that won’t stay that way once we’re done. The obvious solution is to just make sure there’s nothing “greater than” a number. We can invent a whole set of pseudo-numbers: ~0, ~1, ~2, and so on. Then we’ll put the numbers themselves above that. Here’s the new set of natural numbers with the familiar order:

The Lazy Naturals by the Familiar Order

And voila! I can define all my favorite functions with the actual numbers. What remains is to extend my function onto the pseudo-numbers as well. In this order, the pseudo-number ~n means “at least n“. There’s always one safe way to do this: just map everything to ~0, the minimal element. However, if I still want to get partial information about the function, I need to do better.

Here’s the result for the divisibility order:

Lazy Naturals with Divisibility Order

Here we have the same thing, except that “~n” now means “divisible by n“. Again, I need to extend my functions to the pseudo-numbers. I can still map everything to the bottom element (in this case, “~1″), but this throws away any partial information I may have been keeping.

Finally, one more option. This corresponds to a partial order on an equivalence class, sort of like what came out of the perfect squares example. This one, though, is the trivial equivalence class that lumps everything together. The result is the strict natural numbers, in which I must know the entire number to get any information out of any (non-constant) function.

Strict Natural Numbers

Here only a constant function could do anything except map ~0 back to ~0. Therefore, unless your function is constant, the only way to get any information back from your input is to know the precise value of the input. This is an important arrangement of the natural numbers because for efficiency reasons, in the particular case of integers, this is precisely what all real programming languages do. We’re just using natural numbers as an example, though; the ideas here apply equally well to more complex structures where laziness exists.

It turns out, now, that once we’ve chosen a partial order for the pseudo-numbers, there is sometimes a best possible way to extend any function over the naturals to include pseudo-numbers. To determine the value of any function f at ~n, we’d like to find the greatest lower bound of f(x) for all x~n. Now if the partial order we chose happens to be something called a complete meet-semilattice (all of the orders we’ve talked about are), then that greatest lower bound exists.

Connections to Programming Languages

As you may have guessed by now by my occasional references, this is all connected to laziness of functions in programming languages. I had intended to write about that now, but this has gotten too long already, so I am instead going to stop here and finish the other half at a later time. Hope you enjoyed it!

Blog at WordPress.com.