Sunday, February 12, 2012

Evangelicals and Global Warming (Part 1)

I visited my parent’s church today. It’s a very Pentecostal church, and while I haven’t been particularly Pentecostal for many years now, there are many things about the church that I admire. First among these is its well established and effective ministry with recovering alcoholics and drug users. It brings a smile to my face when I think about how many folks once sitting in jail cells are now sitting in pews and shouting hallelujah. I can imagine that first century Christians once nudged each other and said, “See her? She was possessed by seven demons before Jesus cast them out.” I’ll often hear similar comments in my parents’ church: as folks pass by, they’ll say something like, “See him? Before he got saved, he was sleeping under a van down by the river.” Or, “That guy over there? He was selling drugs out of a drive-through window.” If comments like these strike you as condescending, I’d venture to say that you probably don’t know Evangelicals very well.

The sermon this morning was solid, and gave me a lot to chew on. It took Romans 12:1-2 as its text, which says, “Do not conformed to this world, but instead be transformed by the renewing of your mind.” That seemed especially relevant in light of my renewed skepticism of the mainstream media’s portrayal of social and religious issues. As I mentioned in my last post, recent events have driven home to me the importance of a pretty strong filter when the media tries to cover social conservatives.

Still, I was taken aback when the pastor said (I’m paraphrasing from memory, but this is pretty close):

You’ve probably heard a lot about global warming. But that’s just another example of how the media doesn’t tell us the truth. Global warming is just one more big hoax that the media has tried to pull over on us.

My wife and I looked at each other, to make sure we’d actually heard what we thought. I was pretty surprised, both that this pastor (whom I like and respect) would believe this, but even more that he’d choose to bring it up in a sermon. It had nothing to do with the Gospel, and worse, he made it seem like it did. It sent the unmistakable message that if you want to be a good Christian, you ought to believe that global warming is a scam. And that’s a shame, for more reasons than I can begin to count.

Still, because I’ve recently expressed my extreme disappointment with liberals on the matter of religious liberty, it seemed an appropriate time to blog about how frustrated I am with conservative positions on the environment, particularly with respect to global warming. I know lots of folks conservatives who would agree with my parent’s pastor, that climate change is a hoax. And I’m really, really curious about why this is this so.

I’ll start by saying that it’s clearly not because they’ve made an independent and sufficient evaluation of the evidence, and have rejected it as inadequate.  The plain fact of the matter is that nobody I know personally (and this obviously includes me) is anything like qualified enough to offer an authoritative opinion on the science behind scientists’ claims regarding climate change. Yes, I suppose most of us have a cursory understanding of the physics of global warming: CO2 and methane act as “greenhouse gases”, trapping more warmth in the atmosphere, thus raising temperatures worldwide. Some of us may have observed the retreat of glaciers with our own eyes, most of us have read about the increased rate of polar ice melting, and probably a good number have read mainstream summaries of the science behind it (this piece by The Economist is probably the best). But the fact remains that the earth’s climate is composed of innumerable systems whose interactions are mind-bogglingly complex, and the measurements, the math, and the models that real climate scientists use to predict their behavior are only slightly less so. I could spend the next four or five years doing nothing but studying climate change, and I’d barely be qualified to comment on the quality of a few journal articles, and still less on any overarching conclusions that real scientists might reach after having critically digested thousands of them. I simply don’t know enough; and neither does anybody else that I know. There are roughly 7 billion humans on this planet, and maybe a thousand of them possess the knowledge and experience that I freely admit I lack. (This study, for instance, was able to identify 1,372 individuals actively publishing in the field of climate change.) In other words, folks qualified to comment authoritatively on climate science are not just one in a million: they’re quite literally one in seven million. The vast majority of folks who reject global warming, as well as the vast majority of folks who accept it, are doing it for other reasons entirely.

And here’s another red herring. Your typical climate change skeptic doesn’t reject the idea of global warming because the folks who are qualified to judge haven’t made up their minds. If you want to know how convincing the evidence is for climate change, don’t start with this Wikipedia article (on the physics), but with this one (on the consensus opinion among scientists). There’s a lot of data in there, but this gives you a feel for its conclusions:

The predominant scientific opinion on climate change is that the Earth's climate system is unequivocally warming and it is more than 90% certain that humans are causing it . . . No scientific body of national or international standing has maintained a dissenting opinion . . . 97–98% of the climate researchers most actively publishing in the field support the tenets of ACC (Anthropogenic Climate Change) outlined by the Intergovernmental Panel on Climate Change.

In other words, there’s a consensus. I have some reasonable idea of what a consensus looks like, and trust me, that looks like one. And yet some 50% of Americans reject it. Why?

Well, I’ve got a theory about that, but it’ll have to wait until my next post.

Friday, February 10, 2012

Discovering What It’s Like To Be a Partisan

Most of my life, I’ve been a political moderate. My father is a Rush Limbaugh Dittohead, his father before him was a Yellow Dog Democrat, but I’ve never felt particularly comfortable in either strongly liberal or strongly conservative circles. I’m a registered Democrat mostly because, back in college, the guy doing the voter registration drive was pushing very hard for me to register as a Republican. But since then, on both issues and candidates, I’ve sometimes favored the Republicans, sometimes the Democrats. And in political discussions, I’ve generally found that it’s easier for those discussions to be interesting and productive when the person on the other side isn’t swayed by party politics, and isn’t trying to ascribe unworthy motives to the other side while trying to pretend that they themselves are pure as the driven snow. My default position when it comes to controversies is to be fairly sober-minded, to try to see both sides of the picture, to be realistic about my own and others’ motives, and not to claim more for an argument than it really warrants. As you can imagine, this makes me a pretty bad Democrat, and probably an even worse Republican. My glee at the rise and ungainly fall of Herman Cain, Newt Gingrich, Michelle Bachmann, and Rick Perry has been anything but seemly. I’m annoyed at the inability of our congressional representatives to work together, and if there were an intelligent candidate somewhere in the political middle, ready both to cut spending and raise taxes to fix our fiscal woes, he or she would find it difficult to not get my vote.

