Archive for August, 2006

Packrat parser dependency analysis memoization optimization

Bryan Ford has written some nice papers on PEG parsers and the packrat algorithm. (Wikipedia on parsers.) In a nutshell, the packrat algorithm for implementing parsers for PEG grammars achieves unlimited lookahead in an input stream with reasonable resources by memoizing the results of specific grammar rules (storing the result of a rule at individual points in the input stream so that the rule is calculated at most once per input position, and usually much less). In his thesis, in section 4.4.2, he lists (among others) an optimization that helps alleviate the large memory requirements of packrat parsers. By analyzing a PEG grammar before using it to parse an input (or before generating a parser) it can be determined that some rules will not call others recursively, and thus can be de-memoized with the parser remaining O(n) (though a bit slower).

This is a good start. But another optimization I don’t see mentioned anywhere (possibly because it doesn’t apply to a parser implemented in Haskell) is to perform an analysis on rules to automatically determine backtracking scopes. Once certain rules complete sucessfully (usually medium level rules, like “statement” in grammar for a C-like language) it should be possible to guarantee that a whole class of lower-level ones (lexing rules, often) will not be called again on a position inside of the text included in the high-level rule. By grouping rules’ memoization into related structures, it should be possible to easily and quickly free large block of intermediate results as these higher-level statements are matched.

This analysis would be pretty obvious in certain places for a human to give hints about. Whether it’s possible for the parser (or parser compiler) to perform this analysis usefully, I’m not sure.


Personal development

I’m going to try to start doing some personal development. I found Steve Pavlina’s blog (I forget how) and started reading about self-discipline, which is a big weakness of mine. I suck at it. My main problem, I suppose, is consistently doing the things I need to do to keep myself in peak performance. Things like eating well, and consistently, exercising consistently, and sleeping consistently. I’m going to start out by committing for 30 days to get up (right away) at the same time every day. I almost started this morning, but my alarm was set for 8 AM instead of 7 AM, like I want. (I’ll probably push it to 6:30 after a while.) And if that starts to work out for me, I might try polyphasic sleep. (If I decide to do that and succeed, according to Steve I’ll be “one incredible human being”. We’ll see how that goes.) I imagine that once I’m being quite productive with my 14-16 hour day (and that might even go up a bit after I stop sleeping in) I’ll still feel that I don’t have enough time to get everything done that I want done. I have so many projects! And so little discipline (and later, time) with which to do them!

I think my biggest worry is increasing my self-discipline. What metric should I use to gauge progress? If discipline is like a muscle that gets tired when it’s used, then do I need to track all of the different things I do that use up discipline? How quickly should I add in new things?

Continue reading »


The end of the world

Six nuclear targets that, if hit, could effectively end civilization. (From Michael Anissimov.)


Charity gets a bum rap

Charity sure doesn’t get a lot of love. Many Unfogged commenters don’t like the idea much. (Though more express support.) It’s so frustrating to combat the cynicism of those who think there’s not any hope for people productive rational debate. Take, for instance, comments from SomeCallMeTim:

Particularly when we’re talking about something that has been widely discussed, like abortion, people lining up on different sides have at least slightly different baseline principles. And those baseline principles are themselves contingent on a certain series of assumption about facts and the way those facts relate to other facts, and so on. You can’t really overcome the tendency because you often aren’t trying to overcome one opinion, but a host of them, the vast majority of which never get brought up in the debate for reasons of time, etc.

I think we disagree about the (a) the existence of common priors, (b) how willing we are to change our common priors, and (c) how deeply rooted and, at the same time, contingent belief in a set of common priors really is. I think you’re looking for a coherence, stability, and factuality to beliefs that simply doesn’t exist, for any of us. Debating or arguing is really much more about finding out the shape of a possible deal, with the understanding that, like any deal, someone may pull out down the line when his perceived interests change.

What can you say to that? Perhaps a study that trains people in debating productively, then pits those people in discussions with ideological separated people and see if their position changes more than a control group? Maybe there’s some easier way to test the issue using existing data? Someone call Steven Levitt.

Continue reading »


Ahh, that’s better

I’m still editing and expanding the article. I just added links on individual rules so that you can more easily correct someone who’s violating one or two in particular.

Man. I finally feel like I’m earning the title I gave my blog when I thought I was going to start writing about all these issues. It feels pretty good.


I’ve been busy today

RCIACID metastasizes! I basically rewrote the last section, and it turned out to be less “rules concerning implication and charity in debate” and more “how to debate charitably”. I think I might split up the page into two. They basically talk about the same thing, but from opposite perspectives, and thus they don’t actually have much substance in common. Decisions, decisions.


Implications

Having participated in a couple of discussions in the past day or two, my experience has really driven home, once again, my belief that most people are really terrible at debating. So I decided to write an article about the biggest problem I saw. (I completely gave up on the discussion at Alas, a Blog. The commenters ginmar and Q Grrl especially were guilty of the faults I describe there. Also, I’m not resentful in particular about these discussions, they just happened to be the most recent ones I’ve had that have led me to think about these issues, and thus, to write this post. Also, I’d like to say that LizardBreath is already a quite good follower of the advice I give in the third section of the article, though of course there’s always room for improvement.)

You should really, really go read it now. It’s also right over there on the sidebar, so if you ever want to link to it, you know where to find it.

I remember reading somewhere (don’t feel like googling) that people who spend time in “enemy” forums, like liberals posting at Red State or whatnot, tend to solidify their prejudices about the other side, and rarely really gain a more naunced and sympathetic understanding of their opponents’ positions. I wonder if the dynamic I describe in the article is at least part of the mechanism behind this.


A people divided

Excuse my sappy title. Why is it that so many elections in the US are so close? Is there a dynamic that leads to really close elections? Party leaders wanting to pursue their own agendas, but not to compromise more than they have to on ideology, and that leads naturally to selecting the politicians that can appeal to just barely enough of the voters to win the election? Then again, I guess there haven’t really been that many close elections in the US. I wonder if the recent trend will continue, or if it’s a fluke.

And I think we’ve all heard about the study that 90% of our past presidents have been the more handsome of the candidates, or something along those lines. Is there a source for that? (A few seconds of googling puts the number for elections in general at 56%, but that’s not what I remember.)


Secret pay scales

Why is it that one’s salary is such an incredibly sensitive topic in America? (Do other countries have this attitude as well?) Not knowing what other people in your company make is harmful to you, because you can’t be sure you’re not getting screwed. Why can’t more companies have open compensation policies? And further, why can’t workers push for this? Is open pay much more standard in unionized industries?