Chapter 16. Anti-gradients

This chapter is actually usually not taught until much later in 18.02, in Part India. However, I’m going to stick it in here, while your brain hasn’t been infested with integrals yet, since it’s a standalone question. However, if you prefer to follow 18.02 more strictly, you could skip this chapter for now and come back a month or two later once you actually need to know how to do it.

The goal of this chapter is to do ∇ backwards:

Goal
If you know ∇𝑓, can you go back and find 𝑓?

§16.1 [TEXT] There’s still +𝐶 everywhere

I’ll note right away that you still have the +𝐶 from 18.01. To elaborate, you might remember in 18.01 that for ∫𝑥2d𝑥=𝑥33+𝐶 for any constant 𝐶, and we usually just ignore the +𝐶 because it does nothing.

For 18.02 we’ll do the same thing. For example, if 𝑓1(𝑥,𝑦)=𝑥2+𝑦2 and 𝑓2(𝑥,𝑦)=𝑥2+𝑦2+17, then they have the same gradient:

∇𝑓1=∇𝑓2=(2𝑥2𝑦).

However, we just agree to not care about the constant; if asked to find a potential function, and 𝑓 is any acceptable answer, then so is 𝑓+100. But there are will be no other answers besides 𝑓+𝐶 for various 𝐶.

§16.2 [TEXT] Guessing works pretty well

Sometimes you might be able to just guess 𝑓, and if so, good for you. See if you can guess the answers to the following ones:

∇𝑓=(𝑥𝑦)∇𝑓=(𝑦𝑒𝑥𝑦𝑥𝑒𝑥𝑦)∇𝑓=(𝑦𝑧𝑧𝑥𝑥𝑦).

§16.3 [TEXT] Antiderivative method, if you’re promised there is one

Recipe: How to find an anti-gradient with two variables
  1. Let 𝑓 denote the gradient function.
  2. Integrate the given 𝜕𝑓𝜕𝑥 with respect to 𝑥 to get some equation of the form 𝑓(𝑥,𝑦)=expression+𝐶1(𝑦) for some function 𝐶1(𝑦).
  3. Integrate the given 𝜕𝑓𝜕𝑦 with respect to 𝑦 to get some equation of the form 𝑓(𝑥,𝑦)=expression+𝐶2(𝑥) for some function 𝐶2(𝑥).
  4. Stitch them together and output a function 𝑓.

With three variables, it’s similar, but more work.

Recipe: How to find an anti-gradient with three variables
  1. Let 𝑓 denote the gradient function.
  2. Integrate the given 𝜕𝑓𝜕𝑥 with respect to 𝑥 to get some equation of the form 𝑓(𝑥,𝑦,𝑧)=expression+𝐶1(𝑦,𝑧) for some function 𝐶1(𝑦,𝑧).
  3. Integrate the given 𝜕𝑓𝜕𝑦 with respect to 𝑦 to get some equation of the form 𝑓(𝑥,𝑦,𝑧)=expression+𝐶2(𝑥,𝑧) for some function 𝐶2(𝑥,𝑧).
  4. Integrate the given 𝜕𝑓𝜕𝑧 with respect to 𝑧 to get some equation of the form 𝑓(𝑥,𝑦,𝑧)=expression+𝐶3(𝑥,𝑦) for some function 𝐶3(𝑥,𝑦).
  5. Stitch everything together to output 𝑓.

Let’s do a two-variable example first.

Sample Question

We are given the gradient of a function 𝑓(𝑥,𝑦):

∇𝑓(𝑥,𝑦)=(𝑥+cos𝑦−𝑥sin𝑦)

Recover 𝑓.

Solution. This means:

𝜕𝑓𝜕𝑥=𝑥+cos𝑦and𝜕𝑓𝜕𝑦=−𝑥sin𝑦.

Integrate 𝜕𝑓𝜕𝑥 and 𝜕𝑓𝜕𝑦 with respect to 𝑥 and 𝑦:

𝑓(𝑥,𝑦)=∫𝜕𝑓𝜕𝑥d𝑥=∫𝑥+cos𝑦d𝑥=𝑥22+𝑥cos𝑦+𝐶1(𝑦).𝑓(𝑥,𝑦)=∫𝜕𝑓𝜕𝑦d𝑦=∫−𝑥sin𝑦d𝑦=𝑥cos𝑦+𝐶2(𝑥).

