パスカルの三角形の公式と例

⚡ スマートサマリー

Pascal's Triangle is a triangular arrangement of numbers where each value equals the sum of the two numbers directly above it, revealing deep patterns in combinatorics, binomial expansions, and probability that have fascinated mathematicians for centuries.

  • 🔺 構造: 各行は1で始まり1で終わり、内部の値は上の2つの数値を足し合わせることによって作られます。
  • 📐 二項式リンク: n行k列は二項係数C(n, k)に等しく、三角形は組み合わせを視覚的に参照するためのものとなる。
  • 🔢 隠されたパターン: 行の合計は2のべき乗に等しくなり、対角線の合計はフィボナッチ数列を生成する。
  • ✅ 3つの方法: 前の行を基に構築することも、二項係数を計算することも、反復的な修正係数ショートカットを使用することも可能です。
  • 🧪 用途: 現代のカリキュラムにおいて、代数学、確率論、コンピュータサイエンス、および組み合わせ論的証明などで用いられている。

パスカルの三角形とは何ですか?

Pascal's Triangle is a triangular array of numbers that follows a simple pattern based on the row above it. It was popularized by French mathematician Blaise Pascal in the 17th century. The triangle begins with a single "1" at the top, and every subsequent row starts and ends with "1" as well.

パスカルの三角形

Beyond its elegant shape, Pascal's Triangle encodes deep mathematical relationships. It is closely tied to the binomial theorem, combinatorial counting, and probability, which is why it appears in algebra, statistics, and computer science classrooms worldwide.

パスカルのトライアングルの歴史

Although named after Blaise Pascal, the triangle predates him by centuries. The Chinese mathematical text "The Nine Chapters on the Mathematical Art" contains one of the earliest known examples, displaying many of the same patterns we use today.

ペルシャの数学者アル・カラジとインドの学者 Pingala also explored similar arrays. Pascal formalized the triangle's properties in his 1654 treatise "Traité du triangle arithmétique," which gave the structure its modern name in Western mathematics.

パスカルの三角形の構築

Constructing Pascal's Triangle is straightforward. The only rule to remember is that each row starts and ends with 1, and every other number is built from the row above.

任意の行 r と列 c について、その値は行 r-1 の列 c-1 と列 c の数値の合計に等しくなります。

ここでは、

  • r = 3, 4, 5, ...
  • n and c = 2, 3, 4, ..., r-1.

Here are the steps to build Pascal's Triangle:

ステップ1) まず最初の2行を埋めてください。

パスカルの三角形の構築

ステップ2) 3行目の2番目の要素は、2行目の1番目と2番目の数値の合計です。

パスカルの三角形の構築

ステップ3) The fourth row begins with "1". The second number is 3, which is the sum of 1 and 2 (highlighted in blue).

下の画像は、4行目を埋める方法を示しています。

パスカルの三角形の構築

ステップ4) 5行目は5つの数字で構成されています。行を埋めるパターンは、前の手順ですでに分かっています。

パスカルの三角形の構築

パスカルの三角形の公式 - 二項係数

A binomial coefficient counts the number of ways to choose a subset of k elements from a collection of n elements. It is commonly written as "C(n, k)" or "n choose k."

二項係数は次のように定義されます。

パスカルの三角形の公式 - 二項係数

The "!" symbol denotes the factorial of a number.

n! = n.(n-1).(n-2)...3.2.1

たとえば、

5! = 5.4.3.2.1

= 120

So, C(5, 3) or "5 choose 3" = 5! / 3!(5-3)!

= 120/12

= 10

方法1:前の行を使ってパスカルの三角形を作る

The procedure here mirrors how we drew the triangle manually. Suppose we want to generate Pascal's triangle up to seven rows.

その手順は以下のとおりです。

ステップ1) Start the topmost row with "1".

ステップ2) For row "r", element "c" will be the sum of column "c-1" and column "c" of row "r-1".

ステップ3) The first and last numbers in every row will always be "1".

これら3つの簡単な手順に従うことで、三角形全体を体系的に構築することができます。

C++ Code パスカルの三角形の前の行

#include <bits/stdc++.h>
using namespace std;
void printRow(int n)
{
  int numbers[n][n];
  for (int row = 0; row < n; row++)
  {
    for (int col = 0; col <= row; col++)
    {
      if (col == 0 || col == row)
      {
        numbers[row][col] = 1;
      }
      else
      {
        numbers[row][col] = numbers[row - 1][col - 1] + numbers[row - 1][col];
      }
      cout << numbers[row][col] << "\t";
    }
    cout << endl;
  }
}
int main()
{
  int n;
  cout << "How many rows: ";
  cin >> n;
  printRow(n);
}

