Skip to main content

Exercise 9.2

Introduction​

まずは、Codeをおさらいしておく。

// Original smin
float smin(float a, float b, float k){
float h = clamp(0.5 - 0.5 * (b - a) / k, 0.0, 1.0);
return mix(a, b, h) - k * h * (1.0 - h);
}

// Exercise functions below
float smax(float a, float b, float k){
float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
return mix(a, b, h) + k * h * (1.0 - h);
}

float smin2(float a, float b, float k){
float h = max( k - abs(a - b), 0.0 )/k;
return min(a, b) - h * h * k * (1.0 / 4.0);
}

float sminCubic(float a, float b, float k){
float h = max( k - abs(a - b), 0.0 )/k;
return min(a, b) - h * h * h * k * (1.0 / 6.0);
}

これらの関数について、グラフの描画と微分可能性の証明を行う

Graphs​

Original smin() for reference​

Graph in Desmos
original smin graph

smax()​

Graph in Desmos
smax graph

smin2()​

Graph in Desmos
smin2 graph

sminCubic()​

Graph in Desmos
sminCubic graph

Proofs​

smax()​

準備​

smax関数の定義を確認すると、P.129-130で議論された h(x),f(x),g(x)h(x),f(x),g(x) として

h(x)=clamp(0.5+b(x)−a(x)2k,0,1)f(x)=mix(a(x),b(x),h(x))g(x)=f(x)+kh(x)(1−h(x))\begin{aligned} h(x) &= \text{clamp}(0.5 + \frac{b(x) - a(x)}{2k}, 0, 1) \\ f(x) &= \text{mix}(a(x), b(x), h(x)) \\ g(x) &= f(x) + kh(x)(1 - h(x)) \end{aligned}

のように取ったものと言えるので、smaxについてもsminの場合の証明であるEx9.1の時と同様に g(x)g(x) の微分可能性として確認できる。具体的には、やはり同様に正の定数 kk を設定したとして、 ∣b(x)−a(x)∣=k|b(x) - a(x)| = k となるグラフの継ぎ目以外では微分可能性は自明なので、この継ぎ目付近の微分可能性のみを確認する。 なお、継ぎ目については x0x_0 は b(x0)−a(x0)=k i.e h(x0)=1b(x_0) - a(x_0) = k \text{ i.e } h(x_0) = 1 を、x1x_1 は a(x1)−b(x1)=k i.e h(x1)=0a(x_1) - b(x_1) = k \text{ i.e } h(x_1) = 0 を満たすものとしてそれぞれとることにする。

まずは x=x0,x1x = x_0, x_1 での h(x)h(x) の各微分係数をテキスト同様に計算すると、

lim⁡x→x0−0h′(x)=0lim⁡x→x0+0h′(x)=b′(x0)−a′(x0)2kh(x0)=1lim⁡x→x1−0h′(x)=b′(x1)−a′(x1)2klim⁡x→x1+0h′(x)=0h(x1)=0(ex9.2.1)\tag{ex9.2.1} \begin{aligned} \lim_{x \to x_0-0}h'(x) &= 0 \\ \lim_{x \to x_0+0}h'(x) &= \frac{b'(x_0) - a'(x_0)}{2k} \\ h(x_0) &= 1 \\ \lim_{x \to x_1-0}h'(x) &= \frac{b'(x_1) - a'(x_1)}{2k} \\ \lim_{x \to x_1+0}h'(x) &= 0 \\ h(x_1) &= 0 \end{aligned}

らを得る。

また、この結果と f(x)f(x) の定義、およびテキストP.130に記載された f′(x)f'(x)

f′(x)=a′(x)+h(x)(b′(x)−a′(x))+h′(x)(b(x)−a(x))f'(x) = a'(x) + h(x)(b'(x) - a'(x)) + h'(x)(b(x)-a(x))

を使うと、

lim⁡x→x0−0f′(x)=b′(x0)lim⁡x→x0+0f′(x)=b′(x0)+b′(x0)−a′(x0)2lim⁡x→x1−0f′(x)=a′(x1)−b′(x1)−a′(x1)2lim⁡x→x1+0f′(x)=a′(x1)(ex9.2.2)\tag{ex9.2.2} \begin{aligned} \lim_{x \to x_0-0}f'(x) &= b'(x_0) \\ \lim_{x \to x_0+0}f'(x) &= b'(x_0) + \frac{b'(x_0) - a'(x_0)}{2} \\ \lim_{x \to x_1-0}f'(x) &= a'(x_1) - \frac{b'(x_1) - a'(x_1)}{2} \\ \lim_{x \to x_1+0}f'(x) &= a'(x_1) \end{aligned}

