goo blog サービス終了のお知らせ 

CyberChaos(さいばかおす)

プログラミング言語、トランスパイラ、RPA、ChatGPT、データマイニング、リバースエンジニアリングのための忘備録

負の数の階乗を求めることは可能か?

2025-01-11 13:00:24 | 日記














負の数の階乗は、通常の整数の階乗のように直接計算することはできません。しかし、階乗を拡張したガンマ関数を用いることで、負の数の階乗を一般化できます。


1. 階乗の定義とガンマ関数

階乗は自然数 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi></mrow><annotation encoding="application/x-tex">n</annotation></semantics></math> に対して次のように定義されます:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>n</mi><mo stretchy="false">!</mo><mo>=</mo><mi>n</mi><mo>×</mo><mo stretchy="false">(</mo><mi>n</mi><mo>−</mo><mn>1</mn><mo stretchy="false">)</mo><mo>×</mo><mo>…</mo><mo>×</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">n! = n \times (n-1) \times \ldots \times 1</annotation></semantics></math>

これを一般化したガンマ関数 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">Γ</mi><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\Gamma(z)</annotation></semantics></math> は、複素数領域で以下の積分によって定義されます:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi mathvariant="normal">Γ</mi><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo><mo>=</mo><msubsup><mo>∫</mo><mn>0</mn><mi mathvariant="normal">∞</mi></msubsup><msup><mi>t</mi><mrow><mi>z</mi><mo>−</mo><mn>1</mn></mrow></msup><msup><mi>e</mi><mrow><mo>−</mo><mi>t</mi></mrow></msup><mtext> </mtext><mi>d</mi><mi>t</mi></mrow><annotation encoding="application/x-tex">\Gamma(z) = \int_0^{\infty} t^{z-1} e^{-t} \,dt</annotation></semantics></math>

この関数は、正の整数 <math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi></mrow><annotation encoding="application/x-tex">n</annotation></semantics></math> に対して次の性質を持ちます:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi mathvariant="normal">Γ</mi><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo><mo>=</mo><mo stretchy="false">(</mo><mi>n</mi><mo>−</mo><mn>1</mn><mo stretchy="false">)</mo><mo stretchy="false">!</mo></mrow><annotation encoding="application/x-tex">\Gamma(n) = (n-1)!</annotation></semantics></math>

これにより、ガンマ関数は連続的に階乗を拡張しています。


2. 負の数の階乗の定義

負の整数以外の負の数に対して、次のように定義されます:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mo stretchy="false">(</mo><mo>−</mo><mi>n</mi><mo stretchy="false">)</mo><mo stretchy="false">!</mo><mo>=</mo><mfrac><mrow><mi mathvariant="normal">Γ</mi><mo stretchy="false">(</mo><mo>−</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">)</mo></mrow><mn>1</mn></mfrac></mrow><annotation encoding="application/x-tex">(-n)! = \frac{\Gamma(-n+1)}{1}</annotation></semantics></math>

ただし、負の整数ではガンマ関数は特異点(無限大になる点)を持つため、定義されません。

例:<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>−</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mo stretchy="false">!</mo></mrow><annotation encoding="application/x-tex">-\frac{1}{2}!</annotation></semantics></math> の計算

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi mathvariant="normal">Γ</mi><mrow><mo fence="true">(</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mo fence="true">)</mo></mrow><mo>=</mo><msqrt><mi>π</mi></msqrt></mrow><annotation encoding="application/x-tex">\Gamma\left(\frac{1}{2}\right) = \sqrt{\pi}</annotation></semantics></math>

したがって、<math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>−</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mo stretchy="false">!</mo></mrow><annotation encoding="application/x-tex">-\frac{1}{2}!</annotation></semantics></math> は次のようになります:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mo>−</mo><mfrac><mn>1</mn><mn>2</mn></mfrac><mo stretchy="false">!</mo><mo>=</mo><mfrac><msqrt><mi>π</mi></msqrt><mn>2</mn></mfrac></mrow><annotation encoding="application/x-tex">-\frac{1}{2}! = \frac{\sqrt{\pi}}{2}</annotation></semantics></math>

3. 負の整数の階乗は未定義

負の整数の場合、ガンマ関数は**極(無限大)**となるため、計算不可能です。

例:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi mathvariant="normal">Γ</mi><mo stretchy="false">(</mo><mn>0</mn><mo stretchy="false">)</mo><mo>=</mo><mi mathvariant="normal">∞</mi><mo separator="true">,</mo><mspace width="1em"></mspace><mi mathvariant="normal">Γ</mi><mo stretchy="false">(</mo><mo>−</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mi mathvariant="normal">∞</mi></mrow><annotation encoding="application/x-tex">\Gamma(0) = \infty,\quad \Gamma(-1) = \infty</annotation></semantics></math>

4. Pythonでの計算例(scipy使用)

Pythonの scipy ライブラリを使って負の数の階乗を計算する例です:

from scipy.special import gamma

# -0.5の階乗を計算
n = -0.5
factorial_neg = gamma(n + 1)
print(f"{n}! =", factorial_neg)

出力

-0.5! = 1.7724538509055159  # ≈ √π

5. まとめ

  • 負の整数の階乗は未定義(無限大)。
  • 負の非整数の階乗はガンマ関数で計算可能。
  • Pythonのscipyで計算可能(scipy.special.gamma)。


最新の画像もっと見る

コメントを投稿

サービス終了に伴い、10月1日にコメント投稿機能を終了させていただく予定です。
ブログ作成者から承認されるまでコメントは反映されません。