Elliot Temple | Permalink | Messages (0)

Wrong Coding Conventions?

From the ruby-talk mailing list. Quoting removed, I think it's readable out of context.


How can a (coding) convention be *wrong*, instead of just less useful, less practical?

The same argument applies to other conventions. Why is Sati *wrong*, instead of just a less useful, less pleasant way to live?

Ideas have broad consequences that can't be arbitrarily restricted: they reach out to other fields. The full answer to the Sati case should include whether anything is wrong at all, and whether practical considerations have moral consequences. Those issues are important to the question about coding.

We can even take a dialog about Sati, and then use some of the ideas to argue about coding. Most of them will work just as well about either topic.

Jim: "Sure, Sati sounds horrible to us, but they are accustomed to it, and would be unhappy to live another way. It has practical consequences, like reducing how many women are available to knit, but wealth is only a convenience."Chloe: "Medical textbooks are a kind of wealth, and medicine matters. With less knitting, they won't be able to buy as high quality medical books."

So, back to coding. This medical textbook argument will work great. Some programmers write tools for doing page layouts, and for making diagrams. Those tools help us make better medical textbooks. The more convenient and practical the coding conventions of the programmers, the sooner we will have higher quality medical textbooks.

The idea that medical textbook production is a *practical* issue with *moral* consequences can be transplanted just fine between the two cases: it has reach.

This isn't conclusive, of course. Maybe you don't see the moral value in medicine. But I think it's getting somewhere, to tie those things together. Most of us are probably persuaded by now. And if we were to continue on, about Sati, or coding conventions, we'd continue on in exactly the same way -- discussing medicine -- because it's all tied to the same issue now.

Elliot Temple | Permalink | Messages (0)

Love

girl: i love you
boy: i'm not sure if i love you
girl: well, how will you find out?
boy: dunno
girl: will you know soon?
boy: i doubt it
girl: this is important!
boy: why?
girl: i don't love you anymore

Elliot Temple | Permalink | Messages (0)

Elliot Temple | Permalink | Messages (0)

Syntax

Syntax is supposed to be a win. It's supposed to be convenient, readable, shorter.

But Lisp -- the language where you write your code in trees without syntax -- is known for being very succinct.

So I see two possibilities:

1) Most syntax isn't actually a great idea

2) Other languages are so handicapped by lacking features found in Lisp that it more than makes up for syntax advantages (and libraries, and all Lisp's other deficiencies)

I'm leaning towards (2), but I suspect a fair amount of syntax is not helpful and some is bad.

Elliot Temple | Permalink | Messages (0)

Food Liars

http://www.newscientist.com/article.ns?id=dn9318&feedId=online-news_rss20

the headline reads

Why fast foods are bad, even in moderation
this is a filthy lie. the article in no way supports this conclusion.

all the article actually says is:

fast foods often have X kind of fat

X kind of fat is worse for you than Y kind of fat.

you should be really scared of X fat. it will probably kill you. your death will be slow and painful, and will occur soon unless you stop immediately.
by this standard, flour is bad for you, because there exists a food with more nutrients, and apples are bad, because their exists a food with less dirt. *every* food is bad, by this standard. even in moderation.

Elliot Temple | Permalink | Messages (0)

Conquering Iraq

source

which calls for a Palestinian state in the West Bank, Gaza Strip and east Jerusalem, said Sallah Zeidan, an official from the Democratic Front for the Liberation of Palestine, a group in the talks. The areas were conquered by Israel in the 1967 Six-Day War.

that is a terrible summary of what happened.

imagine in 10 years when we're leaving Iraq and an article describes it this way:

For years critics have told the US that the war is won. Finally, they are moving towards peace by dismantling their military bases at Dog Village and Cow Point, Iraq. The areas were conquered by the US in the second Gulf War.

you'd want to shoot the author of the second article, wouldn't you?

but how is the first any less unfair?

Elliot Temple | Permalink | Messages (0)

Quality of Argument

In discussions about Israel like this one I see a huge difference in the quality of argument employed by each side. There are some trolls and flames by each side. But the pro-Israel side makes more attempt to reference or summarise history (I mean an overview instead of just one specific thing used to cherry pick a point). And the anti-Israel side does things like claim the President of Iran was misquoted about wiping Israel off the map. And that's standard fair, not unusual. Then you see a reply "yeah, the real quote was 'wipe from the sands of time'". And oh, by the way, the original topic was an article about how Hamas finally decided to recognise Israel. Except, oh wait, it turns out that the pro-Israel side read the translation and it doesn't say that. And now some other articles have said Hamas still won't recognise Israel. (Which BTW is a bit insane. It'd make a lot more sense of Israel wouldn't recognise Hamas than vice versa.) This is far from the first article that makes things up about Israel. I hope there will be a full investigation (there won't be). Shouldn't any observer of this conversation be able to easily see which side has a higher quality of argument?

