An Algorithmic Lucidity

a blog

The Morality of Ringing a Bell

"Synthia, I want your opinion on something," said Quiana.

"You will have it."

"Is it wrong to enjoy ringing a bell?"

"Pardon me?" said Synthia.

"I said," said Quiana, "is it wrong to enjoy ringing a bell?"

"I heard you the first time," said Synthia irritably, "but I presume the question is prompted by some context you have not yet told me, a context I would need to know to provide you with the best answer I can give."

"There's a fast-food place near the campus," Quiana explained, "and next to the door, there's a bell that you can ring by pulling a cord, and a sign that says, 'If Your Visit Was Swell, Ring the Bell.'"

"And I suppose you're telling me that you go to this restaurant solely for the purpose of getting to ring the bell?"

"Maybe not solely, but yes! I can't think of any other situation where it would be socially acceptable to ring a bell in public. But here, the sign asks you to do it, and that makes it okay." She frowned. "Except," she added, "I even ring it on the occasions that my visit isn't swell."

"In your defense," said Synthia, "the sign doesn't suggest that you shouldn't. Otherwise it would have said, "Ring the bell if and only if your visit was swell."

"That's nice of you to say, but you know as well as me that interpreting the the English language if as a material conditional is at least problematic, especially given that there's no special reason to expect that the sign-writer understood propositional logic."

"True. But why would it be wrong to enjoy ringing the bell?—you must have a reason to suspect as much, or you wouldn't be asking the question. Is it that you don't want to reward the restaurant for ruthlessly exploiting your love of bells?"

"No, just the opposite! I'm worried that I'm being exploitative! The bell has a clearly-defined purpose: to let the employees know that your visit was swell."

"I think they'd prefer a tip."

"Of course. But the managers didn't give them a tipjar; they put out a bell, and I'm using the bell for spurious purposes! Isn't that wrong?"

"Quiana, I don't know why you bother asking me about your moral dilemmas; you know I don't have the kind of respect for Authority and Society that you do. I could walk you through costs and benefits: benefits to you of ringing the bell, possible costs to other diners who don't want their meal interrupted by a bell, mild appreciation of your apparent appreciation on the part of the employees, benefits to the restaurant owner for patronizing their business—but none of these observations will help you, because your morality isn't about facts that can be observed or computed from things that can be observed. Your morality is based on finding the 'correct' interpretation of verbal rules you read or heard. But if there isn't a uniquely preferable interpretation, if the words fail to capture the structure of reality, you get an unresolvable dilemma."

"And that's the reason you can't answer my question?"

"No, that was my answer."

The Problem With My Friend Who Has This Problem

Dear reader, I have this ... friend, who has this problem, and I wanted to ask—

What do you mean, Who is he? You wouldn't know ... her, and—

You must realize that I'm already aware that it's a standard trope for someone to say "I Have This Friend" when they're really talking about themselves, and given that I know it's already a standard trope, I would never be so obvious as to actually do it! Therefore you must truthfully conclude that I really am talking about a—

Okay, that's a good point. No, I didn't consider the fact that that reasoning can't possibly be sound because if it were, then people would use it as an excuse to falsely claim that they were speaking about a friend rather than themselves, thereby contradicting the assumption that the reasoning is—

Well, we could try to calculate the probability that I really am talking about a friend conditional on your epistemic state and taking into account the game-theoretic considerations just mentioned, but that could take all night, so will you just listen to my transparent lies for fuck's sake?

Thank you. So I have this friend, who has this problem, which is that there's a not-infrequently-occurring scenario in which she has trouble doing stuff, which is this: she feels morally obligated to make progress on some work she owes someone else, but she also wants to make progress on her own personal projects. She thinks she ought to work on the thing she owes someone before she works on her own stuff, but doesn't feel motivated to work on the thing for someone else, and she doesn't feel like she's earned the right to work on her own stuff, so she just ends up doing nothing instead. (Or not literally "nothing"; she looks at mildly informative articles and mildly amusing captioned images on the internet. But that should be considered a ground state which might as well be called nothing.) And so the day becomes a double tragedy: not only has she failed her sacred duties to someone else, she's also failed her sacred duties to herself, and for what? Tech news emphemera? Keeping up with all the comments on her favorite community blog? An adorable animated Graphics Interchange Format file of Rainbow Dash jumping on a bed? Not worth it!