However, several recent events have upended a great deal of my self-satisfied centrism. First, in what could only have been a cynical election year ploy to excite his base, Obama decided to make the Catholic Church pay for contraceptives, sterilization, and abortifacients, in an obvious violation of several hundred years of American jurisprudence, along with the Religious Freedom Restoration Act, not to mention the First Amendment. (And of course, it turns out that this did excite the base: but the wrong one.) Second, the Susan G. Komen Foundation first dropped their support of Planned Parenthood, and in the ensuing uproar, re-established it, their hand having been forced by the media’s blatantly one-sided coverage of the move.  And finally, when I pointed these things out to friends, and expressed my astonishment, I was repeatedly met with either blank stares or outright hostility. Folks simply didn’t get why I found these two things – the Obama administration’s trampling of the First Amendment, and the news media’s blatantly biased reporting on Susan G. Komen – so objectionable. And that shocked me. After all, if someone thought that it was wrong for the government to force a particular moral viewpoint on a woman carrying a child, shouldn’t they mutatis mutandis think that it was wrong for the government to force a particular moral viewpoint on Roman Catholics? But apparently they didn’t see any problem with that sort of government intrusion.

More than that, though, my arguments with them put me in a very odd position. I dislike the smell of partisan politics intensely. Nothing is so likely to turn me off in a debate as the realization that the other person not just thinks he’s right, but is convinced that that anyone with a different perspective is operating in bad faith and with impure motives. But that’s exactly what I’m convinced has happened in these two instances. Obama is an expert on Constitutional law: there’s no way that he couldn’t have realized that the HHS decision was a blatant violation the First Amendment (especially after taking a 9-0 shellacking from the Supreme Court on a closely related issue in Hosanna-Tabor just two weeks prior). The media prides itself on its objectivity: but take a look at this interview by Andrea Mitchell, and see if you think there’s any reasonable way you could describe it as fair and balanced.

The result is that I’ve started to feel quite differently about the Republicans, and all the nasty things they’ve been saying about the Obama administration. The strong emotions animating the Tea Party have been even more of a turn-off to me than the actual positions for which they’re advocating. But now that I’ve found myself backed into a political corner, it turns out that I’m suddenly as angry as, well, a Tea Party conservative. I’m unbelievably pissed-off that the Obama administration has decided that the ideology of secularism gets to operate from a privileged position: that our country is no longer pluralist, but actively and specifically secular: that I’m welcome to my religious beliefs only so long as they extend no further than the door of my church. The logic of the Obama administration and its defenders, that public expressions of religious beliefs must always give way to the power of the state, is astonishingly similar to that of the Chinese government. This is a big hairy deal, in other words, and it represents a breathtaking invasion by the federal government into the realm of ultimate truth. It makes me angry to think about it. It’s not right, and Obama should have known better. The realization that he actually thinks this way has revealed a yawning, probably unbridgeable gap between his worldview and mine. He can talk about his respect for religion all he wants: but when it comes right down to it, it’s pretty clear that he doesn’t respect any religion so long as it insists upon actual truth claims about the fundamental nature of God, humanity and the world (in other words, all of them). I will not vote for any president who thinks that way, and I’m going to be a damned sight more suspicious of anything he says going forward.

As a side note, I was gratified to hear that as of this morning, Obama has more-or-less backed down, and is offering a compromise. But in the spirit of my newfound hermeneutic of suspicion, it’s worth pointing out that in his press conference, he baldly lied about the state of the rule-making process. The proposed compromise was not, as he portrayed it, a “speeding up” of a process already under way, but an actual change in the actual rule, a political volte-face after realizing that he’d just managed to push a whole bunch of fence-sitters like myself firmly into the waiting arms of his conservative opponents. And it’s also worth noting that the changes he has proposed seem to be purely verbal: see this analysis, which calls it “economic nonsense”; or this one, or this, which wonder how insurance companies could possibly avoid using premiums from their Catholic clients to pay for contraceptive coverage. As Robert Miller puts it:

Under the old rule, the employer had to pay for abortion-inducing drugs, sterilizations, and contraception. Under the new rule, the employer has to pay for abortion-inducing drugs, sterilizations, and contraception, but President Obama will say that it doesn’t, and we’ll believe him. That fixes everything. And to think, some people accuse President Obama of empty rhetoric.

That’s the sort of wonderfully snarky comment that would have gotten my dander up in the old days (i.e., two weeks ago), but sounds pretty good to me right now.

Moving on, when you layer the Susan G. Komen debacle onto the contraception controversy, it’s made me increasingly suspicious of anything the media has to say as well. I’ve found myself reading a variety of conservative blogs that critique the media’s portrayal of religion, and I’m a little astonished at how much sense they make. You can make the case (as liberals often do) that the mass media is owned by corporations, and hence are likely to present a conservative slant on economic issues. That may or may not be the case: but there’s no remaining doubt in my mind which direction the media leans when covering social and religious issues. This bias shows up in a thousand subtle and blatant ways, and ranges from the scare quotes around “religious liberty” in the third paragraph of this article, to the numerous mistakes of fact in this article, and the decision by the Dallas Morning News to feature a dozen protesters of Susan G. Komen’s decision on the front page, after having completely ignored an 8000-person March for Life the previous month.