Stitching these together to get the final expression for 𝑓(𝑥,𝑦) as:

𝑓(𝑥,𝑦)=𝑥22+𝑥cos𝑦+𝐶

for any constant 𝐶.□

Sample Question

We are given the gradient of a function 𝑓(𝑥,𝑦):

∇𝑓(𝑥,𝑦)=(3𝑥2+4𝑥𝑦+𝑦22𝑥2+2𝑥𝑦−3𝑦2)

Recover 𝑓.

Solution. This means:

𝜕𝑓𝜕𝑥=3𝑥2+4𝑥𝑦+𝑦2and𝜕𝑓𝜕𝑦=2𝑥2+2𝑥𝑦−3𝑦2.

Integrate 𝜕𝑓𝜕𝑥 and 𝜕𝑓𝜕𝑦 with respect to 𝑥 and 𝑦:

𝑓(𝑥,𝑦)=∫𝜕𝑓𝜕𝑥d𝑥=∫(3𝑥2+4𝑥𝑦+𝑦2)d𝑥=𝑥3+2𝑥2𝑦+𝑥𝑦2+𝐶1(𝑦)𝑓(𝑥,𝑦)=∫𝜕𝑓𝜕𝑦d𝑦=∫(2𝑥2+2𝑥𝑦−3𝑦2)d𝑦=2𝑥2𝑦+𝑥𝑦2−𝑦3+𝐶2(𝑥).

Stitching this together gives

𝑓(𝑥,𝑦)=𝑥3+2𝑥2𝑦+𝑥𝑦2−𝑦3+𝐶.

□

Here’s a three-variable version.

Sample Question

We are given the gradient of a function 𝑓(𝑥,𝑦,𝑧):

∇𝑓(𝑥,𝑦,𝑧)=(𝑦2−sin(𝑥)2𝑥𝑦+4𝑦𝑧𝑒𝑧+2𝑦2).

Recover 𝑓.

Solution. Again, integrate with respect to all three components:

𝑓(𝑥,𝑦,𝑧)=∫(𝑦2−sin𝑥)d𝑥=𝑦2𝑥+cos𝑥+𝐶1(𝑦,𝑧)𝑓(𝑥,𝑦,𝑧)=∫(2𝑥𝑦+4𝑦𝑧)d𝑦=𝑥𝑦2+2𝑧𝑦2+𝐶2(𝑥,𝑧)𝑓(𝑥,𝑦,𝑧)=∫(𝑒𝑧+2𝑦2)d𝑦=𝑒𝑧+2𝑦2𝑧+𝐶3(𝑥,𝑦).

Here again 𝐶1(𝑦,𝑧) is some function depending only on 𝑦 and 𝑧; similarly for 𝐶2 and 𝐶3. Now stitch everything together:

𝑓(𝑥,𝑦,𝑧)=𝑦2𝑥+cos𝑥+2𝑦2𝑧+𝑒𝑧+𝐶.

□

§16.4 [TEXT] Actually most of the time no potential function 𝑓 exists

So far this might feel like 18.01 integration beefed up to many variables. But something is actually different. Up until now I’ve picked gradients for which there was an answer.

But most of the time that’s not true: the thing that’s different in 18.02 is that for a randomly written question this task is really impossible. That’s actually a major difference.

Digression: There’s a huge difference between “not easy to write the answer” and “no such function exists”

Weren’t there impossible integrals in 18.01? Well, it depends on what you mean by “impossible”. For example, a question you won’t see in 18.01 is

∫cos(𝑥2)d𝑥

which can be translated to “find a function 𝑓 such that 𝑓′(𝑥)=cos(𝑥2)”. The reason you’re not asked this in 18.01 is because, while such a function 𝑓 does exist, it can’t be expressed in a way that makes sense to 18.01 students.

But I mean, you could always cheat and write

𝑓(𝑡)=∫0𝑡cos(𝑥2)d𝑥.

The right-hand side really evaluates to some number for every 𝑡, e.g. if you do numerical analysis 𝑓(1)≈0.904524, 𝑓(2)≈0.461461, etc. So there really is some function 𝑓 whose derivative is cos(𝑥2). It just doesn’t have any good way to write it down. That means, if you tried to solve the question in 18.01 methods, you just eventually run out of methods and ideas to try.