らを得ることができる。

x=x0x=x_0 での微分可能性​

さて、以後の計算のため、 g(x)g(x) の導関数を計算すると

g′(x)=f′(x)+kh′(x)(1−h(x))+kh(x)(−h′(x))=f′(x)+kh′(x)−kh′(x)h(x)‾−kh(x)h′(x)‾=f′(x)+kh′(x)−2kh′(x)h(x)\begin{aligned} g'(x) &= f'(x) + kh'(x)(1-h(x)) + k h(x)(-h'(x)) \\ &= f'(x) + kh'(x) - \underline{kh'(x)h(x)} - \underline{kh(x)h'(x)} \\ &= f'(x) + kh'(x) - 2kh'(x)h(x) \end{aligned}

を得る。 h(x)→x→x01h(x) \xrightarrow{x \to x_0} 1 なので、 x0x_0 での微分係数を求める際は f′(x)−kh′(x)f'(x) - kh'(x) のみを計算すれば良い。

さて、(ex9.2.2)式より lim⁡x→x0−0f′(x)=b′(x0)\lim_{x \to x_0-0}f'(x) = b'(x_0) であり、さらに(ex9.2.1)式より h(x)h(x) の左微分係数が 00 であることから、 g(x)g(x) の左微分係数は以下の様に容易に導かれる。

lim⁡x→x0−0g′(x)=lim⁡x→x0−0f′(x)−lim⁡x→x0−0kh′(x)=b′(x0)−0=b′(x0)\lim_{x \to x_0-0}g'(x) = \lim_{x \to x_0-0}f'(x) - \lim_{x \to x_0-0}kh'(x) = b'(x_0) - 0 = b'(x_0)

次に、(ex9.2.2)式より、lim⁡x→x0+0f′(x)=b′(x0)+b′(x0)−a′(x0)2\lim_{x \to x_0+0}f'(x) = b'(x_0) + \frac{b'(x_0) - a'(x_0)}{2} であり、さらに(ex9.2.1)式より h(x)h(x) の右微分係数が b′(x0)−a′(x0)2k\frac{b'(x_0) - a'(x_0)}{2k} であることから、 g(x)g(x) の右微分係数も以下の様に求められる。

lim⁡x→x0+0g′(x)=lim⁡x→x0+0f′(x)−lim⁡x→x0+0kh′(x)=b′(x0)+b′(x0)−a′(x0)2−kb′(x0)−a′(x0)2k=b′(x0)+b′(x0)−a′(x0)2−b′(x0)−a′(x0)2=b′(x0)\begin{aligned} \lim_{x \to x_0+0}g'(x) &= \lim_{x \to x_0+0}f'(x) - \lim_{x \to x_0+0}kh'(x) \\ &= b'(x_0) + \frac{b'(x_0) - a'(x_0)}{2} - k\frac{b'(x_0) - a'(x_0)}{2k} \\ &= b'(x_0) + \frac{b'(x_0) - a'(x_0)}{2} - \frac{b'(x_0) - a'(x_0)}{2} \\ &= b'(x_0) \end{aligned}

上記より x=x0x = x_0 で、左微分係数と右微分係数が等しいので、微分可能であることがわかった。

x=x1x=x_1 での微分可能性​

x=x0x=x_0の時と同様に、

g′(x)=f′(x)+kh′(x)−2kh′(x)h(x)g'(x) = f'(x) + kh'(x) - 2kh'(x)h(x)

であり、h(x)→x→x10h(x) \xrightarrow{x \to x_1} 0 なので、 x1x_1 での微分係数を求める際は f′(x)+kh′(x)f'(x) + kh'(x) のみを計算すれば良い。

さて、(ex9.2.2)式より、 lim⁡x→x1−0f′(x)=a′(x1)−b′(x1)−a′(x1)2\lim_{x \to x_1-0}f'(x) = a'(x_1) - \frac{b'(x_1) - a'(x_1)}{2} であり、さらに(ex9.2.1)式より、 h(x)h(x) の左微分係数が b′(x1)−a′(x1)2k\frac{b'(x_1) - a'(x_1)}{2k} であることから、 g(x)g(x) の左微分係数は以下の様に計算できる。

