Difference between revisions of "Basic Pascal Tutorial/Chapter 4/Recursion/ja"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "{{Recursion/ja}} 4E - 再帰 (著者: Tao Yue, 状態: 原文のまま修正なし) '''Recursion''' means allowing a function or procedure to call itself until some limit is...")
 
(bypass [previously missed] redirect [cf. discussion])
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Recursion/ja}}
+
{{Recursion}}
  
 
4E - 再帰 (著者: Tao Yue, 状態: 原文のまま修正なし)
 
4E - 再帰 (著者: Tao Yue, 状態: 原文のまま修正なし)
  
'''Recursion''' means allowing a function or procedure to call itself until some limit is reached.
+
'''再帰''' とは関数や手続きがある条件が満たされるまで自分自身を呼び出すことである。
  
The summation function, designated by an uppercase letter ''sigma'' (Σ) in mathematics, can be written recursively:
+
数学における大文字の ''sigma'' (Σ) で示される合計関数は再帰的に書くことができる。
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
function Summation (num : integer) : integer;
 
function Summation (num : integer) : integer;
 
begin
 
begin
Line 15: Line 15:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Suppose you call <tt>Summation</tt> for <tt>3</tt>.
+
<tt>3</tt> <tt>Summation</tt> を呼び出したとしよう。
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
a := Summation(3);
 
a := Summation(3);
 
</syntaxhighlight>
 
</syntaxhighlight>
  
* <tt>Summation(3)</tt> becomes <tt>Summation(2) + 3</tt>.
+
* <tt>Summation(3)</tt> <tt>Summation(2) + 3</tt> になる。
* <tt>Summation(2)</tt> becomes <tt>Summation(1) + 2</tt>.
+
* <tt>Summation(2)</tt> <tt>Summation(1) + 2</tt> になる、
* At <tt>1</tt>, the recursion stops and becomes <tt>1</tt>.
+
* <tt>1</tt> になると、再帰は終了し、 <tt>1</tt> になる。
* <tt>Summation(2)</tt> becomes <tt>1 + 2 = 3</tt>.
+
* <tt>Summation(2)</tt> <tt>1 + 2 = 3</tt> になる。
* <tt>Summation(3)</tt> becomes <tt>3 + 3 = 6</tt>.
+
* <tt>Summation(3)</tt> <tt>3 + 3 = 6</tt> になる。
* <tt>a</tt> becomes <tt>6</tt>.
+
* <tt>a</tt> <tt>6</tt> になる。
  
Recursion works backward until a given point is reached at which an answer is defined, and then works forward with that definition, solving the other definitions which rely upon that one.
+
再帰は答えが定義されているある時点に達するまで後ろ向きに働く。それから、その定義を基にした他の定義を解きながら、その定義に対しては前向きに働く???(Recursion works backward until a given point is reached at which an answer is defined, and then works forward with that definition, solving the other definitions which rely upon that one.)。
  
All recursive procedures/functions should have a test to stop the recursion, the base condition. Under all other conditions, the recursion should go deeper. If there is no base condition, the recursion will either not take place at all, or become infinite.
+
再帰手続きや再帰関数はすべてその再帰が基準条件で止まるかテストするべきである。基準条件以外のすべての条件では再帰はどんどん深くなっていくだろう。もし、基準条件がないと、再帰は全く起きないか、無限状態のいずれかになるだろう。
  
In the example above, the base condition was <tt>if num = 1</tt>.
+
上の例では、基準条件は <tt>if num = 1</tt> である。
  
 
{|style=color-backgroud="white" cellspacing="20"
 
{|style=color-backgroud="white" cellspacing="20"
|[[Scope/ja|previous]]   
+
|[[Basic Pascal Tutorial/Chapter 4/Scope/ja|previous]]   
|[[Contents/ja|contents]]  
+
|[[Basic Pascal Tutorial/Contents/ja|contents]]  
|[[Forward_Referencing/ja|next]]
+
|[[Basic Pascal Tutorial/Chapter 4/Forward Referencing/ja|next]]
 
|}
 
|}

Revision as of 14:24, 6 August 2022

български (bg) English (en) français (fr) 日本語 (ja) 中文(中国大陆)‎ (zh_CN)

4E - 再帰 (著者: Tao Yue, 状態: 原文のまま修正なし)

再帰 とは関数や手続きがある条件が満たされるまで自分自身を呼び出すことである。

数学における大文字の sigma (Σ) で示される合計関数は再帰的に書くことができる。

function Summation (num : integer) : integer;
begin
  if num = 1 
  then Summation := 1
  else Summation := Summation(num-1) + num
end;

3Summation を呼び出したとしよう。

a := Summation(3);
  • Summation(3)Summation(2) + 3 になる。
  • Summation(2)Summation(1) + 2 になる、
  • 1 になると、再帰は終了し、 1 になる。
  • Summation(2)1 + 2 = 3 になる。
  • Summation(3)3 + 3 = 6 になる。
  • a6 になる。

再帰は答えが定義されているある時点に達するまで後ろ向きに働く。それから、その定義を基にした他の定義を解きながら、その定義に対しては前向きに働く???(Recursion works backward until a given point is reached at which an answer is defined, and then works forward with that definition, solving the other definitions which rely upon that one.)。

再帰手続きや再帰関数はすべてその再帰が基準条件で止まるかテストするべきである。基準条件以外のすべての条件では再帰はどんどん深くなっていくだろう。もし、基準条件がないと、再帰は全く起きないか、無限状態のいずれかになるだろう。

上の例では、基準条件は if num = 1 である。

previous contents next