So here’s the first thing. Like I said, I’m angry at Obama, and I’m newly suspicious of the news media. I’m in no mood to compromise, and right now, I’d love to see Obama filing for unemployment because of his attempted betrayal of the First Amendment. And I guess that makes me a conservative.

But here’s the other thing. For perhaps the first time in my life, I understand what a political partisan feels like. I now know what it means to be angry and frustrated, because you’re so convinced that you’re right and that your opponents are mulish and stubborn miscreants. And I know that folks on both sides feel like that. I’m able to understand a great deal of why folks on both the right and the left respond the way they do to each other. I sympathize with the partisans. I get it now. I feel their pain. And I guess that makes me a liberal.

Sunday, January 15, 2012

The Joys of Parenting

It started Thursday night. I've been fighting off the same chest cold that sent Calista to the doctor's office New Year’s Day, so before I went to bed, I took a couple NyQuil to help me sleep. About 1:00 am, I woke out of a drug-fogged sleep to find our four-year-old son Caedmon crawling into our bed. That wasn't unprecedented, but it's not normal either. I was groggy enough that I decided to cut him some slack, so I put up with him squirming and kicking me for 15 minutes or so before finally deciding that no, he had to go back to his own bed. So I picked him up and carried him back to his room. I was setting him down into his bunk bed when I noticed a strong sour smell in the air, and simultaneously felt my hands plunge into a wet, sticky substance covering his blankets. My brain took a few seconds to put it all together and draw some conclusions. Then I sighed and picked him up and carried him back into our room. We made a bed for him on the floor, got a bowl from the kitchen, and put him down, hoping that would be the end of it.

About 20 minutes later, we were awoken again, to the sound of Caedmon gagging. Most of it made it in the bowl, but by no means all of it. More cleanup and consoling. Then something like sleep, more gagging, more cleanup, more consoling. This repeated itself all night long, every 20 minutes or so, until about 5:00 am, when Caedmon finally managed to get to sleep and stay asleep. About the same time, I removed myself to the couch downstairs, and got an hour or so of rest.

When we woke up, we let Caedmon continue to sleep in our bed, and Galena began cleaning his room. Our one-year-old daughter Calista wasn't making any noise, so we let her sleep, while I tried to entertain our two-year-old son, Brendan. By 8:30 or so, though, Galena decided that she really needed to check on Calista. When she opened the door, she got a full whiff: turns out Calista had been having the same troubles, but had suffered them all in complete silence. (We even had the baby monitor on!) So her crib, her blankets, and her hair was encrusted with not-quite-dried puke. Calista herself was surprisingly calm about the whole thing, and gave us a big grin as we gingerly tried to extract her from the Crib of Dried Vomit.

After that, Friday and Friday night passed more-or-less without event. On Saturday morning, we thought we'd seen the worst of it, and since the kids were begging to go outside and play in the snow, we got them dressed and spent some time outdoors. (Caedmon discovered that it's painfully tricky to ride your bike in the snow; Brendan and Calista discovered, once again, that your hands get cold and hurt when you play in the snow and refuse to wear gloves.)

But Saturday afternoon, Calista started having a variety of diarrhea episodes, including at least one "Level 3 Containment Failure" (I'll leave the exact definition of that to your imagination). And then Galena started looking green around the gills. And then she threw up. And then the other end as well. Rinse and repeat.

So Galena took herself to bed, while I did my best to entertain the kids. Caedmon and Calista were definitely feeling better, but were still a little stunned after their run-in with the Stomach Bug That's Going Around. Brendan seemed to have a stainless steel immune system, however, and wasn't going to let anything slow him down. (And you have to remember, through all this, that I've got a cold too, and periodically feel like I'm about to hack up a lung.) When evening rolled around, I finally got the kids fed and down to bed, and all seemed quiet. So I checked in with Galena, who was still in bed, and then left for Bellevue, for a movie night with some friends that had been long planned (and for which I was supposed to supply the movie).

I got a call from a groggy-sounding Galena around 8:30. "Brendan just threw up," she said, sounding on the verge of tears. "Can you come home?" By 9:00 pm or so, I was thus available to make myself the target for Brendan's third heave of the evening. After several more abortive attempts to get Brendan to sleep, I gave up, and for an hour or two, he sat on my lap with a bowl in his hands. We passed the time by watching extreme skiing videos off of YouTube (at Brendan's request). We'd pause the video - or sometimes not - whenever Brendan started heaving, then I'd wipe his mouth, and we'd start watching the video again. It was oddly bonding. By midnight, the worst had passed, and I put him to bed.

I should note that during all this, my side of the bed had gotten nailed with at least one round, so I elected to spend the rest of the night in the guest bed in the library. Galena's side was relatively clean, and more than that, she was too tired to care.

I got up around 7:30 this morning to find Brendan and Caedmon in great spirits: they weren't up to the Running and Chasing Game, precisely, but they were quarreling normally and demanding books and juice and videos. But by 9:00 am, when Calista still hadn't made any noise, I decided to check on her. Turns out that (once again) she'd been having the same trouble as everyone else, but (also once again) hadn't complained to let anyone know about it. The carpet around her crib, her bedding, her hair, and the outside of her pajamas were covered with one particularly noxious substance; the inside of her pajamas, and most of her body, was covered with a different one, surprisingly similar in texture and smell, and equally objectionable. Even after I gave Calista a shower, Galena was still combing unidentified chunks out of her hair.