Of course the right thing to do would be to efficiently work on the project she owes someone for a reasonable amount of time, and then work on her own project, but if my friend knew how to "just" do the right thing regardless of psychological state, then this problem wouldn't exist (and I wouldn't waste your time telling you about a problem that doesn't even exist on behalf of my friend who also doesn't ex—uh, doesn't ex–pect me to annoy you with problems that—unlike my friend—don't exist). To say that she should "just use willpower" isn't necessarily wrong, but it needs to be made more specific for the use of my poor friend, or an easier-to-use (although morally or pragmatically inferior) strategy is needed.

So I recommended to my friend that when she notices herself in this situation, maybe she should just start working on her personal stuff that moment, with the quiet hope that the psychological momentum of doing something, anything, can be carried over to fulfilling her obligations to others later in the day. Again, it's not the right thing to do, but surely it's better than what she lets happen now. It is written that the perfect is the enemy of the good, with the implied moral being that we should side with the merely good. I would prefer to say that the perfect is the enemy of the good, and while we would hope for the perfect to mercilessly annihilate all its enemies, sometimes you have to temporarily ally with a stronger enemy (in this case, the good) in order to vanquish an even greater foe (in this case, evil). But for humans at least, it amounts to the same thing.

Did I say the Right Thing?

A "Knock, Knock" Joke

This one is a classic that I love to repeat; stop me if you've heard it before. Knock, knock.

"Who's there?"

Truly repentant are those.

"Truly repentant are those who?"

Truly repentant are those who, when the temptation to sin is repeated, refrain from sinning!

Training Your Very Own Turtle to Draw the Boundary of the Mandelbrot Set

Dear reader, I don't think I've ever told you how much I love the Python standard library, but I do. When they say "Batteries included," they may not mean it in the sense of "a device that produces electricity by a chemical reaction between two substances," but they do mean it in the sense of "an array of similar things," where the similar things are great libraries. If you need a CSV reader, it's there. If you need fixed-point decimal arithmetic, it's there. But although perhaps it should not have surprised me, never has my joy and appreciation been greater than the fateful moment when I learned that the standard library itself contains a module for

TURTLE GRAPHICS

Yes, turtle graphics! In case you had a deprived childhood, I should explain: the idea is that you have a cursor on the screen (the turtle), and you can type, say,

FORWARD 10

and then the turtle will move forward ten units, drawing a line as it goes. And then you can say, like,

RIGHT 60

and the turtle will rotate 60 degrees clockwise. What a glorious introduction to the idea of computing: the user has her very own turtle to command, in effect becoming a godlike master of turtle existence with power limited only by her imagination and the bounds on thought itself! Isn't that truly outrageous (truly, truly, truly outrageous)?!

No it's not, you say? Well, fair enough. It is only to be expected that we should grow jaded with small miracles as we gain experience, and maybe I should stop doing that thing where I pretend to be more enthusiastic about geeky things than I actually am in some pathetic and misguided attempt to signal intelligence and curiosity.

But in any case, as long as we have turtles, we might as well have them do something vaguely amusing. Like, let's say, drawing the edge of the Mandelbrot set? Sure, okay. Let's do it.

One thing you have to know about turtles is—well, it's probably not very polite to say this, but it needs to be said—they're not very bright. You can't just say, "Oh, turtle friend!—would you please be a dear and draw the boundary of the Mandelbrot set for me?" because they'd never figure out how to do that on their own. You've got to give them very specific instructions.

The other thing you have to know about turtles is that they don't speak English; you have to tell them what to do in their native language. Our particular turtle happens to speak Python.