In the 18.02 version, we’re about to see that even simple analogous questions might have answer “no such function exists”. So when you try to solve an impossible anti-gradient question, something really different will happen: rather than running out of methods and ideas, you can follow the usual method and then reach a contradiction.

Question

Determine whether or not there exists a differentiable function 𝑓(𝑥,𝑦) such that

∇𝑓=(2𝑦𝑥).

Solution. We can imagine we follow through the same method as before. Integration gives

𝑓(𝑥,𝑦)=∫2𝑦d𝑥=2𝑥𝑦+𝐶1(𝑦)𝑓(𝑥,𝑦)=∫𝑥d𝑦=𝑥𝑦+𝐶2(𝑥).

For these to be equal we need 2𝑥𝑦+𝐶1(𝑦)=𝑥𝑦+𝐶2(𝑥), so 𝑥𝑦+𝐶1(𝑦)=𝐶2(𝑥), which is impossible! What’s going on?

(It’s tempting to write 𝐶1(𝑦)=𝐶 and 𝐶2(𝑥)=𝑥𝑦+𝐶, but that’s a type error. These new functions 𝐶1 and 𝐶2 can only depend on their arguments. Indeed, look carefully at everything we wrote for 𝐶𝑖 previously: for example, whenever we wrote 𝐶1(𝑦) or 𝐶1(𝑦,𝑧), we never allow it to depend on 𝑥.)

In mathematics there’s a concept of proof by contradiction: if you start from an assumption, and then do some logic and reasoning to reach an impossible conclusion, then the starting assumption was wrong. Here, the starting assumption that there was some function 𝑓 such that ∇𝑓=(2𝑦𝑥). Starting from this assumption we found that there were functions 𝐶1(𝑦) and 𝐶2(𝑥) such that 𝐶2(𝑥)−𝐶1(𝑦)=𝑥𝑦 holds for all real numbers 𝑥 and 𝑦. So our assumption was wrong: there can’t be such function 𝑓. Not like 18.01 where “𝑓 exists but is hard to write down”; the function 𝑓 literally cannot exist.□

§16.5 [TEXT] Shortcut for weeding out impossible questions

Okay, so I bet you’re all wondering now, “how can I tell if the question is impossible?”.

Well, one strategy would just be to run the recipe I showed you and see if it works out.

But that’s a lot of work. We’d like a shortcut, and there is one.

The idea is that for functions (for which the partial derivatives are continuous), the partial derivatives commute. What that means, if say 𝑓(𝑥,𝑦) is a two-variable function, the following is true:

Memorize: partial derivatives commute

If 𝑓𝑥 and 𝑓𝑦 are both continuously differentiable then

𝑓𝑥𝑦=𝑓𝑦𝑥.

If you like 𝜕 notation better, this could also be written as

𝜕𝜕𝑦𝜕𝑓𝜕𝑥=𝜕𝜕𝑥𝜕𝑓𝜕𝑦.

In other words, if you try to differentiate with respect to 𝑥, then with respect to 𝑦, you get the same thing as 𝑦 first then 𝑥. Sometimes people write this as

𝜕2𝑓𝜕𝑥𝜕𝑦=𝜕2𝑓𝜕𝑦𝜕𝑥.

This result is at least a bit surprising, and I actually don’t expect you to believe me without seeing some examples. So let’s see some examples:

Example showing that the order of differentiation doesn’t matter

Let 𝑓(𝑥,𝑦)=𝑥7𝑦3.

  • If we differentiate with respect to 𝑥 then to 𝑦 we get 𝑓𝑥=7𝑥6𝑦3⟹(𝜕𝜕𝑦)𝑓𝑥=21𝑥6𝑦2.
  • Do it the other order: 𝑓𝑦=3𝑥7𝑦2⟹(𝜕𝜕𝑥)𝑓𝑦=21𝑥6𝑦2.
  • Either way we get the same result

    𝑓𝑥𝑦=𝑓𝑦𝑥=21𝑥6𝑦2.
Another example showing that the order of differentiation doesn’t matter