出力:

How many rows: 7
1
1       1
1       2       1
1       3       3       1
1       4       6       4       1
1       5       10      10      5       1
1       6       15      20      15      6       1

Python Code パスカルの三角形の公式を前の行で表す

def printRow(n):
    numbers = [[0 for row in range(n)]
               for col in range(n)
               ]
    for row in range(len(numbers)):
        for col in range(0, row+1):
            if row == col or col == 0:
                numbers[row][col] = 1
            else:
                numbers[row][col] = numbers[row-1][col-1]+numbers[row-1][col]

            print(numbers[row][col],end="\t")
        print("\n")
n = int(input("How many rows: "))
printRow(n)

Pascal's Triangle Example Output:

How many rows: 7
1
1       1
1       2       1
1       3       3       1
1       4       6       4       1
1       5       10      10      5       1
1       6       15      20      15      6       1

複雑さの分析

A 二次元配列 is used in this implementation. Given that N is the number of rows in Pascal's triangle, this requires N2 単位空間。したがって、空間計算量はO(N)である。2).

The function uses two nested loops, each running up to "N" times. So, the time complexity is also オン2)または、時間計算量の二乗。

方法2:二項係数を計算してパスカルの三角形を構築する

We can derive the numbers of Pascal's triangle directly using binomial coefficients. The diagram below illustrates the relationship:

二項係数を計算してパスカルの三角形を構築する

Here are the steps to build Pascal's Triangle by calculating the binomial coefficient:

ステップ1) 一番上の行は C(0, 0) です。上記の式を用いると、0! = 1 なので、C(0, 0) = 1 となります。

ステップ2) For row "i", there will be a total of "i" elements. Each item is calculated as C(n, r), where n is i-1.

ステップ3) Repeat step 2 for as many rows of Pascal's triangle as you want to generate.

C++ Code 二項係数によるパスカルの三角形

#include <iostream>
using namespace std;
int factorial(int n)
{
    int result = 1;
    for (int i = 1; i <= n; i++)
    {
        result *= i;
    }
    return result;
}
int binomialCoefficient(int n, int r)
{
    int result = 1;
    if (r > n)
    {
        return -1;
    }
    result = factorial(n) / (factorial(r) * factorial(n - r));
    return result;
}
void printPascalTriangle(int row)
{
    for (int i = 0; i <= row; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            cout << binomialCoefficient(i, j) << "\t";
        }
        cout << endl;
    }
}
int main()
{
    int n;
    cout << "Enter row number: ";
    cin >> n;
    printPascalTriangle(n);
}

出力:

Enter row number: 9
1
1	1
1	2	1
1	3	3	1
1	4	6	4	1
1	5	10	10	5	1
1	6	15	20	15	6	1
1	7	21	35	35	21	7	1
1	8	28	56	70	56	28	8	1
1	9	36	84	126	126	84	36	9	1

Python Code 二項係数によるパスカルの三角形

def factorial(n):
    result = 1
    for i in range(1,n+1):
        result*=i
    return result
def binomialCoefficient(n,r):
    result =1
    if r>n:
        return None
    result = factorial(n) / (factorial(r) * factorial(n - r))
    return int(result)
def printPascalTriangle(row):
    for i in range(row+1):
        for j in range(i+1):
            print(binomialCoefficient(i, j), end="\t")
        print()
# print(binomialCoefficient(3, 2))
n = int(input("Enter row number: "))
printPascalTriangle(n)

Pascal's Triangle Example Output:

Enter row number: 8
1
1       1
1       2       1
1       3       3       1
1       4       6       4       1
1       5       10      10      5       1
1       6       15      20      15      6       1
1       7       21      35      35      21      7       1
1       8       28      56      70      56      28      8       1

複雑さの分析

Three loops are used in this implementation: one to compute the binomial coefficient and two more to iterate through every row and column. With respect to the number of rows, all three loops run up to "n" times. Consequently, the overall time complexity is O(n3).

中間結果を一切保存しないため、空間計算量は一定です。プログラムは各要素をその場で計算し、行内に出力するため、空間計算量は減少します。 O(1).

方法 3: 修正二項係数によるパスカルの三角形の構築

従来の手法では、二項係数式を用いて各要素を計算していました。改良された手法では、C(n, r)をC(n, r-1)から直接導出することで、計算量を1桁削減します。

Here are the steps to build Pascal's Triangle by the modified binomial coefficient:

ステップ1) Initiate the first row with "1".

ステップ2) Calculate C(n, r), where "n" is the row number and "r" is the column index. Assign that value to a variable C.

ステップ3) For computing the next coefficient, use C * (n - k) / k. Assign this new value back to C.