That brings us up to the present. I'm the only one who hasn't gotten the bug yet, but I can feel it circling warily at a distance, like a pack of wolves preparing for the attack. We've basically decided that all the normal household rules and routines are out the window. The kids are watching videos and drinking juice and eating pretty much whenever and whatever they want. Galena informs me that Calista has just fallen asleep in the hallway. Brendan and Caedmon have scattered a box of paper clips around my office, and I can barely bring myself to care. Civilization and discipline has given way to raw survival.

Wish us luck.

Friday, November 4, 2011

My favorite C# micro-optimizations #2: 1D Arrays

This is my second post on my favorite C# micr0-optimizations. Everything I said in the first post applies to this one as well, namely, don’t optimize until you know that you need to; and spend most of your optimization budget optimizing the algorithms, rather than figuring out which way to access an array is faster.

That said, this was a surprise to me: jagged arrays (e.g., arrays of arrays) are much faster than rectangular arrays: but indexed access into a 1D array is faster yet.

In other words, this is relatively slow:

   1:  for (int x = 0; x < size1; x++)
   2:  {
   3:      for (int y = 0; y < size2; y++)
   4:      {
   5:          result = twoDArray[x, y];
   6:      }
   7:  }

This is significantly faster:

   1:  for (int x = 0; x < size1; x++)
   2:  {
   3:      for (int y = 0; y < size2; y++)
   4:      {
   5:          result = jaggedArray[x][y];
   6:      }
   7:  }

But this is the fastest:

   1:  for (int x = 0; x < size1; x++)
   2:  {
   3:      for (int y = 0; y < size2; y++)
   4:      {
   5:          result = oneDArray[x * size2 + y];
   6:      }
   7:  }

Benchmark results on my machine (1000 iterations through a 1000x1000 array):

2DArrayTest action completed: iteration = 5, completionTime = 3111, averageCompletionTime = 3101.400
JaggedArrayTest action completed: iteration = 5, completionTime = 2283, averageCompletionTime = 2256.000
1DArrayTest action completed: iteration = 5, completionTime = 1698, averageCompletionTime = 1638.800

It’s also very much worth noting that the order in which the iteration happens is important. Sequential memory access is faster than purely random memory access, most likely because data is fetched from main memory to the CPU’s cache in chunks, so that subsequent sequential reads are from cache.

In other words, if instead of this at the center of each loop:

result = jaggedArray[x][y];
result = twoDArray[x, y];
result = oneDArray[x * size2 + y];

We switch the order of the indexes, so that memory is accessed out-of-order (this is called “diagonal access”):

result = jaggedArray[y][x];
result = twoDArray[y, x];
result = oneDArray[y * size1 + x];
Then the tests take more than twice as long:

JaggedArrayTest action completed: iteration = 5, completionTime = 7499, averageCompletionTime = 7676.400
2DArrayTest action completed: iteration = 5, completionTime = 6790, averageCompletionTime = 6818.600
1DArrayTest action completed: iteration = 5, completionTime = 5862, averageCompletionTime = 5883.200

It’s interesting that in a diagonal access pattern, rectangular arrays are indeed faster than jagged arrays: but one-dimensional arrays are still the fastest.

Thursday, November 3, 2011

My favorite C# micro-optimization #1: Buffer.BlockCopy()

So a caveat first-off. Micro-optimizations are evil. You almost never need them. You can live the vast majority of your life as a programmer and never use them; and most of the time you use them, you’re going to use them incorrectly. If your program is running slow, you’ll almost never find some tiny little micro-optimization that will fix it.

But there are times when they’re handy, and with all the work I’ve been doing the last couple years on a custom Silverlight media stack, I’ve had a number of opportunities to learn about how to speed up code that gets called thousands of times each second. This series of articles is the result of that experience.

And my first suggestion is to use Buffer.BlockCopy() when you need to move data in and out of arrays. You don’t normally need to do this very heavily, but when you’re dealing with real-time multimedia, you’ll find yourself doing it all the time, so the faster you can do it, the better.

I mention this because a common way to move data from one array to another is through a for loop, like so:

   1:  for (int i = 0; i < sourceArray.Length; i++)
   2:  {
   3:      destinationArray[i] = sourceArray[i];
   4:  }

Unfortunately, that’s very nearly the slowest way to do it. (Array.Clone() is actually slower, but that’s another story.) A much better way to do it is to use Array.Copy(). Indeed, this is normally the preferred method, since you don’t have to worry about the size of the individual elements, which is an easy place to mess up. Moreover, Array.Copy() works for arrays of any type, instead of just intrinsic value types.

   1:  Array.Copy(sourceArray, 0, destinationArray, 0, sourceArray.Length);

But as it turns out, Buffer.BlockCopy() is slightly faster for many operations, since it doesn’t have to perform certain checks at the beginning of the copy:

   1:  Buffer.BlockCopy(sourceArray, 0, destinationArray, 0, sourceArray.Length * sizeof(short));

Benchmark results on my machine (10 million copies of a 64-element short[] array):

Buffer.BlockCopy action completed: iteration = 5, completionTime = 420, averageCompletionTime = 422.000
Array.Copy action completed: iteration = 5, completionTime = 478, averageCompletionTime = 482.600
forLoop action completed: iteration = 5, completionTime = 1092, averageCompletionTime = 1093.000

That said, the difference between Array.Copy() and Buffer.BlockCopy() tends to disappear the larger the amount of data to copy (while a for loop falls further and further behind). If you’re copying 64,000 elements instead of 64 elements, these are the results:

Buffer.BlockCopy action completed: iteration = 5, completionTime = 1251, averageCompletionTime = 1229.000
Array.Copy action completed: iteration = 5, completionTime = 1254, averageCompletionTime = 1218.200
forLoop action completed: iteration = 5, completionTime = 11063, averageCompletionTime = 11082.200

But there’s one significant caveat: if you only need to move a few elements, even the minimal overhead of Buffer.BlockCopy() can be too much. If you need to move less than 32 elements, you’ll probably find that a straightforward for loop (or perhaps an unrolled version of it) is the fastest. Of course, you’ll want to do your own testing to find out where the break-even point is. But here are my results with 1,000,000 copies of a 16-element array:

Buffer.BlockCopy action completed: iteration = 5, completionTime = 367, averageCompletionTime = 363.800
Array.Copy action completed: iteration = 5, completionTime = 418, averageCompletionTime = 420.000
forLoop action completed: iteration = 5, completionTime = 291, averageCompletionTime = 290.000

Tuesday, November 1, 2011

Fast (approximate) Sqrt method in C#

As part of the video codec that Alanta uses, we need to calculate the variation between blocks in one frame and the equivalent blocks in the next frame. I’ve been using an algorithm proposed by Thiadmer Riemersma that looks something like this:

public static double GetColorDistance(byte r1, byte g1, byte b1, byte r2, byte g2, byte b2)
{
    int rmean = (r1 + r2) / 2;
    int r = r1 - r2;
    int g = g1 - g2;
    int b = b1 - b2;
    int weightR = 2 + rmean / 256;
    const int weightG = 4;
    int weightB = 2 + (255 - rmean) / 256;
    return Math.Sqrt(weightR * r * r + weightG * g * g + weightB * b * b);
}

It works pretty well, but that last step depends on a square root calculation, which is relatively slow; and when this is something you need to run on every pixel in a frame, you want it to be as fast as possible. Consequently, I’ve been looking at ways to optimize it.

The important thing to note is that for my purposes, close is good enough: I don’t need IEEE precision. It turns out that there’s a pretty good approximation that’s available in languages like C or C++ which let you do unsafe casts back and forth between ints and floats:

float sqrt_approx(float z)
{
    union
    {
        int tmp;
        float f;
    } u;
    u.f = z;
    u.tmp -= 1 << 23; /* Subtract 2^m. */
    u.tmp >>= 1; /* Divide by 2. */
    u.tmp += 1 << 29; /* Add ((b + 1) / 2) * 2^m. */
    return u.f;
}
The problem with this approach is that C# doesn’t normally let you play this kind of magic.
The key word being “normally”, of course.
Turns out there’s one trick you can use to make C# treat the same memory address as either an int or a float, and that’s to create a struct with a [StructLayout(LayoutKind.Explicit)] attribute. (And surprisingly enough, the trick works in Silverlight as well.) The resulting class looks like this:
public class Approximate
{
    public static float Sqrt(float z)
    {
        if (z == 0) return 0;
        FloatIntUnion u;
        u.tmp = 0;
        u.f = z;
        u.tmp -= 1 << 23; /* Subtract 2^m. */
        u.tmp >>= 1; /* Divide by 2. */
        u.tmp += 1 << 29; /* Add ((b + 1) / 2) * 2^m. */
        return u.f;
    }

    [StructLayout(LayoutKind.Explicit)]
    private struct FloatIntUnion
    {
        [FieldOffset(0)]
        public float f;

        [FieldOffset(0)]
        public int tmp;
    }
}
The results are pretty good: it’s more than twice as fast, and the results tend to be within 2% of the “real” answer:

MathSqrtTest: averageCompletionTime = 2424.000
ApproxSqrtTest: averageCompletionTime = 1058.000
Average variation: 0.0253587081881525

If you want a bit more accuracy at the cost of an additional CPU cycle or two, you can use this one, based on the famous inverse square root method in Quake 3:

public static float Sqrt2(float z)
{
    if (z == 0) return 0;
    FloatIntUnion u;
    u.tmp = 0;
    float xhalf = 0.5f * z;
    u.f = z;
    u.tmp = 0x5f375a86 - (u.tmp >> 1);
    u.f = u.f * (1.5f - xhalf * u.f * u.f);
    return u.f * z;
}
It’s a tad slower than the first (though still nearly 2x as fast as Math.Sqrt()), but much more accurate:

MathSqrtTest: averageCompletionTime = 2428.400
ApproxSqrt2Test: averageCompletionTime = 1361.000
Average variation for method2: 0.000928551700594071

Sunday, September 25, 2011

Dead to Sin, Alive to Christ

Today was our last Sunday at Overlake Park Presbyterian Church. Three weeks ago, we made it public that we’d decided to begin attending a church closer to our house. This was a hard decision to make, and even harder to tell everyone about. Folks at OPPC have welcomed us warmly for the last seven years, and they love our kids. But it was nearly a half hour drive to church, and we decided that for our kids’ sake, we needed to belong to a church that was closer to home. So today we said goodbye. In a rather astonishing show of good will, they asked me to preach; and this is what I came up with.

Introduction

Many stories in the Bible evoke a sense of crisis, of paths diverging forever, of profound, world-changing events turning on the smallest details. God’s selection of Abraham. Moses hidden in the reeds. The sound of a horn at Jericho. The voice of an angel in Mary’s room. One of the most important examples of small details that change the course of history is found in the words that the risen Jesus spoke to Saul of Tarsus, when He met him on the road to Damascus. “Saul, Saul,” Jesus said, “why are you persecuting me?”