Now we should be ready to proceed, except ... well, we've all seen the famous pictures of the Mandelbrot set, but how is it defined, anyway? Well, as the great Jonathan Coulton sings (slightly edited):

Just [let zee be zero] in the complex plane, Let zee-one be zee-squared plus cee, Zee-two is zee-one squared plus cee, Zee-three is zee-two squared plus cee, and so on. If the series of zees will always stay Close to cee and never trend away, That point is in the Mandelbrot set.

That is, we pick a number \(c\) in ℂ, iterate \(z_{n+1} = z_n^2 + c\) starting from zero, and if the \(z_n\) diverge off to infinity, then that particular \(c\) is not in the Mandelbrot set.

Let's start writing instructions for our turtle. First, we'll summon the turtle. Also, let's tell her to look up instructions on how to compute the argument of a complex number—don't ask me how, but I have a feeling we're going to need that later:

import turtle
from cmath import phase

Now, it turns out (claims Wikipedia, and I believe it), that if the absolute value of one of our \(z_n\)'s ever exceeds two, then that sequence will diverge. This seems like a useful fact, so let's tell our turtle how to calculate how many iterations it will take for the sequence associated with a particular c to exceed two, and if it doesn't do so within some given number of iterations, then to tell us that:

def z_n_escape_time(c, n):
    z = 0
    for i in range(n):
        z = z**2 + c
        if abs(z) > 2:
            return i
    return False

To approximate the boundary of the Mandelbrot set, we'll tell the turtle to consider a grid of reasonably-finely-spaced points, and to consider a point to be on the boundary if the number of iterations it takes for the sequence for that point to exceed two is in some given range. We'll also tell her to sort those points by their argument, because that seems like a somewhat-reasonable order to visit them in:

def mandelbrot_edge(resolution, iterations, edge):
    points = []
    x_coordinates = [-2+i*(3/resolution) for i in range(int(resolution*1.5))]
    y_coordinates = [1-j*(2/resolution) for j in range(resolution)]
    for x in x_coordinates:
        for y in y_coordinates:
            if z_n_escape_time(complex(x,y), iterations) in edge:
                points.append((x,y))
    points = sorted(points, key=lambda p: phase(complex(p[0],p[1])))
    return points

Then (choosing some reasonable-looking numbers as specific parameters for our earlier instructions) we tell our turtle to visit all those points, drawing along the way:

def draw_boundary(protagonist, boundary_points, speed):
    protagonist.speed(speed)
    protagonist.penup()
    protagonist.setheading(protagonist.towards(boundary_points[0][0],boundary_points[0][1]))
    protagonist.forward(protagonist.distance(boundary_points[0][0],boundary_points[0][1]))
    protagonist.pendown()
    for p in boundary_points[1:]:
        protagonist.setheading(protagonist.towards(p[0],p[1]))
        protagonist.forward(protagonist.distance(p[0],p[1]))

def main():
    setting = turtle.Screen()
    protagonist = turtle.RawTurtle(setting)
    protagonist.shape("turtle")
    points = [(190*p[0],190*p[1]) for p in mandelbrot_edge(300, 500, list(range(60,500)))]
    draw_boundary(protagonist, points, 10)
    setting.mainloop()

if __name__ == "__main__":
    main()

And we get this:

our heroine's valiant attempt to draw the boundary of the mandelbrot set

Okay, so it's not perfect. But give the turtle a little credit, maybe? She tried. We tried. And if that's not good enough—and, well, I guess it clearly is not good enough—then I can only beg for forbearance on the part of any powers that could save us from our imminent self-destruction, we wretched and miserable creatures that are good enough to try but not good enough to succeed.

Trying to Buy a Lamp

Dear reader, I had wanted to tell you an anecdote about a recent incident in which I considered myself to have been outrageously mistreated, but it occurred to me that you probably would not find the story at all worthy of note. In fact, I fear you would be quite likely to think less of me for complaining in such a melodramatic fashion about something which the prevailing norms of our Society consider quite ordinary and proper. And what authority do I have to insist that it's Society that is in the wrong, and not I?