lim⁡x→x1−0g′(x)=lim⁡x→x1−0f′(x)+lim⁡x→x1−0kh′(x)=a′(x1)−b′(x1)−a′(x1)2+kb′(x1)−a′(x1)2k=a′(x1)\begin{aligned} \lim_{x \to x_1-0}g'(x) &= \lim_{x \to x_1-0}f'(x) + \lim_{x \to x_1-0}kh'(x) \\ &= a'(x_1) - \frac{b'(x_1) - a'(x_1)}{2} + k\frac{b'(x_1) - a'(x_1)}{2k} \\ &= a'(x_1) \end{aligned}

次に、(ex9.2.2)式より、lim⁡x→x1+0f′(x)=a′(x1)\lim_{x \to x_1+0}f'(x) = a'(x_1) であり、さらに(ex9.2.1)式より、h(x)h(x) の右微分係数が 00 であるので、これらの事実より g(x)g(x) の右微分係数も以下の様に求められる。

lim⁡x→x1+0g′(x)=lim⁡x→x1+0f′(x)+lim⁡x→x1+0kh′(x)=a′(x1)\begin{aligned} \lim_{x \to x_1+0}g'(x) &= \lim_{x \to x_1+0}f'(x) + \lim_{x \to x_1+0}kh'(x) \\ &= a'(x_1) \end{aligned}

上記より x=x1x = x_1 で、左微分係数と右微分係数が等しいので、微分可能であることがわかった。

smin2()​

smin2関数を数学的な表現で書き直すと