We’ve heard those words so many times that we often miss their significance. To put them into perspective, ask yourself the question, “Who was it that Saul had thought he was persecuting?” Because of course, Saul hadn’t been intending to persecute Jesus at all. As far as Saul knew, Jesus was dead and buried, and good riddance. Saul had been harassing Jesus’ followers precisely because Jesus wasn’t around to bother with. But that day, when Saul fell blinded onto the ground, Jesus didn’t say, “Saul, why are you persecuting my followers?” He said instead, “Saul, why are you persecuting me?”

We all know the rest of the story. As a result of his archetypal “Damascus road experience,” Saul became a Christian. He disappeared from sight for some years. And when we hear from him next, he is already an apostle and a missionary, proclaiming loudly and eloquently the story of Jesus’ life and death. But Paul is also doing something else that is quite interesting. He’s not just telling the story of Jesus: he’s telling us what the story means. Because, after all, that story is a little ambiguous, isn’t it? I mean, so there was this Jewish rabbi from Galilee who caused a bit of a stir, and stirred up a bit of trouble, and ran afoul of the establishment, and ended up tortured to death at the hands of a police state. His followers claimed that this rabbi had come back from the dead, but even if that was true, well, so what?

It’s precisely that “so what” which interested Paul. And for Paul, the key to understanding the significance of Jesus’ life, death and resurrection lay in those first words from Jesus’ mouth: “Saul, Saul, why are you persecuting me?” Because those words tell us, as they told Paul, that those who follow Jesus are not just well-meaning disciples of some Jewish rabbi. On the contrary, those followers are Jesus, and when Paul was persecuting them, he was actually persecuting Jesus Himself. And if that is true, something big and entirely unexpected is afoot.

The Cross

In his letters, Paul develops this initial insight in a variety of different ways. One of them is through his familiar image of the Church as the Body of Christ. To the Corinthians Paul wrote, “Now you are the body of Christ, and each one of you is a part of it” (1 Cor. 12:27). And to the Romans, similarly, “For just as each of us has one body with many members, and these members do not all have the same function, so in Christ we, though many, form one body, and each member belongs to all the others” (Rom. 12:4-5).

As the poet Gerard Manley Hopkins put it,

the just man...
Acts in God’s eye what in God’s eye he is—
Chríst—for Christ plays in ten thousand places,
Lovely in limbs, and lovely in eyes not his
To the Father through the features of men’s faces

The other way Paul develops this insight may be a little less familiar to us, though it is perhaps even more important. Paul says that when Jesus suffered and died on the cross, we ourselves, the Church, were right there with him. “Do you not know,” he asks in today’s passage, “that whoever has been baptized into Christ Jesus has been baptized into his death?” (Rom. 6:3). “I am crucified with Christ,” he writes to the Galatians, “and I no longer live, but Christ lives in me” (Gal. 2:20). And in the same way, we were somehow present in Christ at the moment of His resurrection. “We were therefore buried with him through baptism into death in order that, just as Christ was raised from the dead through the glory of the Father, we too may live a new life” (Rom. 6:4).

But what exactly does this mean, to be “crucified with Christ”? And why have Christians always believed that the cross was at the heart of Christianity?

To put this into perspective, if you were a Muslim, the symbol of your religion would be a crescent moon.  If you were a Buddhist, the symbol of your religion would be a lotus flower.  If you were a Jew, the symbol of your religion would be a six pointed star.  These all symbolize things like beauty, grace and life. But as Christians, our emblem suggests nothing like that.  Our emblem is the cross, a crude but effective method of execution invented by the Romans for the gruesome purpose of convincing would-be criminals that whatever they were contemplating, it just wasn't worth it.  The symbol of Christianity is a symbol of ugliness, suffering and death.  Why?  Why do all other religions have as their symbols something reminiscent of light and beauty, yet Christians insist on exactly the opposite?

I certainly don’t have a complete answer. But it’s worth noting that this theme of death and resurrection was not merely a Christian invention. On the contrary, it has been the refrain of the great myths and stories throughout history. The Babylonians told the story of how Gilgamesh sought and failed to find the secret of immortality after the death of his best friend. The Egyptians told the story of how Osiris was brought back to life after his body was cut into 14 pieces and scattered across the earth. The Greeks told of Persephone, and how she was abducted by the king of the underworld, and then returned to the earth again after her mother cut a deal with the gods. Perhaps most remarkably, Nordic legends tell of how Odin, the chief of the gods, sacrificed himself to himself, by piercing his side with a spear and then hanging himself on the holy tree at the center of the world.

Beyond those legends, science tells us much the same story. According to the theory of evolution, life arose through pain and suffering and sacrifice. Think of how many different systems in your body need to work perfectly, just to keep you alive. Then think about how many random genetic mutations were required to arrive at those perfectly functioning systems: and how many thousand times more mutations failed, and left the organisms who inherited them vulnerable to accidents, predators and sickness. You and I have life only because untold billions before us suffered and died. Our bodies work because their bodies didn’t. You might very well say, “By their stripes we are healed.”

In other words, a life that comes through death is at the beating heart of our world. So when we see the same pattern in Christianity, we shouldn’t be surprised. Life followed by death followed by new life is not just an abstract doctrine: it’s as close as we can come to reality itself. As George MacDonald put it, “When Jesus died on the cross, He did that, in the wild weather of his outlying provinces, which he had done at home in glory and gladness.”

Crucified with Christ