So I won't tell you. Instead, let me tell you a completely unrelated anecdote about my analogue in an alternate universe not entirely unlike our own. You see, recently, my alternate-universe analogue wanted to buy a table lamp, so he went—or let us say in a manner of speaking that I went—to a store to purchase one.

In the showroom, I found a lamp I liked, flagged down a salesman, and said to him, "I'd like to buy this lamp."

"Have you previously purchased a side table from us before?" he said.

"No," I said, somewhat puzzled by the seemingly irrelevant question.

"Well, you can't buy a lamp unless you already have a table to put it on," said the salesman in a tone of polite condescension.

"Oh, I certainly agree that it simply wouldn't do to get a lamp without having a table to put it on," I said, "but you see, I already have a table."

"So you did buy a table from us."

"No," I said.

"So you don't have a table."

"No, I do have a table," I said.

"So where did you buy it?" he asked.

"I'm actually an amateur craftsperson," I explained, "I have a table which I built myself."

The salesman showed no sign of having failed to hear me, but he showed no sign of having understood me, either. "The table is a prerequisite for the lamp; you have to buy a table before you can buy a lamp," he said.

I sighed. "Okay," I said in resignation, "in that case, I would like to buy a table and a lamp."

"No, no," he said. "That's not how prerequisites work; you can't buy a table and a lamp in the same transaction."

I didn't understand how it could make any substantive difference whether I paid in one transaction or two, but I perceived that objecting as much would be a waste of time, so I asked, "When can I get this lamp by?"

"Well, we only offer table lamps in the fall, so ..." he paused for a moment, "September 2013."

I said, "May I please speak to your manager?"

"Well, you can try talking to the guy in charge of lamps," said the salesman, "but he's probably not going to tell you anything different."

It soon transpired that the person responsible for the lamps wasn't in that day. I got his email address and sent him a letter asking if I could please buy a lamp, attaching photographs of my table as evidence that I was in fact qualified to buy a lamp.

I did not receive a reply.

Not from him, anyway. A couple of weeks later, I did receive an email from the CEO of the company, which I excerpt below, verbatim:

From: SF State CEO Alternate Universe Robert A. Corrigan <ceo@sfsu.com>

To: Alternate Universe Zachary Davis <main@altunivzackmdavis.net>

Subject: Message From the Office of the CEO

Dear Alternate Universe Zachary Davis,

I am writing to ask you to tell our elected officials how important affordable access to furniture at San Francisco State Upholstery and Home Furnishings Company is to you. California’s budget will be adopted in the next few weeks and you have one more chance to let legislators hear your voice.

TAKE ACTION

Last November, the California Legislature passed a budget that cut $750 million in subsidies from the state furniture system, forcing the CSU Board of Trustees to approve price increases for fall 2012 for customers.

The notification of this increase was met, understandably, with anger and frustration. When I met with customers protesting these cuts on December 1, 2011 it was agreed that we needed to work together to take our case to our elected officials and the "Customer Voices Campaign" was born. We launched a website and collected more than 400 stories about how budget cuts and price increases had affected customers and their families.

TAKE ACTION

A few weeks ago, I joined customers for a trip downtown to meet with our elected officials. The customers brought hard copies of each letter. We have been assured that each and every letter will be read. Your fellow customers who joined me spoke with power and passion—they were impressive.

But I have to tell you, I am not optimistic that our legislators really understand how customers are affected when state budgets force us to reduce inventory and ask you to shoulder a greater share of the cost. Over the next two weeks they will be gathering in Sacramento to make their final budget decisions. We have over 30,000 SF State customers and over 400,000 customers in the CSU, now is the time to inundate our elected officials with reminders about how important their budget decisions are to us.

By clicking the link below, you can send a pre-prepared message to all of your elected representatives in just a few seconds. Let them know the real consequences of their budget decisions.

