James Tauber's Blog 2005/11/10
One Red Paperclip and the Benefits of Trade
The One Red Paperclip project and the Donald Duck story it reminded Hans Nowak of is a nice example of a key principle in economics: voluntary trade benefits both parties.
Gene Callahan, in his wonderful book Economics for Real People, makes the point that when we trade voluntarily it isn't because we give equal value to what we are receiving and what we are giving—it is because we value what we are receiving more than what we are giving. If we valued them the same, there would be no reason to trade. (Note that I'm not just talking about monetary value.) The exact same thing is true of the other party.
People value things differently, in part because people just have different values but also because of marginal utility. Marginal utility is just the idea that the value to you of something is based on the value of getting it in addition to what you already have. e.g. if you already have enough food to eat, you might not value extra food as much. A second car isn't as valuable as the first. A third even less so. The animal in the Donald Duck cartoon that needed the string for his kite was willing to give up a pocket knife for it but if someone offered him the same deal again 5 minutes later, he likely would have rejected it as the marginal utility of the string had greatly reduced.
by jtauber : Created on Nov. 10, 2005 : Last modified Nov. 10, 2005 : Categories economics : (permalink)
5 things
Dave Warnock has tagged me in this blogospherical equivalent of a chain-letter.
Ten years ago
Finishing up my linguistics degree at University of Western Australia. Working part-time there as their first webmaster. Conspiring to get SGML used on the Web.
Five years ago
Living in Portsmouth, New Hampshire. Working at Bowstreet Software as Director of XML Technology. Going to conferences every couple of weeks to talk on XML and Web Services.
One year ago
Living back in Perth, but working for mValent in Boston. Working on the editing and scoring for my first short film, Alibi Phone Network. Resumed work on my morphological database of the Greek New Testament, MorphGNT and was in the midst of a major rewrite of Leonardo (release as 0.4)
Five yummy things
Kaju katli, good sushi, anything at Tu Y Yo (Somerville, Mass.), anything cooked by HB, anything cooked by my Mum.
Five songs I know by heart
Too many to name. Certainly anything by Nelson James :-)
Five things I would do with a lot of money
Relative to most of the rest of the world, I already do so I'd do what I'm already doing.
Five places I would escape to
A library, a film, a piano, HB's house, my parent's house.
Five things I would never wear
Wouldn't or shouldn't? :-)
Five favourite TV shows
Babylon 5, Seinfeld, ...
Five things I enjoy doing
Writing open source software, making films, producing records, teaching, learning
Favourite toys
My Macs, my Digi 002, my Canon 10D, my books (do they count as toys?)
Five people who get this 'meme'
Nelson, Graham, Rick, Anthony, Jenni
by jtauber : Created on Nov. 10, 2005 : Last modified Nov. 10, 2005 : 0 comments (permalink)
Relational Python: Basic class for relations
A relation is basically a set of dictionaries (called tuples) where each dictionary has identical keys (called attributes).
While, as you'll see in the next couple of posts in this series, my display routine and the initial relational operators work on iterations over plain Python dictionaries, I found it useful to implement a relation, at least in these preliminary stages, using a different internal structure (something Date is clear in his book he has no problem with).
Basically, I store the each tuple internally as a Python tuple rather than a dictionary and the relation also keeps an ordered list of the attributes which is used as the index into the tuples. Amongst other things, this gets around dictionaries not being hashable. It's also a storage optimization akin to using slots for Python attributes.
class Rel:Note that Rel.attributes and Rel.tuples return a set of attributes and a generator over dictionaries just as you would expect.def __init__(self, attributes): self.attributes_ = tuple(attributes) self.tuples_ = set()
def add(self, tup): self.tuples_.add(self._convert_dict(tup))
def _convert_dict(self, tup): return tuple([tup[attribute] for attribute in self.attributes_])
def attributes(self): return set(self.attributes_)
def tuples(self): for tup in self.tuples_: tupdict = {} for col in range(len(self.attributes_)): tupdict[self.attributes_[col]] = tup[col] yield tupdict
By implementing the handy little helper function:
def d(**args):
return args
we can now create a relation and add tuples like so:
rel1 = Rel(["ENO", "ENAME", "DNO", "SALARY"])rel1.add(d(ENO="E1", ENAME="Lopez", DNO="D1", SALARY="40K")) rel1.add(d(ENO="E2", ENAME="Cheng", DNO="D1", SALARY="42K")) rel1.add(d(ENO="E3", ENAME="Finzi", DNO="D2", SALARY="30K"))
In the next post I'll share my display routine and, following that, start on the relational operators, beginning with PROJECT.
by jtauber : Created on Nov. 9, 2005 : Last modified Nov. 9, 2005 : Categories python relational_python : (permalink)