So then: Christians have chosen the cross as their emblem, because we believe that it gives expression to the fundamental reality underlying the universe. As Paul said, “We preach Christ crucified: a stumbling block to Jews and foolishness to Gentiles, but to those whom God has called, both Jews and Greeks, Christ the power of God and the wisdom of God” (1 Cor. 1:23-24). But again I ask: what does this mean? So we are somehow united with Christ in his death and resurrection; and Christ’s death and resurrection somehow shows who God is in a way that nothing else could. But what does that mean? What is its significance? Does believing this actually change anything?

This is a profound question, and I don’t think we can do anything more than touch on it today. But it’s worth noting three things.

#1 – This is God’s Life

The first is that Jesus tells us that it’s only by conforming to this pattern that we can partake of the life that He came to bring. In Luke 9:23, Jesus says, “Whoever wants to be my disciple must deny himself and take up his cross daily and follow me. For whoever wants to save his life will lose it, but whoever loses his life for my sake will save it.” I don’t think that Jesus is saying, “Unless you’re willing to sacrifice yourself, you’re not good enough to be a Christian.” Rather, I think he means that sacrificing ourselves is what the Christian walk looks like. We partake of the life that God offers us precisely to the extent that our lives resemble God’s Life; and that Life is a life of love, and therefore of sacrifice. The same is also true of another difficult saying of Jesus: “Whoever wants to become great among you must be your servant, and whoever wants to be first must be the slave of all. For even the Son of Man did not come to be served, but to serve, and to give his life as a random for many” (Mark 10:43-45). The requirement that we serve others is not an arbitrary standard, a line which God drew in the sand but which could have been drawn elsewhere; rather, the requirement of service expresses certain unalterable facts about God’s own nature.

#2 – This is forgiveness

The second thing to note has to do with forgiveness. For both to ask and to receive forgiveness is a kind of death. In the Lord’s Prayer, we pray, “Forgive us our debts, as we forgive our debtors.” Again, it’s not that God won’t forgive us unless we forgive others; it’s that we can’t truly repent, and ask for that forgiveness, until we ourselves have learned to extend it.

I’ve had a pretty good life, and I can only think of one instance where someone has done me a significant and genuine injustice. I was angry about that injustice for years; and if you get me talking too much about it, you’ll find that I still am. It’s very true, of course, that my anger, and my lack of forgiveness, isn’t hurting anyone except me. But it is hurting me, and it’s hurting me precisely because that part of me doesn’t want to die. I want to hold on to my rights, I want to insist on what’s coming to me. And to the extent that I’m not dying to myself, to the extent that I’m continuing to hold on to my natural life, I simply can’t participate in the new life that Jesus offers.

Because I need to be clear: extending forgiveness to someone who has genuinely done you wrong, means death. Imagine trying to forgive a serial killer who had kidnapped, tortured and murdered one of your children. Even the thought of forgiving someone who had done that would gnaw away at your insides. It would feel like you were betraying your murdered child; it would feel like you were condoning the murderer’s actions. In short, it would kill you to forgive him. But it would kill you in the right way. It would put to death just that much more of that part of yourself which refuses to participate in God’s life.

But there is maybe even a better way to look at it. For if it hurts us to forgive someone who has done us an injustice – just imagine how it must feel to God. Can it be any less of a death for God to forgive? God loves the child who has been murdered, the wife whose husband was unfaithful, the partner who was cheated out of his business, far more than we could ever hope to. If it kills us to forgive someone, how much more must it kill God? And if Christianity is right, that is precisely what it did: it killed God. People talk nonchalantly about God forgiving sins as if it was the easiest thing in the world. But our own experience gives the lie to that facile assumption. Forgiving sins isn’t easy: there is no more difficult thing in all of creation. It’s so hard that the undying God Himself had to die in order to do it. And we must die as well, if we want to participate in that forgiveness.

#3 – This is Resurrection

Third, we must remember that Jesus’ death on the cross was not the end of the story. Yes, Jesus died; and it was a true death. His heart ceased to beat. The neurons in his brain ceased to register the agony of his body. His muscles, on fire for the last six hours, finally slumped, and his corpse began its slow, inevitable decomposition in that merciless April sun. But God had something else in store, for He would not abandon Jesus to the realm of the dead, nor allow His Holy One to see corruption. On the morning of the third day, God raised Jesus from the dead; and the life he now lives, he lives to God. One small part of the meaning of the Resurrection is the lesson that God is faithful to those who engage in self-sacrificial love. Indeed, how could He not be? For He cannot deny Himself; and those who sacrifice their own desires for the good of others, are already living in God’s love, whether they know it or not. If we die to our sinful nature, we will be alive to God. As Paul says elsewhere in Romans, “And if the Spirit of him who raised Jesus from the dead is living in you, he who raised Christ from the dead will also give life to your mortal bodies because of his Spirit who lives in you.”

Two Stories

I should point out as well that self-sacrificing love is not merely rewarded in heaven. To the extent that we live in that love in this life, to the extent that we die to ourselves, we experience God’s new life right now.

I have two examples of how this can work: one from my own very recent experience, another from the experience of one of the great saints of the Church.

Olivet University

To give you some background, twenty years ago, I graduated from a small Christian school in the Santa Cruz Redwoods named Bethany University. Bethany was a lovely school in many ways, but it’s been teetering on the edge of financial ruin for years, and finally, this summer, it ran out of money and was forced to close its doors. Many people had loved that school, and were genuinely grieved at its closure. But within a month after Bethany announced that it was closing, another tiny Christian school by the name of Olivet University announced that it was going to purchase the Bethany campus, and continue Bethany’s mission of ministerial training. On the face of it, this was welcome news.