TAKE ACTION

Sincerely yours,

Alternate Universe Robert A. Corrigan, CEO

Reading this letter made me very angry. "If a business selling any other kind of product—for example, math tutoring—provided such uniformly terrible customer service, they would either go bankrupt, or be burned to the ground by an angry mob, whichever came first," I fumed to myself. "And yet not only do these people treat their customers poorly, but they expect to be rewarded for it with taxpayer subsidies?! And Society just gives it to them, instead of laughing them out of business? The world is surely mad!"

But my anger subsided within a few minutes. What authority did I have to insist that it was Society that was in the wrong, and not I? The prerequisite policy must have been put into place for a good reason, and nor was it hard to discern what that reason was. San Francisco State Upholstery was, ultimately, just trying to protect me. Might it not be delusionally arrogant of me, a mere amateur, to suppose that my homemade table was adequate to support a lamp? What if I had been permitted to buy a lamp, but then it fell over and broke because my table wasn't sturdy enough?—I had to admit that was at least plausible. Should I not then be grateful that I was not permitted to take such a foolhardy risk?

Still, I thought, it simply wouldn't do to leave my table bare and my room dark for more than a year. So I—that is, my alternate-universe analogue—set aside all irrelevant thoughts, grabbed his cheap paperback copy of How to Build a Lamp by Alternate Universe Georgi E. Shilov (translated from the Russian by Alternate Universe Richard A. Silverman), and headed off to his workshop, to work.

Interpolating Between Vectorized Green's Theorems

Green's theorem says that (subject to some very reasonable conditions that we need not concern ourselves with here) the counterclockwise line integral of the vector field F = [P Q] around the boundary of a region is equal to the double intregral of

$$\frac{\partial Q}{\partial x}-\frac{\partial P}{\partial y}$$

over the region itself. It's natural to think of it as a special case of Stokes's theorem in the case of a plane. We can also think of the line integral as the integral of the inner product of the vector field with the unit tangent, leading us to write Green's theorem like this:

$$ \oint_{\partial D}\vec{\mathbf{F}}\cdot\vec{\mathbf{T}}\, ds=\iint_{D}(\mathrm{curl\,}\vec{\mathbf{F}})\cdot\vec{\mathbf{k}}\, ds$$

But some texts (I have Mardsen and Tromba's Vector Calculus and Stewart's Calculus: Early Transcendentals in my possession; undoubtedly there are others) point out that we can also think of Green's theorem as a special case of the divergence theorem! Suppose we take the integral of the inner product of the vector field with the outward-facing unit normal (instead of the unit tangent)—it turns out that

$$\oint_{\partial D}\vec{\mathbf{F}}\cdot\vec{\mathbf{n}}\, ds=\iint_{D}\mathrm{div\,}\vec{\mathbf{F}} ds$$

—which suggests that there's some deep fundamental sense in which Stokes's theorem and the divergence theorem are really just mere surface manifestations of one and the same underlying idea! (I'm told that it's called the generalized Stokes's theorem, but regrettably I don't know the details yet.)

But here's something I thought was pretty. We have these two equations, one of which involves the unit tangent vector, and one of which involves the unit normal vector. (It's actually pointing in the opposite direction of the unit normal that we use to define the Frenet frame, which one might argue is an unfortunate clash of conventions, but whatever.) So my linear-algebraic intuitions say: hey, why not smoosh them together in a linear combination? (Making linear combinations is just what you do when you see orthogonal unit vectors, right?) Then it's like we're interpolating between the two forms of Green's theorem. Specifically, let θ be a constant. Then we have

$$\oint_{\partial D}\vec{\mathbf{F}}\cdot((\sin\theta)\vec{\mathbf{T}}+(\cos\theta)\vec{\mathbf{n}})\, ds$$

(component decomposition of some unit vector)

$$=\oint_{\partial D}\vec{\mathbf{F}}\cdot(\sin\theta)\vec{\mathbf{T}}+\vec{\mathbf{F}}\cdot(\cos\theta)\vec{\mathbf{n}}\, ds$$