Update: Look at this and think about the quality of argument.

Update 2: nokilli hadn't posted so much when i wrote this. i'm not referring just to him. also if you think this is unusual please show me some examples of good/sane discussion about Israel.

Elliot Temple | Permalink | Messages (0)

Envelope Paradox

Here is an interesting math problem about a paradox with envelopes. The answers given there are incorrect so I've written better ones.

Problem
There are two envelopes each with a random number inside. You open one and guess if the other number is bigger or smaller. Can you do better than chance?

Problem 2
There are two envelopes with money in them. One has twice as much as the other. You open one and then choose to keep it or swap envelopes. Is there a strategy that makes more money than never swapping?

Wrong Answer 1
Before you open the envelope, choose a pivot number like 500. If the number you open is over 500 guess the other number will be smaller. If it's under 500, guess bigger. The following can happen:

Both numbers are over 500. You score 50%
Both numbers are under 500. You score 50%
One number is over 500 and the other is under 500. You score 100%

Therefore on average the pivot strategy scores over 50%!

Wrong Answer 2
Say you open 100. Four possible things can happen. The total money in both is 300 or 150 and we keep or swap.

total 300 swap get 200
total 300 keep get 100
total 150 swap get 50
total 150 keep get 100

Total for keeping: 200
Total for swapping: 250

Therefore swapping makes more money than keeping.

Answer 1
There is no such thing as choosing a random integer (with equal probability for all integers). You can't choose randomly from an infinitely large set. You can think of it as each individual number has a 1 in infinity chance to be chosen, which is zero.

Answer 2
Again, there is no such thing as choosing a random integer (with equal probability for all integers). So it's not possible to be presented with that situation.

But that's boring! And it's still hard to see why the wrong answers are wrong besides that the problems technically don't make sense. So I tried putting money into envelopes in some possible ways and then seeing what strategy would be best (if any).

I used ruby to help out. Here's the code. But first I'll try to explain why the wrong answers are false in English.

The pivot strategy only does better than chance if you can ever guess a pivot that is between the two numbers. There are infinite choices of pivot, but only finite integers between the two numbers. So your chance of guessing correctly is finite divided by infinite. It's zero.

The money strategy (always swap) can't be right because it doesn't use the information of how much money you opened. So you could swap without even opening an envelope. That can't possibly be profitable.

Now let's put some money into envelopes! We'll need a strategy for deciding what goes in the envelopes. Let's try this: take the numbers from 0-5. For each one, make the pairs [x, x*2] and [x, x/2]. So we'll get 12 pairs of envelopes and each pair will correctly have one envelope with twice as much cash. Here are all the pairs:

[[0, 0.0], [0, 0.0], [1, 0.5], [2, 1.0], [2, 1.0], [3, 1.5], [4, 2.0], [4, 2.0], [5, 2.5], [6, 3.0], [8, 4.0], [10, 5.0]]

If we look closely we can figure out what we might get if we swap each number. All you do is imagine you open a 4 and then look for all the envelopes that have a 4 paired with them. There's two 2's paired with 4, and an 8. Here's all of them:

0: 0 0 0 0
.5: 1
1: .5 2 2
1.5: 3
2: 1 1 4 4
2.5: 5
3: 1.5 6
4: 2 2 8
5: 2.5 10
6: 3
8: 4
10: 5

So you can see you don't wanna swap any high numbers (6-10), swapping 0 and 4 breaks even, and swapping 1, 2, 3, 5 and fractions gains. So there is a strategy to make extra money, but it's not "always swap". You have to look at what number you open and only swap certain numbers.