ステップ4) Continue step 3 until "k" reaches the end of the row. After each iteration, increment k by one.

C++ Code 修正二項係数によるパスカルの三角形

#include <bits/stdc++.h>
using namespace std;
void printpascalTriangle(int n)
{
  for (int row = 1; row <= n; row++)
  {
    int previous_coef = 1;
    for (int col = 1; col <= row; col++)
    {
      cout << previous_coef << "\t";
      previous_coef = previous_coef * (row - col) / col;
    }
    cout << endl;
  }
}

int main()
{
  int n;
  cout << "How many rows: ";
  cin >> n;
  printpascalTriangle(n);
}

出力:

How many rows: 5
1
1       1
1       2       1
1       3       3       1
1       4       6       4       1

Python Code 修正二項係数によるパスカルの三角形

def printpascalTriangle(n):
    for row in range(1, n+1):
        previous_coef = 1
        for col in range(1, row+1):
            print(previous_coef, end="\t")
            previous_coef = int(previous_coef*(row-col)/col)
        print()
n = int(input("How many rows: "))
printpascalTriangle(n)

Pascal's Triangle Patterns Output:

How many rows: 5
1
1       1
1       2       1
1       3       3       1
1       4       6       4       1

複雑さの分析

The implementation uses two loops, each running a maximum of "n" times, where "n" is the number of rows in the triangle. So, the time complexity is オン2)、二乗時間。

空間計算量に関しては、ストレージ用の配列は必要ありません。前の二項係数を保持するために1つの変数のみを使用するため、追加のスペースは1つだけで済みます。したがって、空間計算量は次のようになります。 O(1).

パスカルの三角形の応用

Here are some practical applications of Pascal's Triangle:

二項展開: The coefficients of any binomial expansion can be read directly from Pascal's triangle. Here is an example:

(x + y)0 1
(x + y)1 1.x + 1.y
(x + y)2 1x2 + 2xy+ 1y2
(x + y)3 1x3 + 3x2および+ 3xy2 + 1y3
(x + y)4 1x4 + 4x3および+ 6x2y2 + 4xy3 + 1y4

組み合わせの計算: The elements of Pascal's triangle correspond directly to binomial coefficients. For example, if you have 6 balls and want to choose 3, the answer is 6C3. You can find that value in the 3rd element of the 6th row of Pascal's triangle.

確率: Pascal's Triangle is widely used to compute probabilities in coin tosses, dice problems, and other combinatorial events where each outcome corresponds to a binomial distribution.

パスカルの三角形に関する興味深い事実

Here are some facts you will find interesting about Pascal's triangle:

  • どの行においても、すべての要素の合計は常に2のべき乗となる。

パスカルの三角形に関する事実

  • 行の対角線の合計はフィボナッチ数列を生成する。

パスカルの三角形に関する事実

  • 各行は、(a+b) の展開における係数に対応します。n.
  • 奇数だけを塗りつぶすと、結果として得られる図形はシェルピンスキーの三角形フラクタルを形成します。

よくあるご質問

1654年に形式化したブレーズ・パスカルにちなんで名付けられた三角形だが、中国、インド、ペルシャでは数世紀前から知られていた。賈賢、楊輝、 Pingアラやアル・カラジは、パスカルよりもずっと以前に同様の配列を研究していた。

パスカルの三角形の各要素は、二項係数 C(n, k) に相当します。n 行目の数値は (a + b) の n 乗の係数を表しており、この三角形は二項展開の高速参照表として利用できます。

パスカルの三角形のn行目のすべての数字の合計は、2のn乗になります。例えば、4行目には1、4、6、4、1があり、これらを合計すると16となり、ちょうど2の4乗になります。

パスカルの三角形の浅い対角線上の数字を足し合わせると、フィボナッチ数列(1、1、2、3、5、8、13…)が形成されます。これは、この三角形に隠された最も美しいパターンの1つです。

パスカルの三角形は、コイン投げのように、2つの結果が等しい確率で起こる事象の確率をモデル化します。n行目は、n回のコイン投げでk回表が出る場合のパターン数を示しており、これは二項確率分布に直接関係します。

AIシステムは、特徴選択、サンプリング、および組み合わせ最適化のために、パスカルの三角形から抽出した二項係数を使用します。強化学習エージェントや数式処理ソルバーも、多項式展開や離散選択問題について推論する際に、この三角形を参照します。

はい。AI搭載の数学チューターは、行ごとの視覚化、適応型練習問題、二項係数演習に対する即時フィードバックを提供します。学習者は自分のペースで、三角形と組み合わせ、確率、二項定理を結びつけて理解することができます。