(inner product distributes over vector addition)

$$=(\sin\theta)\oint_{\partial D}\vec{\mathbf{F}}\cdot\vec{\mathbf{T}}\, ds+(\cos\theta)\oint_{\partial D}\vec{\mathbf{F}}\cdot\vec{\mathbf{n}}\, ds$$

(linearity of integrals, bilinearity of inner product)

$$=(\sin\theta)\iint_{D}(\mathrm{curl\,}\vec{\mathbf{F}})\cdot\vec{\mathbf{k}}\, dA+(\cos\theta)\iint_{D}\mathrm{div\,}\vec{\mathbf{F}} dA$$

(vectorized Green's theorem)

$$=(\sin\theta)\iint_{D}\left(\frac{\partial Q}{\partial x}-\frac{\partial P}{\partial y}\right)\, dA+(\cos\theta)\iint_{D}\left(\frac{\partial P}{\partial x}+\frac{\partial Q}{\partial y}\right)dA$$

(planar curl and divergence)

$$=\iint_{D}(\cos\theta)\frac{\partial P}{\partial x}+(\sin\theta)\frac{\partial Q}{\partial x}-(\sin\theta)\frac{\partial P}{\partial y}+(\cos\theta)\frac{\partial Q}{\partial y}\, dA$$

(linearity of integrals)

Isn't that great!? Nor is it a mere coincidence that the coefficients in the final line resemble the entries of the two-by-two matrix representing a counterclockwise rotation by θ. Ideally, we would then generalize this to an arbitrary number of dimensions and gain true insight into the generalized Stokes's theorem, and thus, a facet of the nature of reality itself.

But I'm not there yet.

Untitled

"I just got an idea that will make a great blog post ..."

"No, it won't."

"What? I didn't even tell you the idea."

"I'm not denying that you had an idea; rather, I claim that it won't make a great blog post, because you won't write it. You wrote two nontrivial posts last year and then abandoned your blog for six months. Obviously, you're just like all the other millions of bags of human refuse who think of themselves as writers and yet never write. They never change, and you've shown by your behavior that you're one of them, so why should I believe you when you say you're going to write something?"

"Uh ..."

"Aww, are you offended? Is our little soi-disant 'aspiring rationalist' incapable of handling a honest statement of the undeniable truth?"

"No, I'm not offended. I disagree—"

"As expected."

"—but I won't argue with you. Just—stay subscribed to the RSS feed, will you?"

"Oh, but of course. It's not like anything will appear in it."

"..."

"This is the part where you threaten to drown me in a veritable deluge of good writing, and then I continue to mock the pathetic cycle of failure and self-delusion at the center of your existence."

"Let's skip that part. I'll see you later."

"I know what you're trying to do! It won't work!"

"I never said it would work."

Days Gone By

Should auld acquaintance be forgot and never brought to mind? Should auld acquaintance be forgot, and days of auld lang syne? (Hint: Assume the opposite and try to derive a contradiction.)

Dialogue Concerning Birthdays

"Happy birthday, Synthia!"

"Why," mused Synthia, "do we celebrate birthdays? I fail to see anything special about the calendar day on which a person's age-in-calendar-years passes an integer. Are things supposed to be different now that it's been seven-point-five-seven-four times ten-to-the-eighth seconds since my birth, rather than seven-point-five-seven-three?"

Quiana suppressed a groan. Somehow she had been expecting Synthia to say something "normal," like Thanks! But knowing Synthia, it would have been unusual if she had done so: relative to Quiana's state of knowledge of her friend, this—the general style, though not, of course, the specific questions—was the normal response.

Quiana said, "Is that a rhetorical question or a genuine one? Surely you can think of a few reasons yourself."

"I'd like to hear what you think."

"It's true that time itself is continuous and linear, and that there's nothing intrinsically special about a particular interval of time—whatever intrinsically would mean in this context. But we live on a planet with cyclic variation in weather and daylight, so it's natural to think in terms of days and years, and therefore, 'this day last year.' And even if things were otherwise—if our culture had matured on some sort of space station with no such natural cycles—integer units are indispensably useful; we need them in order to make sense of continuous quantities. We'd just end up celebrating our analogues of anniversaries every million minutes or whatever, for the same reason you just named intervals of time to merely four significant figures and in seconds, rather than using an arbitrary number of figures in some arbitrary units."

"That's not what I meant," said Synthia. "Of course I understand the importance of units, and I agree that if we're going to celebrate particular people for no reason, then it's not surprising that we do it on birth anniversaries—I can't think of a better Schelling point. Rather, my question is this: if a world without celebrations is too terrible to imagine, why do we have celebrations for no reason other than the calendar date?—this applies to regular holidays as much as birthdays. Why not reserve celebrations strictly for when someone actually accomplishes something?"

"Like ... a school graduation party."

It was just the first example that came to her mind, but Quiana was not surprised to see a brief flicker of pain cross Synthia's face.

"Yes, things like that," Synthia said.

"Well, if that's what you think, how do you justify the Christmas—"

"Newtonmas."

"—Newtonmas party you had here three days ago?"

Synthia shrugged and made a tight-lipped expression that Quiana could only interpret as meaning Yes, I'm a worthless hypocrite like everyone else; tell me something I don't know.

"But anyway," said Quiana, "even if you think people should earn their parties somehow, no one's throwing you an explicit celebration today; I didn't even get you a gift. So when I said 'Happy birthday, Synthia!' two minutes ago, why didn't you just say 'Thanks,' as if I had said 'Happy Wednesday!' or 'I hope you're having an excellent interval between eleven-thirteen and noon-minus-pi-minutes'?"

"Oh, is that what you meant?"

"... yes?"

Synthia beamed. "Thanks."

The Derivative of the Natural Logarithm

Most people learn during their study of the differential and integral calculus that the derivative of the natural logarithm ln x is the reciprocal function 1/x. Indeed, sometimes the natural logarithm is defined as

$$ \int_1^x \frac{1}{t}\,dt$$

. However, on observing the graphs of ln x and 1/x, the inquisitive seeker of knowledge can hardly fail to notice a disturbing anomaly:

y=ln(x) y=1/x

The natural logarithm is only defined for positive numbers; no part of its graph lies in quadrants II or III. But the reciprocal function is defined for all nonzero numbers. So (one cannot help oneself but wonder) how could the latter be the derivative of the former? If the graph of the natural logarithm isn't there to be differentiated in the left half of the plane, how could its derivative be defined in that region? Some would-be explorers lose all hope or sanity in the face of such bizarre and inexplicable mysteries, but even those brave souls who manage to retain their wits are not guaranteed success: many (who can say but that most?) will die never knowing the answer. But not you, dear reader!—for in this very post, I will share with you the true secret of the derivative of the natural logarithm! Some people may find some of what I am about to say somewhat disturbing, even frightening. But if your love of truth exceeds your fear of the unknown, keep reading, and I will show you the strange world that lies beneath these familiar and seemingly innocent graphs.

You see, dear reader, the natural logarithm is not what we think it is. Your typical person-in-the-street hears talk of the natural logarithm and says, "Oh, sure, I know all about ln x; that's just the exponent you put on base e to get x." And, to be fair, it is. But it's also so much more! Ask our person-in-the-street what exponent you put on base e to get negative three, and no doubt she will regard you as mad. "Manifestly," we can imagine her replying, "manifestly there's no such thing. The exponential function ex is always positive." And, to be fair, it is—if you arbitrarily restrict your mind to the mundane, oppressive, and boring magisterium of the so-called "real" numbers!

Probably the dear reader is already familiar with the numbers which are said to be complex, those of the form a + b\(i\), where \(i\) is the square root of negative one. (To those who object that taking the square root of a negative number is a feat that simply cannot be done, the proper reply is only, "Watch me!") The reader may furthermore recall the Euler formula \(e^{ix} = \cos x + i \sin x\), source of the much-marveled-at identity \(e^{\pi i} = -1\). With these prerequisites understood, it's quite reasonable to suspect that if we have a complex exponential, its inverse must be the complex logarithm, and that true apprehension of the nature of such is the key insight that will let us resolve the mystery at hand. And this does, in fact, turn out to be the case—but not so fast.

There is a difficulty here that must be explained. The dear reader may still yet furthermore recall that to say that a function is invertible is to say that it is both injective (which is to say that every element in the codomain is mapped to by at most one element in the domain, which is to say that distinct inputs have distinct outputs) and surjective (which is to say that every element in the codomain is mapped to by at least one element in the domain, which is to say that our codomain only includes actual outputs of our function). And dear reader, it turns out (to our great horror and distress) that the complex exponential is not injective! Was our dream of a complex logarithm nothing but a gaudy delusion?

On further consideration, however, it becomes clear that the situation is not so bad as all that. Probably the dear reader has faced analogous difficulties before. Recall that positive numbers actually have two square roots, a positive one and a negative one, and yet we casually designate the positive one as the principal square root, yielding us a square root function. We use a similar technique to define inverse trigonometric functions. Is it ugly? Yes. But does it work? Apparently.

So we can perform the same kind of surgical horror in order to get a proper function out of the complex logarithm idea: pick a ray emanating from the origin in the complex plane and cut the logarithm there—but I'll spare the dear reader the grisly details, which can be found in any standard text on complex analysis.

There is, however, another point of view. The reason a function needs to be injective in order to be invertible is because functions are defined such that each input has a unique output. There are reasons for defining it that way, but it is ultimately only a definition, a convention for what we mean when we use the world function, and mere definitions can't coerce true facts into being something other than what they are. Just because a non-injective function doesn't have an inverse function doesn't mean we can't talk about that-which-inverts-it; it only means that for clear communication, we should avoid calling the inverting-thing a function. Just call it a multifunction or a relation instead. (One can even imagine that if the history of mathematical inquiry had gone differently, we might call multifunctions functions and functions (say) deterministic functions, although some would argue that it is useless and idle to speculate about worlds that are not our own.)

So if we understand the complex logarithm multifunction as that-which-inverts the complex exponential, then we can understand the logarithm of a negative number \(-x_0\) as \(\ln x_0 + (2n+1)\pi i\) where \(n \in \mathbb{Z}\), because \(e^{\ln x_0 + (2n+1)\pi i} = e^{\ln x_0}e^{(2n+1)\pi i} = -e^{\ln x_0} = -x_0\).

But now we are ready to resolve the mystery that we set out to explain, of why the reciprocal function is the derivative of the natural logarithm even though no real number is the logarithm of a negative number, for now it is plain to see that the logarithm of a negative number is complex, but the derivative of the logarithm is real, because the imaginary part is a constant that drops out when we take the derivative:

$$ f'(-x_0) = \lim_{h \to 0} \frac{f(-x_0+h)-f(x_0)}{h} = \lim_{h \to 0} \frac{(\ln{(x_0 - h)} + (2n+1)\pi i) - (\ln{x_0} + (2n+1)\pi i)}{h}$$
$$ = \lim_{h \to 0} \frac{\ln{(x_0 - h)} - \ln{x_0}}{h}$$

—which turns out to be \(-1/x_0\), as expected.

Some might object that this argument is so sloppy as to be treacherous, misleading, and invalid: we've brazenly assumed that the definition of the derivative familiar from the study of the single-variable calculus can be applied to this complex-valued thing that isn't even a function, with no concern for preciseness, rigor, or even the Cauchy-Riemann conditions. But look. Presented with a procedure that makes sense and gives the right answer, perhaps the dear reader would be so kind as to cut me some goddam slack? I would be ever so much obliged.