跳到正文

个人记录

重幂求导

__delta_epsilon__约 17 分钟
原文
文章信息与版本

文章信息

发布
2024年7月25日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 17 分钟
获赞
1

版本

  1. v1当前

注: 用 df(x)dxg(x)\frac{\mathrm{d}f(x)}{\mathrm{d}x}g(x) 表示 f(x)f(x) 对 xx 的导函数与 g(x)g(x) 的乘积。


求 dxx/dx\mathrm{d}x^x/\mathrm{d}x。

这玩意很典啊。设 y=xxy=x^x。

所以,

ln⁡y=ln⁡xx\ln y=\ln x^x

所以,

ln⁡y=xln⁡x\ln y=x\ln x

两边分别对 xx 求导,

dln⁡ydx=d(xln⁡x)dx\frac{\mathrm{d}\ln y}{\mathrm{d} x}=\frac{\mathrm{d}(x\ln x)}{\mathrm{d} x}

运用求导法则,

1ydydx=dxdxln⁡x+dln⁡xdxx=ln⁡x+1\frac{1}{y}\frac{\mathrm{d}y}{\mathrm{d}x}=\frac{\mathrm{d}x}{\mathrm{d}x}\ln x+\frac{\mathrm{d}\ln x}{\mathrm{d}x}x=\ln x+1

所以,

dxxdx=dydx=y(ln⁡x+1)=xx(ln⁡x+1)\frac{\mathrm{d}x^x}{\mathrm{d}x}=\frac{\mathrm{d}y}{\mathrm{d}x}=y(\ln x+1)=x^x(\ln x+1)

以上为背景。

好,我们现在要求 dxf(x)/dx\mathrm{d}x^{f(x)}/\mathrm{d}x。

类比前面可得,