Let 𝑓(𝑥,𝑦)=cos(𝑥+𝑦)𝑦8.

  • Differentiate 𝑓 with respect to 𝑥 then to 𝑦:

    𝑓𝑥=−sin(𝑥+𝑦)𝑦8⟹𝜕𝜕𝑦𝑓𝑥=𝜕𝜕𝑦(−sin(𝑥+𝑦)𝑦8)=−cos(𝑥+𝑦)𝑦8−8𝑦7sin(𝑥+𝑦)
  • Do it the other order: Differentiate 𝑓 with respect to 𝑦 then to 𝑥:

    𝑓𝑦=(−sin(𝑥+𝑦)𝑦8+8𝑦7cos(𝑥+𝑦))⟹𝜕𝜕𝑥𝑓𝑦=𝜕𝜕𝑥(−sin(𝑥+𝑦)𝑦8+8𝑦7cos(𝑥+𝑦))=−cos(𝑥+𝑦)𝑦8−8𝑦7sin(𝑥+𝑦)
  • Either way, we get the same result:

    𝑓𝑥𝑦=𝑓𝑦𝑥=−cos(𝑥+𝑦)𝑦8−8𝑦7sin(𝑥+𝑦)

Okay, so how about the example we gave earlier?

Question

Determine whether or not there exists a differentiable function 𝑓(𝑥,𝑦) such that

∇𝑓=(2𝑦𝑥).

Well, if there was such an 𝑓, and we got a mismatch, then

𝑓𝑥𝑦=𝜕𝜕𝑦𝑓𝑥=𝜕𝜕𝑦(2𝑦)=2𝑓𝑦𝑥=𝜕𝜕𝑥𝑓𝑦=𝜕𝜕𝑥𝑥=1.

So via proof by contradiction, no such 𝑓 could exist.

§16.6 [RECIPE] Ruling out the existence of an anti-gradient

As it turns out, this test I described is good enough for 18.02 — it will catch all impossible questions. Specifically, the following theorem is true.

Memorize: Criteria for 2D anti-gradient to exist

Consider two functions (𝑝(𝑥,𝑦)𝑞(𝑥,𝑦)) defined on all of ℝ2, where 𝑝 and 𝑞 are continuously differentiable. Then there exists 𝑓 such that

∇𝑓=(𝑝(𝑥,𝑦)𝑞(𝑥,𝑦))

if and only if

𝜕𝑝𝜕𝑦=𝜕𝑞𝜕𝑥.

You should think of this as 𝑓𝑥𝑦=𝑓𝑦𝑥. We’ll see this again much later in Part India, but in different language: “the 2D scalar curl of 𝑓 is zero”.

The 3D version tests all the possible pairs:

Memorize: Criteria for 3D anti-gradient to exist

Consider three functions (𝑝(𝑥,𝑦,𝑧)𝑞(𝑥,𝑦,𝑧)𝑟(𝑥,𝑦,𝑧)) defined on all of ℝ3, where 𝑝, 𝑞, 𝑟 are continuously differentiable. Then there exists 𝑓 such that

∇𝑓=(𝑝(𝑥,𝑦,𝑧)𝑞(𝑥,𝑦,𝑧)𝑟(𝑥,𝑦,𝑧))

if and only if all three of the following equations hold:

𝜕𝑝𝜕𝑦=𝜕𝑞𝜕𝑥,𝜕𝑝𝜕𝑧=𝜕𝑟𝜕𝑥,𝜕𝑞𝜕𝑧=𝜕𝑟𝜕𝑦.

The above three equations should be remembered as 𝑓𝑥𝑦=𝑓𝑦𝑥, 𝑓𝑦𝑧=𝑓𝑧𝑦, 𝑓𝑧𝑦=𝑓𝑥𝑦. We’ll see this also in Part India again hidden in a different name: “the 3D scalar curl of 𝑓 is zero”. In that part, the given right-hand side will be called called a vector field and the function 𝑓 will be called a potential function for it. But ignore those names for now.

§16.7 [EXER] Exercises

Exercise 16.1. Suppose 𝑓(𝑥,𝑦) is a differentiable function and that

∇𝑓(𝑥,𝑦)=(𝑥2+𝑎𝑥𝑦+2𝑦2+𝑦+1𝑥2+𝑥+𝑏𝑥𝑦+𝑦2+2)

for some constants 𝑎 and 𝑏. Compute the constants 𝑎 and 𝑏, and determine 𝑓.