But after that, things kind of got weird. This isn’t the place to go into all the details, but suffice to say that this new school, Olivet, was surprisingly sloppy with the truth as they began the process of moving onto the Bethany campus. To a wide range of alumni who were still grieving their school’s demise, it felt like our school’s heritage was being used fraudulently – and for purposes that we could only guess at.

My involvement in all this started when I wrote a blog entry in which I complained about some of Olivet’s behavior, and pointed out some of the misinformation that they had been spreading. I uploaded the post to my blog, turned off my monitor, and headed downstairs with a book. I presumed that was going to be the end of it: among other things, really, nobody reads my blog. So I was pretty well surprised when I got a phone call that very evening from an Olivet administrator, in which he threatened legal action if I didn’t take my blog post down.

I didn’t take it down, of course, but as you can imagine, that was the wrong approach for him to take, and it got me even more suspicious about what Olivet was up to. So I started doing quite a bit of research on Olivet University, its history, its background, its faculty, everything I could find. And I followed up that initial blog post with several more, detailing some of the relevant information that I’d found. And some of the information I found was indeed quite interesting.

But here’s the point that I’m finally getting to. As I was researching Olivet, and writing up my findings, I found myself, almost without thinking about it, wanting to stretch the truth. Olivet had made me angry; and I absolutely wanted the bad things I found to be worse than they were; and I absolutely wanted the good things I found to not be as good as they were. I wanted to include any incriminating information I turned up, even if I thought it wasn’t likely to be true; and I wanted to leave out anything that tended to exonerate them. I found myself having to go back and rewrite whole paragraphs of my blog posts, because I had been doing exactly what I was accusing Olivet of doing, of being insufficiently careful with the truth. In brief, I wanted to be right, and I was willing to go to rather inappropriate lengths to convince others that Olivet was in the wrong. Worse than anything else, though, was the realization that I tended to do this with more frequency than I was happy to admit. My conflict with Olivet was not the first time that I had been ready to present “facts” with an unwarranted confidence.

I’ll confess, I wasn’t entirely comfortable when God pointed this out to me. But after some squirming, I did what I should really do more frequently: I repented. I didn’t get down on my knees or anything, but as I sat there, my hands on my keyboard, I prayed, “God, help me to love the truth more than being right.”

As I stand here now, I’ll confess, that sounds kind of lame. But I can’t express how freeing that simple prayer was. I have no illusions about being cured of my tendencies to exaggerate, or my desire to prove the other side wrong. But at least in that one particular debate, that one particular prayer entirely changed my perspective. The debate was no longer about me, but about the truth, and that made all the difference. I ended up having to admit that I was wrong about a couple things, but it felt OK to say so. And when my worst suspicions about Olivet eventually proved to be unfounded, I was very grateful that those suspicions hadn’t made it onto my blog. Giving up my insistence on being right was only the tiniest sip from the cup of death: but the freedom which followed in its wake was no minor taste of life.

St. Francis of Assisi

The second story I have to tell comes from the life of St. Francis of Assisi. Apart from Jesus himself, more than any other human being, St. Francis’ life is an example of the extent to which dying to yourself is merely the start of an entirely new life. You may know the story. St. Francis was born to a wealthy family, but in his early twenties he renounced all of his worldly possessions, and began to serve and care for the lepers around his village. St. Francis has a well-deserved reputation for loving nature, and for caring for all of God’s creatures; but it’s worth noting that this love of nature was combined with a very strong asceticism. He renounced any possessions, he walked barefoot through the snow, and regularly engaged in extended fasts. During one such forty-day fast in preparation for Easter, St. Francis prayed that he would know the full pain that Christ suffered, and in answer to this prayer received the stigmata, the five wounds of Christ in his own body. When he died two years later, he requested that they lay him naked on the ground, so that he could return to God the same way he came. Several years ago, a modern medical analysis of St. Francis’ skeleton showed that he was suffering not only from starvation, but also quite likely from leprosy.

And yet, despite these sufferings, those who knew him universally said that the overriding characteristic of St. Francis was not pain, not sadness, not depression; but rather joy.

In his biography of St. Francis, G. K. Chesterton sums up this paradox well:

[St. Francis’ self-denial] was as positive as a passion; it had all the air of being as positive as a pleasure. He devoured fasting as a man devours food. He plunged after poverty as men have dug madly for gold. … He held on this heroic course from the moment when he went forth in his hair-shirt into the winter woods to the moment when he desired even in his death agony to lie bare upon the bare ground, to prove that he had and that he was nothing. And we can say, with almost as deep a certainty, that the stars which passed above that gaunt and wasted corpse stark upon the rocky floor had for once, in all their shining cycles round the world of labouring humanity, looked down upon a happy man.

Conclusion

OPPC has been through a great deal over the last year. We said good-bye to Charlie last August, and then unexpectedly had to say goodbye to him again just last month. We said goodbye to Pastor Vonna just last week. And as you presumably know, Galena and I are saying our own goodbyes: this is our last Sunday here. With all of these changes, I wouldn’t be surprised if some of us sometimes felt a little like St. Francis, lying shivering on the rocky floor.

But if you feel that way, think back again on Jesus’ words to Paul. Any pain that Jesus’ church feels, is experienced by Jesus Himself. All authority in heaven and on earth has been given to our Lord; and we go forth today, not merely in His name, but with His power and authority coursing through our own bodies. We die daily, but our life, our true Life, is hidden with Christ in eternity. OPPC may yet have further deaths to die, whether literal or sacramental, and that is as it should be. In a far less dramatic manner than St. Francis, we are called to partake of our Lord’s sufferings; but we are equally called to partake of our Lord’s glory. For we are His Church, His Body, and we live in the power of His resurrection.