h(x)={0k≤∣a(x)−b(x)∣1−∣a(x)−b(x)∣/kk>∣a(x)−b(x)∣h(x) = \left\{ \begin{array}{ll} 0 & k \leq |a(x) - b(x)| \\ 1 - |a(x) - b(x)|/k & k > |a(x) - b(x)| \end{array} \right.
f(x)={a(x)−h(x)h(x)k/4a(x)≤b(x)b(x)−h(x)h(x)k/4a(x)>b(x)f(x) = \left\{ \begin{array}{ll} a(x) - h(x)h(x)k/4 & a(x) \leq b(x) \\ b(x) - h(x)h(x)k/4 & a(x) > b(x) \end{array} \right.

となる。 a(x),b(x)a(x), b(x) は微分可能な関数であるので、 f(x)f(x) の微分可能性を確認するにあたり、上記条件分岐点の微分可能性を調べれば十分である。 今回、自明ではない分岐点の xx の値として、 k=∣a(x0)−b(x0)∣k = |a(x_0) - b(x_0)| を満たす x0x_0 ( h(x)h(x) の分岐点)と、a(x1)=b(x1)a(x_1) = b(x_1) を満たす x1x_1 ( f(x)f(x) の分岐点) の2つを取る。

また、以後の計算のために、 f(x)f(x) の微分 f′(x)f'(x) を計算しておく。その定義より

f′(x)={a′(x)−2h′(x)h(x)k/4=a′(x)−h′(x)h(x)k/2a(x)≤b(x)b′(x)−2h′(x)h(x)k/4=b′(x)−h′(x)h(x)k/2a(x)>b(x)f'(x) = \left\{ \begin{array}{ll} a'(x) - 2h'(x)h(x)k/4 = a'(x) - h'(x)h(x)k/2 & a(x) \leq b(x) \\ b'(x) - 2h'(x)h(x)k/4 = b'(x) - h'(x)h(x)k/2 & a(x) > b(x) \end{array} \right.

x=x0x=x_0 での微分可能性​

f(x)f(x) の x=x0x=x_0 での左微分係数について、h(x)→x→x0−00h(x) \xrightarrow{x \to x_0-0} 0に注意して計算すると、

lim⁡x→x0−0f′(x)=min(a′(x0),b′(x0))−lim⁡x→x0−0h′(x)h(x)k/2=min(a′(x0),b′(x0))\lim_{x \to x_0-0}f'(x) = \text{min}(a'(x_0),b'(x_0)) - \lim_{x \to x_0-0}h'(x)h(x)k/2 = \text{min}(a'(x_0),b'(x_0))

であることがわかる。次に、右微分係数についても、やはり、h(x)→x→x0+00h(x) \xrightarrow{x \to x_0+0} 0 であるので、同じく

lim⁡x→x0+0f′(x)=min(a′(x0),b′(x0))−lim⁡x→x0+0h′(x)h(x)k/2=min(a′(x0),b′(x0))\lim_{x \to x_0+0}f'(x) = \text{min}(a'(x_0),b'(x_0)) - \lim_{x \to x_0+0}h'(x)h(x)k/2 = \text{min}(a'(x_0),b'(x_0))

となり、左右の微分係数が等しくなるので、 x=x0x=x_0 での微分可能性は確認できた。

x=x1x=x_1 での微分可能性​

まずは、 h(x)h(x) の x=x1x=x_1 点での微分係数を求めておきたい。なお、ここでは、 x1x_1 の左側で a(x)>b(x)a(x)>b(x) 、 x1x_1 の右側で a(x)<b(x)a(x)<b(x) となると仮定する。すると、下記の様に左右の微分係数を得る。

lim⁡x→x1−0h′(x)=−a′(x)/k+b′(x)/klim⁡x→x1+0h′(x)=a′(x)/k−b′(x)/k\begin{aligned} \lim_{x \to x_1-0}h'(x) &= - a'(x)/k + b'(x)/k \\ \lim_{x \to x_1+0}h'(x) &= a'(x)/k - b'(x)/k \end{aligned}

f(x)f(x) の x=x1x=x_1 左微分係数については、 a(x1)−b(x1)=0a(x_1) - b(x_1) = 0 が h(x)→x→x11h(x) \xrightarrow{x \to x_1} 1 を導くことに注意して計算する。 上記前提のもと、左微分係数は、

lim⁡x→x1−0f′(x)=b′(x1)−lim⁡x→x1−0h′(x)h(x)k/2=b′(x1)−lim⁡x→x1−0h′(x)k/2=b′(x1)−(−a′(x1)/k+b′(x1)/k)k/2=b′(x1)+(a′(x1)−b′(x1))/2=(a′(x1)+b′(x1))/2\begin{aligned} \lim_{x \to x_1-0}f'(x) &= b'(x_1) - \lim_{x \to x_1-0}h'(x)h(x)k/2 \\ &= b'(x_1) - \lim_{x \to x_1-0}h'(x)k/2 \\ &= b'(x_1) - (- a'(x_1)/k + b'(x_1)/k)k/2 \\ &= b'(x_1) + (a'(x_1) - b'(x_1))/2 \\ &= (a'(x_1) + b'(x_1))/2 \end{aligned}

となり、また、右微分係数も

lim⁡x→x1+0f′(x)=a′(x1)−lim⁡x→x1+0h′(x)h(x)k/2=a′(x1)−lim⁡x→x1+0h′(x)k/2=a′(x1)−(a′(x1)/k−b′(x1)/k)k/2=a′(x1)+(−a′(x1)+b′(x1))/2=(a′(x1)+b′(x1))/2\begin{aligned} \lim_{x \to x_1+0}f'(x) &= a'(x_1) - \lim_{x \to x_1+0}h'(x)h(x)k/2 \\ &= a'(x_1) - \lim_{x \to x_1+0}h'(x)k/2 \\ &= a'(x_1) - (a'(x_1)/k - b'(x_1)/k)k/2 \\ &= a'(x_1) + (-a'(x_1) + b'(x_1))/2 \\ &= (a'(x_1) + b'(x_1))/2 \end{aligned}

となる。

上記より x=x1x = x_1 で、左微分係数と右微分係数が等しいので、微分可能であることがわかった。

以上より、全ての点で微分可能であることが確かめられた。

sminCubic()​

sminCubicについては、h(x)が共通なので、smin2と同様に証明が可能である。 f(x)は

f(x)={a(x)−h(x)h(x)h(x)k/6a(x)≤b(x)b(x)−h(x)h(x)h(x)k/6a(x)>b(x)f(x) = \left\{ \begin{array}{ll} a(x) - h(x)h(x)h(x)k/6 & a(x) \leq b(x) \\ b(x) - h(x)h(x)h(x)k/6 & a(x) > b(x) \end{array} \right.

となり、その微分 f′(x)f'(x) が

f′(x)={a′(x)−3h′(x)h(x)h(x)k/6=a′(x)−h′(x)h(x)h(x)k/2a(x)≤b(x)b′(x)−3h′(x)h(x)h(x)k/6=b′(x)−h′(x)h(x)h(x)k/2a(x)>b(x)f'(x) = \left\{ \begin{array}{ll} a'(x) - 3h'(x)h(x)h(x)k/6 = a'(x) - h'(x)h(x)h(x)k/2 & a(x) \leq b(x) \\ b'(x) - 3h'(x)h(x)h(x)k/6 = b'(x) - h'(x)h(x)h(x)k/2 & a(x) > b(x) \end{array} \right.

となるので、smin2時に証明した x=x0x=x_0, x=x1x=x_1 での微分可能性の確認方法がそのまま適用できる。