Now suppose the envelope filling scheme is to take all the numbers from 1-1000 and make pairs of x,x+2 and x,x-1. The edge cases only have a small effect instead of being many of the numbers. So suppose you open the number 500.

500 is in the following pairs:

x = 498 => 498,500
x = 500 => 500,502, 500,499
x = 501 => 501,500

So if you swap you can get: 498 499 501 502

So despite the imbalance that a 10 can turn into 9 or 12 which average to 10.5 ... away from the edges swapping doesn't matter, swapping breaks even. Yay, the world is sane again! It's because and 8 and 11 can turn into a 10, which balances it out.

Now lets go back to having one envelope with double the money using x,x*2, x,x/2

500 is in the following pairs:

x = 250 => 250,500
x = 500 => 500,1000, 500,250
x = 1000 => 1000,500

So if you swap you can get 250 250 1000 1000. So swapping non-edge cases seems to be profitable! Is that really weird? Indiscriminate swapping can't be right!

Well, it's not as counter-intuitive as it seems. Think of it this way: there are some really big jackpots you can get. If the numbers range from 1-1000 before halving and doubling then there is an envelope with $2000. If you get a low number then it's worth shooting for doubling. But if you get a really high number then you should obviously keep it. So it's not crazy if we should swap more than half the time.

Now let's look at some more detailed results. Here is the half the output to my ruby program:

Results for *2 and /2 envelopes
sum simple swap results 11361136.0
sum smart swap results 13177840.0
avg of envelopes 113.0625
avg simple swap results 113.61136
avg smart swap results 131.7784
count of envelope pairs is 400
total envelopes is 800
swap 550
keep 100
tie 150
total unique values you can open is 400
unique swap 250
unique keep 100
unique tie 50
first swap index is 0 val is 0.5
last swap index is 696 val is 199.0
first keep index is 700 val is 202.0
last keep index is 799 val is 400.0
first tie index is 452 val is 102.0
last tie index is 699 val is 200.0


So what does all that mean in English? The envelope creation process used range 1-200 and made envelopes with x,2x and x,x/2 for a total of 800 envelopes we could open. And the results are: for 550 we should swap, 100 we should keep, and 150 it doesn't matter. Of the 400 actual different numbers we could open, we should swap 250 of them, keep 100, and for 50 it doesn't matter. We should swap 68.75%, and only keep 12.5% of the time!

From some extra output I disabled here (it's 800 lines long) I was able to see how the keep/swap/tie decisions were distributed (the summary of how they are distributed is above). All numbers up to 100 we should swap. All numbers over 200 we should keep. In the middle some should be swapped and some don't matter either way. It alternated 2 swaps then 3 ties.

So a new way to think about what happens if the numbers are chosen from an infinite range is: there are three sections: always swap, swap or tie, and always keep. Two are near the edges. In an infinite range there are no edges, so you get a biased set of envelopes with only the middle cases. But that's not possible.

If you use an envelope stuffing strategy with simple addition then the entire middle is ties, one end is swaps and the other end is keeps. You can see output for this at the bottom of my ruby code here.

By the way, I included a method in my script to make the ruby program learn how to play correctly and then play. I also had it play randomly. At the half/double envelopes game, the random program makes $113 per play and the smart one makes about $132. So it works! Soon I'll be rich...

Update I meant that you can't choose a random integer *with equal probability for all integers*. I've corrected the text above.

Elliot Temple | Permalink | Messages (3)

Cheap Global Warming Solution

Tom: i need a fan
Tom: will buy tomorrow maybe.
Elliot: fan > no fan
Elliot: (i'm smart)
Tom: i seem to remember that the curi fan will solve global warming crisis
Elliot: i dunno. if there is enough global warming i'll prolly get a second fan
Tom: lmao
Elliot: if a fan costs $10 (a good, big one), and there are 6 billion ppl, (when u mass produce this much i bet they cost much less than $10 .. let's say $5) ... then global warming will cost ....
Elliot: 30bil (max)
Elliot: plus electricity and fan maintanance
Elliot: that sounds like a lot less than kyoto's 500 thousand trillion

Elliot Temple | Permalink | Messages (2)