dxf(x)dx=xf(x)(f′(x)ln⁡x+f(x)x)\frac{\mathrm{d}x^{f(x)}}{\mathrm{d}x}=x^{f(x)}\left(f'(x)\ln x+\frac{f(x)}{x}\right)

所以,难免不会有人没有不求 dxxx/dx\mathrm{d}x^{x^{x}}/\mathrm{d}x 的想法。

我们用 f(x)=xxf(x)=x^x 代入上式,正好我们刚求了 f′(x)f'(x) 的表达式。

所以说,套用结论可得,

dxxxdx=xxx(xx(ln⁡x+1)ln⁡x+xx−1)\frac{\mathrm{d} x^{x^{x}}}{\mathrm{d} x}=x^{x^{x}}\left(x^x(\ln x+1)\ln x+x^{x-1}\right)

这个式子不是很好看,但是还行吧。

由此,我们可以递推得到 d(nx)/dx\mathrm{d}(^nx)/\mathrm{d}x 的表达式。

这样,我们可以写代码了。

这段代码能帮我们计算 nx^n x 的表达式的 LaTeX\LaTeX。

C++
string f(int n) {
    if(n == 1) return "x";
    if(n == 2) return "x^x";
    return "x^{" + f(n - 1) + "}";
}

这段代码能够帮我们计算 d(nx)/dx\mathrm{d}(^n x)/\mathrm{d}x 的表达式的 LaTeX\LaTeX。

C++
string f_(int n) {
    if(n == 1) return "1";
    if(n == 2) return "x^x(\\ln x+1)";
    return f(n) + "\\left(" + f_(n - 1) + "\\ln x+x^{" + f(n - 2) + "-1}\\right)";
}

由此,我们有了如下结论:

dxxxxdx=xxxx(xxx(xx(ln⁡x+1)ln⁡x+xx−1)ln⁡x+xxx−1)\frac{\mathrm{d}x^{x^{x^x}}}{\mathrm{d} x}=x^{x^{x^x}}\left(x^{x^x}\left(x^x(\ln x+1)\ln x+x^{x-1}\right)\ln x+x^{x^x-1}\right) dxxxxxdx=xxxxx(xxxx(xxx(xx(ln⁡x+1)ln⁡x+xx−1)ln⁡x+xxx−1)ln⁡x+xxxx−1)\frac{\mathrm{d}x^{x^{x^{x^x}}}}{\mathrm{d}x}=x^{x^{x^{x^x}}}\left(x^{x^{x^x}}\left(x^{x^x}\left(x^x(\ln x+1)\ln x+x^{x-1}\right)\ln x+x^{x^x-1}\right)\ln x+x^{x^{x^x}-1}\right)

以及,重幂求导法则,

d(nx)dx=nx(n−1x(n−2x(⋯(xx(ln⁡x+1)ln⁡x+xx−1)⋯ )ln⁡x+n−2xx)ln⁡x+n−1xx)\frac{\mathrm{d}(^n x)}{\mathrm{d}x}={}^n x\left(^{n-1}x\left(^{n-2}x\left(\cdots\left(x^x\left(\ln x+1\right)\ln x+x^{x-1}\right)\cdots\right)\ln x+\frac{^{n-2}x}{x}\right)\ln x+\frac{^{n-1}x}{x}\right)

我们要推广这个东西,有三条路可以走。

  1. 求 d(nf(x))/dx\mathrm{d}(^nf(x))/\mathrm{d}x。
  2. 求 dk(nx)/dxk\mathrm{d}^k(^nx)/\mathrm{d}x^k。
  3. 求 d(x↑↑↑n)/dx\mathrm{d}(x\uparrow\uparrow\uparrow n)/\mathrm{d}x。

推广 1 只需要在重幂求导法则外面套一个链式求导法则就好了。也就是说,

d(nf(x))dx=d(nf(x))df(x)⋅df(x)dx\frac{\mathrm{d}(^nf(x))}{\mathrm{d}x}=\frac{\mathrm{d}(^nf(x))}{\mathrm{d}f(x)}\cdot\frac{\mathrm{d}f(x)}{\mathrm{d}x}

主要研究推广 2 和推广 3。


推广 2,求 nn 重幂的 kk 阶导数。

首先我们看 xxx^x 的 kk 阶导数。

dxxdx=xx(ln⁡x+1)\frac{\mathrm{d}x^x}{\mathrm{d}x}=x^x(\ln x+1)

用乘法法则得到,

d2xxdx2=dxxdx(ln⁡x+1)+d(ln⁡x+1)dxxx=xx(ln⁡x+1)2+xx−1\frac{\mathrm{d}^2x^x}{\mathrm{d}x^2}=\frac{\mathrm{d}x^x}{\mathrm{d}x}(\ln x+1)+\frac{\mathrm{d}(\ln x+1)}{\mathrm{d}x}x^x=x^x(\ln x+1)^2+x^{x-1}

继续求导,

d3xxdx3=dxxdx(ln⁡x+1)2+d(ln⁡x+1)2dxxx+dxx−1dx=xx(ln⁡x+1)3+2xx−1(ln⁡x+1)+xx−1(ln⁡x+x−1x)=xx(ln⁡x+1)3+3xx−1(ln⁡x+1)−xx−2\begin{aligned}\frac{\mathrm{d}^3x^x}{\mathrm{d}x^3}&=\frac{\mathrm{d}x^x}{\mathrm{d}x}(\ln x+1)^2+\frac{\mathrm{d}(\ln x+1)^2}{\mathrm{d}x}x^x+\frac{\mathrm{d}x^{x-1}}{\mathrm{d}x}\\&=x^x(\ln x+1)^3+2x^{x-1}(\ln x+1)+x^{x-1}\left(\ln x+\frac{x-1}{x}\right)\\&=x^x(\ln x+1)^3+3x^{x-1}(\ln x+1)-x^{x-2}\end{aligned}

继续求导,

d4xxdx4=dxxdx(ln⁡x+1)3+d(ln⁡x+1)3dxxx+3(dxx−1dx(ln⁡x+1)+d(ln⁡x+1)dxxx−1)−dxx−2dx=xx(ln⁡x+1)4+3xx−1(ln⁡x+1)2+3(xx−1(ln⁡x+x−1x)(ln⁡x+1)+xx−2)−xx−2(ln⁡x+x−2x)=xx(ln⁡x+1)4+6xx−1(ln⁡x+1)2−4xx−2(ln⁡x+1)+3xx−2+2xx−3\begin{aligned}\frac{\mathrm{d}^4x^x}{\mathrm{d}x^4}&=\frac{\mathrm{d}x^x}{\mathrm{d}x}\left(\ln x + 1\right)^{3} + \frac{\mathrm{d}\left(\ln x + 1\right)^{3}}{\mathrm{d}x}x^{x}+3\left(\frac{\mathrm{d}x^{x-1}}{\mathrm{d}x}(\ln x+1)+\frac{\mathrm{d}(\ln x+1)}{\mathrm{d}x}x^{x-1}\right)-\frac{\mathrm{d}x^{x-2}}{\mathrm{d}x}\\&= x^{x} \left(\ln x + 1\right)^{4} + 3x^{x - 1} \left(\ln x + 1\right)^{2}+3\left(x^{x-1}\left(\ln x+\frac{x-1}{x}\right)(\ln x+1)+x^{x-2}\right)-x^{x-2}\left(\ln x+\frac{x-2}{x}\right)\\&=x^x(\ln x+1)^4+6x^{x-1}(\ln x+1)^2-4x^{x-2}(\ln x+1)+3x^{x-2}+2x^{x-3}\end{aligned}

经过仔细观察之后发现没有什么明显的规律。我们观察这里的每一项,都可以写成 kxx−i(ln⁡x+1)jkx^{x-i}(\ln x+1)^j 的形式。

我们对这个式子求导,

dxx−i(ln⁡x+1)jdx=dxx−idx(ln⁡x+1)j+d(ln⁡x+1)jdxxx−i=xx−i(ln⁡x+x−ix)(ln⁡x+1)j+j(ln⁡x+1)j−1xx−i−1=xx−i(ln⁡x+1)j+1−ixx−i−1(ln⁡x+1)j+jxx−i−1(ln⁡x+1)j−1\begin{aligned}\frac{\mathrm{d}x^{x-i}(\ln x+1)^j}{\mathrm{d}x}&=\frac{\mathrm{d}x^{x-i}}{\mathrm{d}x}(\ln x+1)^j+\frac{\mathrm{d}(\ln x+1)^j}{\mathrm{d}x}x^{x-i}\\&=x^{x-i}\left(\ln x+\frac{x-i}{x}\right)(\ln x+1)^j+j(\ln x+1)^{j-1}x^{x-i-1}\\&=x^{x-i}(\ln x+1)^{j+1}-ix^{x-i-1}(\ln x+1)^j+jx^{x-i-1}(\ln x+1)^{j-1}\end{aligned}

令 F(i,j)=xx−i(ln⁡x+1)j\mathcal{F}(i,j)=x^{x-i}(\ln x+1)^j,则可以简写成,

dF(i,j)dx=F(i,j+1)−iF(i+1,j)+jF(i+1,j−1)(*)\frac{\mathrm{d}\mathcal{F}(i,j)}{\mathrm{d}x}=\mathcal{F}(i,j+1)-i\mathcal{F}(i+1,j)+j\mathcal{F}(i+1,j-1)\tag{*}

所以,不难写出求解 xxx^x 的 kk 阶导数的 LaTeX\LaTeX 的程序。

我们先定义一个结构体 Term,

C++
struct Term {
	int k, i, j;
	string str() {
		return (k < 0 ? '-' : '+')
		     + (abs(k) == 1 ? "" : to_string(abs(k)))
		     + "x^{x" + (i == 0 ? "" : to_string(-i)) + "}"
		     + (j == 0 ? "" : "(\\ln x+1)") + (j <= 1 ? "" : "^{" + to_string(j) + "}");
	}
}; 

其成员函数 str() 是格式化输出函数。

接着实现求导部分:

C++
vector<Term> calcDeri(vector<Term> v) {
	map<pair<int, int>, int> mp;
	vector<Term> ret;
	for(auto iter : v) {
		mp[{iter.i, iter.j + 1}] += iter.k;
		mp[{iter.i + 1, iter.j}] -= iter.i * iter.k;
		mp[{iter.i + 1, iter.j - 1}] += iter.j * iter.k;
	}
	for(auto iter : mp) {
		if(!iter.second) continue;
		ret.push_back({(iter.second), (iter.first).first, (iter.first).second});
	}
	return ret;
}

用 map 实现各项系数的相加,用 vector<Term> 表示一个代数式。

调用,

代码
terms = calcDeri(terms);

就可以完成一次求导操作。

不管如何,我们借此求出了 xxx^x 的 5,65,6 阶导数。

d5xxdx5=xx(ln⁡x+1)5+10xx−1(ln⁡x+1)3+15xx−2(ln⁡x+1)−10xx−2(ln⁡x+1)2−10xx−3+10xx−3(ln⁡x+1)−6xx−4\frac{\mathrm{d}^5 x^x}{\mathrm{d}x^5}=x^{x}(\ln x+1)^{5}+10x^{x-1}(\ln x+1)^{3}+15x^{x-2}(\ln x+1)-10x^{x-2}(\ln x+1)^{2}-10x^{x-3}+10x^{x-3}(\ln x+1)-6x^{x-4} d6xxdx6=xx(ln⁡x+1)6+15xx−1(ln⁡x+1)4+45xx−2(ln⁡x+1)2−20xx−2(ln⁡x+1)3+15xx−3−60xx−3(ln⁡x+1)+30xx−3(ln⁡x+1)2+40xx−4−36xx−4(ln⁡x+1)+24xx−5\frac{\mathrm{d}^6 x^x}{\mathrm{d}x^6}=x^{x}(\ln x+1)^{6}+15x^{x-1}(\ln x+1)^{4}+45x^{x-2}(\ln x+1)^{2}-20x^{x-2}(\ln x+1)^{3}+15x^{x-3}-60x^{x-3}(\ln x+1)+30x^{x-3}(\ln x+1)^{2}+40x^{x-4}-36x^{x-4}(\ln x+1)+24x^{x-5}

那么 dnxx/dxn\mathrm{d}^nx^x/\mathrm{d}x^n 有没有什么通项公式呢?

我们考察 dnxx/dxn\mathrm{d}^nx^x/\mathrm{d}x^n 中 F(i,j)\mathcal{F}(i,j) 的系数,记作 Kn(i,j)\mathcal{K}_n(i,j)。它是由什么递推而来的呢?

由 (∗)(*) 式可得,

Kn(i,j)=Kn−1(i,j−1)−(i−1)Kn−1(i−1,j)+(j+1)Kn−1(i−1,j+1)\mathcal{K}_n(i,j)=\mathcal{K}_{n-1}(i,j-1)-(i-1)\mathcal{K}_{n-1}(i-1,j)+(j+1)\mathcal{K}_{n-1}(i-1,j+1)

初始值为 K0(0,0)=1,K0(i,j)=0,(i,j≠0)\mathcal{K}_0(0,0)=1,\mathcal{K}_0(i,j)=0,(i,j\neq0)。

这玩意当 dp 写也挺好的。


但这只是 xxx^x 的 kk 阶导数的求法。我们还需要求出 dk(nx)/dxk\mathrm{d}^k({}^nx)/\mathrm{d}x^k。

如果要效仿之前的做法,我们必须找到 dk(nx)/dxk\mathrm{d}^k({}^nx)/\mathrm{d}x^k 每一项的通式。

但这似乎计算量非常的大。有没有别的方法呢?

我们回到这个式子,

dxf(x)dx=xf(x)(f′(x)ln⁡x+f(x)x)\frac{\mathrm{d}x^{f(x)}}{\mathrm{d}x}=x^{f(x)}\left(f'(x)\ln x+\frac{f(x)}{x}\right)

我们直接对这个式子求导,再把 f(x)=n−1xf(x)={}^{n-1}x 代入,不就能求出 nx^nx 的二阶导了吗?

说的道理。

d2xf(x)dx2=dxf(x)dx(f′(x)ln⁡x+f(x)x)+d(f′(x)ln⁡x+f(x)x)dxxf(x)=xf(x)(f′(x)ln⁡x+f(x)x)2+xf(x)(df′(x)ln⁡xdx+df(x)xdx)=xf(x)(f′(x)ln⁡x+f(x)x)2+xf(x)(f′′(x)ln⁡x+2f′(x)x−f(x)x2)\def\deri#1{\frac{\mathrm{d}#1}{\mathrm{d}x}} \begin{aligned}\frac{\mathrm{d}^2x^{f(x)}}{\mathrm{d}x^2}&=\deri{x^{f(x)}}\left(f'(x)\ln x+\frac{f(x)}{x}\right)+\deri{\left(f'(x)\ln x+\frac{f(x)}{x}\right)}x^{f(x)}\\&=x^{f(x)}\left(f'(x)\ln x+\frac{f(x)}{x}\right)^2+x^{f(x)}\left(\deri{f'(x)\ln x}+\deri{\frac{f(x)}x}\right)\\&=x^{f(x)}\left(f'(x)\ln x+\frac{f(x)}{x}\right)^2+x^{f(x)}\left(f''(x)\ln x+\frac{2f'(x)}{x}-\frac{f(x)}{x^2}\right)\end{aligned}

然后,你就会惊奇的发现,nx^nx 的二阶导是可以由 n−1x^{n-1}x 的一阶导和二阶导推导而来的。

也就是说,这是一个递归的过程。我们可以写代码来硬算!

C++
string f(int n, int k) {
	if(k == 0) {
		if(n == 2) return "x^x";
		return "x^{" + f(n - 1, 0) + "}";
	}
	else {
		if(n == 2) return "x^{x-" + to_string(k) + "}";
		return "x^{" + f(n - 1, 0) + "-" + to_string(k) + "}";
	}
}

string fD(int n, int k) {
	if(k == 0) {
		if(n == 2) return "x^x(\\ln x+1)";
	}
	else {
		if(n == 2) return "x^{x-" + to_string(k) + "}(\\ln x+1)";
	}
	return f(n, k) + "\\left(" + fD(n - 1, 0) + "\\ln x+" + f(n - 1, 1) + "\\right)";
}

string fDD(int n) {
	if(n == 2)
		return "x^x(\\ln x+1)^2+x^{x-1}";
	return f(n, 0) + "\\left(" + fD(n - 1, 0) + "\\ln x+" + f(n - 1, 1) + "\\right)^2+"
	     + f(n, 0) + "\\left(\\left(" + fDD(n - 1) + "\\right)\\ln x+2" + fD(n - 1, 1) + "-" + f(n - 1, 2) + "\\right)";
}

我们用 f(n,k){\rm f}(n, k),fD(n,k){\rm fD}(n, k),fDD(n){\rm fDD}(n) 三个函数分别表示 nx/xk^nx/x^k,d(nx)/dx⋅1/xk\mathrm{d}(^nx)/\mathrm{d}x\cdot1/x^k 和 d2(nx)/dx2\mathrm{d}^2(^nx)/\mathrm{d}x^2。

调用 fDD(n){\rm fDD}(n) 即可得到想要的结果。由此可得,

d2xxxdx2=xxx(xx(ln⁡x+1)ln⁡x+xx−1)2+xxx((xx(ln⁡x+1)2+xx−1)ln⁡x+2xx−1(ln⁡x+1)−xx−2)\frac{\mathrm{d}^2x^{x^x}}{\mathrm{d}x^2}=x^{x^x}\left(x^x(\ln x+1)\ln x+x^{x-1}\right)^2+x^{x^x}\left(\left(x^x(\ln x+1)^2+x^{x-1}\right)\ln x+2x^{x-1}(\ln x+1)-x^{x-2}\right) d2xxxxdx2=xxxx(xxx(xx(ln⁡x+1)ln⁡x+xx−1)ln⁡x+xxx−1)2+xxxx((xxx(xx(ln⁡x+1)ln⁡x+xx−1)2+xxx((xx(ln⁡x+1)2+xx−1)ln⁡x+2xx−1(ln⁡x+1)−xx−2))ln⁡x+2xxx−1(xx(ln⁡x+1)ln⁡x+xx−1)−xxx−2)\frac{\mathrm{d}^2x^{x^{x^x}}}{\mathrm{d}x^2}=x^{x^{x^x}}\left(x^{x^x}\left(x^x(\ln x+1)\ln x+x^{x-1}\right)\ln x+x^{x^x-1}\right)^2+x^{x^{x^x}}\left(\left(x^{x^x}\left(x^x(\ln x+1)\ln x+x^{x-1}\right)^2+x^{x^x}\left(\left(x^x(\ln x+1)^2+x^{x-1}\right)\ln x+2x^{x-1}(\ln x+1)-x^{x-2}\right)\right)\ln x+2x^{x^x-1}\left(x^x(\ln x+1)\ln x+x^{x-1}\right)-x^{x^x-2}\right)

而 xxxxxx^{x^{x^{x^x}}} 的二阶导的 LaTeX\LaTeX 已经有 604604 个字符长了。

归纳可得通项公式。但是我懒得写。


然而我们只解决了 dk(nx)/dxk\mathrm{d}^k(^nx)/\mathrm{d}x^k 在 n=2n=2 和 k=2k=2 时的情况。

也就是说,我们仍然需要求一个算法来解决这类问题。一种简单的想法是写出一个可以用于求解任意问题的导数计算器。

另一种想法是求出 dk(xf(x))/dxk\mathrm{d}^k(x^{f(x)})/\mathrm{d}x^k 的通项或递推。

但用现成的导数计算器求出来就是一坨答辩一样的式子。

目前没有想到较好的解法,遂咕之。

原文
存档评论1 条抓取于