ååã®ãCÏãã«ä»¥ä¸ã®æ©è½ã追å ãããã¨ã«ãã¾ãã
ããã°ã©ãã³ã°è¨èªCã§ãé åã使ããã¨ã§å®ç¾ã§ããã®ã§å¿ è¦ãªã(ã¡ã¢ãªã¼ä¸è¶³ã«ã¯ãªããªãã¨ãã¦ããã®ã§ä»»æã®é·ãã®é åã使ããã¨ãã§ãã)ã®ã§ãããæåããã§ãããã¨ã«ãã¦ããã¾ãã
ãä¸å®å ¨æ§å®çã¨ã¯ãªã«ã å®å ¨ç ã²ã¼ãã«ã¨ãã¥ã¼ãªã³ã° 天æã¯ãªã«ã証æããã®ã (ãã«ã¼ããã¯ã¹ B 2277)ãã調ã¹ãåã«ãããã°ã©ãã³ã°è¨èªçä¸å®å ¨æ§å®çãã«ã¤ã㦠ChatGPT ã§èª¿ã¹ã¦ã¿ã¾ããã
ããã°ã©ãã³ã°è¨èªçä¸å®å ¨æ§å®ç
å ¥å: ãè«çå¼ã§æ¸ãã¨ã©ããªãã¾ãã
çµæ:
é¢æ° ã®å®ç¾©ã«åºã¥ãã¨ã ã¨ã¯ èªç¶æ° ããCÏãã®ã³ã¼ãã§ããããã®ã³ã¼ããå®è¡ããã¨ãã«åæ¢ãã ãã¨ãæå³ãã¾ãã
ãããè«çå¼ã§æ¸ãã¨ã次ã®ããã«è¡¨ç¾ã§ãã¾ãï¼
è«çå¼ã®è¦ç´
1. ããCÏãã®ã³ã¼ãã§ãããã¨
- ããã¯ã ãèªç¶æ°ã¨ãã¦æå¹ãªãCÏãã®ã³ã¼ãã§ãããã¨ããæå³ã§ããããã ã¨æ¸ãã¾ãã
2. ãCÏãã®ã³ã¼ã ãå®è¡ããã¨åæ¢ãããã¨
- ããã¯ã ãã³ã¼ãã¨ãã¦è§£éãå®è¡ããã¨ãã«æéæéå ã«åæ¢ãããã¨ããæå³ã§ããããã ã¨æ¸ãã¾ãã
è«çå¼ã®çµè«
以ä¸ãã¾ã¨ããã¨ã ã¯æ¬¡ã®ãããªè«çå¼ã§æ¸ãã¾ãï¼
è£è¶³
- : ããCÏãã®ã³ã¼ãã¨ãã¦æ§æçã«æ£ãããã¨ã示ãè¿°èªã
- : ã³ã¼ã ãå®è¡ããã¨ãã«åæ¢ãããã¨ã示ãè¿°èªã
ãã® ãåæ¢æ§åé¡ï¼Halting Problemï¼ã«é¢ä¿ããè¿°èªã§ããããããè¨ç®å¯è½ãªå½¢ã§å®ç¾©ãããã¨ãä¸è¬ã«ã¯ä¸å¯è½ã§ãããããé¢æ° ã®å®ç¾ãçè«çã«ä¸å¯è½ã§ãããã¨ã«ã¤ãªããã¾ãã
è«çå¼ã§æ¸ããã¨ãã§ãããã©ããããããããªãã®ã§ã以ä¸ã®ããã«å ¥åãã¾ããã
å ¥å: ã¯ããã¹ã¦ã®ã«ã¼ãã®å®è¡åæ°ã¨ãã¹ã¦ã®é¢æ°å¼ã³åºãã®å®è¡åæ°ã®åè¨ãæéãã¨è¨ãæãããã¨ã¯ã§ãã¾ãã
çµæ:
ã¯ãã ãããã¹ã¦ã®ã«ã¼ãã®å®è¡åæ°ã¨ãã¹ã¦ã®é¢æ°å¼ã³åºãã®å®è¡åæ°ã®åè¨ãæéãã¨è¨ãæãããã¨ã¯å¯è½ã§ãããã®è¨ãæãã¯ãåæ¢æ§åé¡ã®æ§è³ªãæ£ãã表ãã¦ãã¾ãã
çç±
åæ¢æ§åé¡ã®æ¬è³ªã¯ããããã°ã©ã ãæéã®æé ã§çµäºãããã©ããããå¤å®ãããã¨ã§ãããã®æ¡ä»¶ãæºããããã«ã¯ã以ä¸ã®2ç¹ã確èªããå¿ è¦ãããã¾ãï¼
1. ã«ã¼ã:
- ããã°ã©ã å ã®ãã¹ã¦ã®ã«ã¼ãï¼ä¾ãã°ã`for` ã `while`ï¼ãæéåã§çµäºããå¿ è¦ãããã¾ãã
- ã«ã¼ãã®ç¡éå®è¡ã¯ãããã°ã©ã ã®åæ¢ã妨ãã主è¦ãªè¦å ã§ãã
2. é¢æ°å¼ã³åºã:
- ããã°ã©ã ãå¼ã³åºããã¹ã¦ã®é¢æ°ãæéåã®å¦çã§çµäºããå¿ è¦ãããã¾ãã
- å帰çãªé¢æ°å¼ã³åºããé¢æ°ã®ç¡éã«ã¼ããåæ¢ã妨ãã¾ãã
ããã2ã¤ãåãããã¨ããããã°ã©ã ã®ãã¹ã¦ã®ã«ã¼ãã¨é¢æ°å¼ã³åºããæéåã§çµäºããå ´åããã®ããã°ã©ã ã¯åæ¢ãããã¨è¨ãã¾ãã
è¨ãæãã¨ãã¦ã®è¡¨ç¾
ãã®è¦³ç¹ããã ã次ã®ããã«è¨ãæãããã¨ãã§ãã¾ãï¼
- å½¢å¼çãªè¨ãæã:
- éå½¢å¼çãªè¨ãæã:
ããã°ã©ã ã®å®è¡ãç¡éã«ç¶ãããæçµçã«åæ¢ãããã¨ã
注æç¹
ãã®è¨ãæãã¯åæ¢æ§åé¡ã®æ§è³ªãç´æçã«æãããã®ã§ãããåæ¢æ§åé¡ã®æ¬è³ªçãªé£ããã解æ¶ããããã§ã¯ããã¾ãããå ·ä½çã«ã¯æ¬¡ã®ç¹ãéè¦ã§ãï¼
1. å®è¡åæ°ãäºåã«ç¥ãã®ã¯å°é£
- ããããã°ã©ã ã«ããããã¹ã¦ã®ã«ã¼ããé¢æ°å¼ã³åºãã®å®è¡åæ°ãæéãã©ããã決å®ãããã¨ã¯ä¸è¬ã«ã¯ä¸å¯è½ã§ãï¼ãã¥ã¼ãªã³ã°æ©æ¢°ã®åæ¢æ§åé¡ã«å¸°çãã¾ãï¼ã
2. åæ¢æ§åé¡ã®é決å®å¯è½æ§
- åæ¢æ§åé¡ã¯ä¸è¬ã«é決å®å¯è½ã§ãããããã¹ã¦ã®ã«ã¼ããé¢æ°å¼ã³åºãã®å®è¡åæ°ãæéãããå¤å®ããè¿°èªèªä½ãè¨ç®å¯è½ã§ã¯ããã¾ããã
ãããã£ã¦ããã®è¨ãæãã¯åæ¢æ§ã®æ§è³ªãåããããã表ç¾ããå©ãã«ã¯ãªãã¾ãããããã使ã£ã¦åæ¢æ§åé¡ã解決ãããã¨ã¯ã§ãã¾ããã
è«çå¼ã§æ¸ããã¨ã¯ã§ããã¨è¨ãã¾ãã確èªã®ããããã«ä»¥ä¸ãå ¥åãã¦ã¿ã¾ãããããã¯åæ¢ããªããã¨ã証æããã«ã¯ã«ã¼ããå®è¡ãããåæ°ã調ã¹ãå¿ è¦ãããã¨æãããããã§ãã
å ¥å: ç¡éã«ã¼ãã¯åæ¢ããªããã¨ã証æãã¦ãã ãã
çµæ:
ç¡éã«ã¼ããåæ¢ããªããã¨ã¯ããã®å®ç¾©ããæããã§ãã以ä¸ã§è«ççã«èª¬æãã¾ãã
ç¡éã«ã¼ãã®å®ç¾©
ç¡éã«ã¼ãã¨ã¯ãçµäºæ¡ä»¶ãæºããããªãã¾ã¾ããããã¯ã«ã¼ãã®æ§é èªä½ãçµäºæ¡ä»¶ãæããªãããã«ãç¡éã«ç¹°ãè¿ãå®è¡ãããå¦çãæãã¾ãã
ä¸è¬çãªç¡éã«ã¼ãã®æ§é ã¯æ¬¡ã®ããã«ãªãã¾ãï¼
1. æ¡ä»¶ä»ãã«ã¼ã:
while (true) { /* å¦ç */ }ããã§ã¯ãã«ã¼ãã®çµäºæ¡ä»¶ã常㫠`true` ã§ãããããçµäºãããã¨ãããã¾ããã
2. æ¡ä»¶ãå¤åããªãã«ã¼ã:
while (x != 0) { /* å¦ç */ }ããã§ã`x` ã®å¤ãã«ã¼ãå é¨ã§å¤æ´ãããªãå ´åãæ¡ä»¶ `x != 0` ã常㫠`true` ã®ã¾ã¾ã«ãªããã«ã¼ãã¯çµäºãã¾ããã
åæ¢ããªããã¨ã®è¨¼æ
ç¡éã«ã¼ããåæ¢ããªããã¨ãå½¢å¼çã«è¨¼æããã«ã¯ããåæ¢ãããã¨ããä»®å®ãçç¾ãçããã¨ã示ãèçæ³ãç¨ãããã¨ãã§ãã¾ãã
1. åæ¢ããã¨ããä»®å®
ç¡éã«ã¼ããåæ¢ããã¨ä»®å®ãã¾ããããã¯ãã«ã¼ãã®å®è¡åæ°ãæéã§ãããã¨ãæå³ãã¾ãã
2. å®è¡åæ°ã®æéæ§ã¨ã®çç¾
ç¡éã«ã¼ãã®å®ç¾©ã«ããã¦ã次ã®2ã¤ãæºãããã¾ãï¼
- ã«ã¼ãã®æ¡ä»¶ãæ°¸é ã«çã§ããç¶ããï¼çµäºæ¡ä»¶ãåå¨ããªããã¾ãã¯æºããããªãï¼ã
- å®è¡åæ°ã«ä¸éããªãï¼ç¡éåç¹°ãè¿ãããï¼ã
ãããã£ã¦ããç¡éã«ã¼ããåæ¢ãããã¨ããä»®å®ã¯ãç¡éã®å復ãæéåã§çµäºãããã¨è¨ã£ã¦ããã®ã¨çãããªããããã¯çç¾ã§ãã
3. çµè«
çç¾ãçããããããç¡éã«ã¼ããåæ¢ãããã¨ããä»®å®ã¯èª¤ãã§ããã¨ãããã¾ãããã£ã¦ãç¡éã«ã¼ãã¯åæ¢ãã¾ããã
å½¢å¼çãªè«çè¨è¿°
ç¡éã«ã¼ããåæ¢ããªããã¨ãæ°çè«ççã«è¨è¿°ããå ´åã次ã®ããã«æ¸ãã¾ãï¼
1. ç¡éã«ã¼ãã表ãããã°ã©ã ã ã¨ããã
2. ããã°ã©ã ãåæ¢ããã¨ã¯ãããæéã®ã¹ãããæ° ãåå¨ããããã°ã©ã ããã®ã¹ãããæ°ä»¥å ã«çµäºãããã¨ã§ãããç¡éã«ã¼ãã®å®ç¾©ãããä»»æã®æéã® ã«å¯¾ãã¦æ¬¡ãæãç«ã¡ã¾ãï¼
ããã¯ããç¡éã«ã¼ããåæ¢ããªããã¨ãããã¨ãè«ççã«è¡¨ãã¦ãã¾ãã
è£è¶³
ç¡éã«ã¼ããåæ¢ããªããã¨ã¯ããã®åä½ãã·ãã¥ã¬ã¼ã·ã§ã³ããã ãã§ã観å¯å¯è½ã§ããããããåæ¢æ§åé¡å ¨ä½ãèæ ®ããã¨ãç¹å®ã®ããã°ã©ã ãç¡éã«ã¼ãã«é¥ããã©ãããäºåã«å¤å®ãããã¨ã¯ä¸è¬ã«ã¯ä¸å¯è½ã§ãï¼åæ¢æ§åé¡ã®é決å®å¯è½æ§ï¼ã
ãä¸å®å
¨æ§å®çã¨ã¯ãªã«ã å®å
¨ç ã²ã¼ãã«ã¨ãã¥ã¼ãªã³ã° 天æã¯ãªã«ã証æããã®ã (ãã«ã¼ããã¯ã¹ B 2277)ãã§ã¯çã§ãã証æã§ããªãè«çå¼ãããã¨æ¸ããã¦ãã¾ãããã®ã·ã¹ãã ã§ãã®ãããªãã®ããããã©ããã調ã¹ãããã以ä¸ã®ããã«å
¥åãã¾ããã
å ¥å: ãçãªã®ãå½ãªã®ããããã¾ãã
çµæ:
ãçãå½ããå¤å®ãããã¨ã¯ä¸å¯è½ã§ãããããåæ¢æ§åé¡ã®é決å®å¯è½æ§ã«ãããã®ã§ãããèªå·±åç §çãªæ§é ãå«ã ã ã®ãããªç¶æ³ã§ã¯çç¾ãçãã¾ãã以ä¸ã§ãã®çç±ã詳細ã«èª¬æãã¾ãã
1. ã®å®ç¾©
ã¯èªå·±åç §çãªããã°ã©ã ã®ã³ã¼ãï¼èªç¶æ°è¡¨ç¾ï¼ã¨ãã¾ãã ã®æåã¯æ¬¡ã®ããã«å®ç¾©ããã¦ãã¾ãï¼
2. ãå¤å®ãããã¨ããã¨çç¾ãçãã
ã¨ä»®å®ããå ´å㨠ã¨ä»®å®ããå ´åãããããèãã¾ãã
ã±ã¼ã¹ 1: ã¨ä»®å®ãã
- ã§ãããªããå®ç¾©ã«ãã ã¯ç¡éã«ã¼ããã¾ãã
- ãããã ã¯ã ãåæ¢ãããã¨ä¸»å¼µãã¦ãããããçç¾ãçãã¾ãã
ã±ã¼ã¹ 2: ã¨ä»®å®ãã
- ã§ãããªããå®ç¾©ã«ãã ã¯åæ¢ãã¾ãã
- ãããã ã¯ã ãåæ¢ããªããã¨ä¸»å¼µãã¦ãããããçç¾ãçãã¾ãã
3. çµè«: ãå¤å®ã§ããªã
ãã®èªå·±çç¾ãããã ãçãå½ããå¤å®ãããã¨ã¯ã§ããªãããã¨ããããã¾ããããã¯ãåæ¢æ§åé¡ã®é決å®å¯è½æ§ãç´æ¥ç¤ºãã¦ãã¾ãã
åæ¢æ§åé¡ã®æ ¸å¿
ãã®ä¾ã¯ãåæ¢æ§åé¡ãè¨ç®çè«çã«æ±ºå®ä¸å¯è½ã§ããçç±ã端çã«ç¤ºãã¦ãã¾ããé¢æ° ã使ã£ã¦åæ¢æ§ãå¤å®ãããã¨ããã¨ãèªå·±åç §ãçããè«çççç¾ãçºçãããããåæ¢æ§ãä¸è¬çã«å¤å®ãã ã®ãããªé¢æ°ã¯åå¨ãå¾ã¾ããã
ãã®ã·ã¹ãã ã§ã¯ãã¶ãã§ããªãã®ã§ãæ¡ä»¶ãå¤ãã¦ã¿ã¾ãã
å ¥å: ããã°ã©ãã³ã°è¨èªã®æ©è½ãå¶éããã° ãçãªã®ãå½ãªã®ããããã¾ãã
çµæ:
ããã°ã©ãã³ã°è¨èªã®æ©è½ãå¶éãããã¨ã§ãç¹å®ã®æ¡ä»¶ä¸ã§ ãçãªã®ãå½ãªã®ããå¤å®ã§ããå ´åãããã¾ãããã ãããã®å¤å®å¯è½æ§ã¯è¨èªã®å¶éã®ç¨åº¦ã«ä¾åãã¾ãã以ä¸ã«è©³ãã説æãã¾ãã
1. ããã°ã©ãã³ã°è¨èªãå¶éããä¾
åæ¢æ§åé¡ã®æ±ºå®ä¸å¯è½æ§ã¯ããã¥ã¼ãªã³ã°å®å ¨ãªããã°ã©ãã³ã°è¨èªã«ãããç¹æ§ã§ãããããã£ã¦ãè¨èªã以ä¸ã®ããã«å¶éããã¦ããå ´åã«ã¯ãåæ¢æ§ãå¤å®å¯è½ã«ãªãå ´åãããã¾ãï¼
a. å帰ãç¡éã«ã¼ããç¦æ¢
- ããã°ã©ã ã«å帰é¢æ°ãç¡éã«ã¼ã (`while (true)`) ãè¨è¿°ã§ããªãããã«ããã
- ä¾ã¨ãã¦ãåç´ãªæéã®å½ä»¤ã»ããã®ã¿ã許ãããã°ã©ã ï¼ä¾ï¼ã«ã¼ãåæ°ãéçã«æ±ºã¾ãï¼ãèãã¾ãã
ãã®å ´åããã¹ã¦ã®ããã°ã©ã ã®å®è¡ãæéã§ããããã ãã©ããã常ã«å¤å®å¯è½ã§ããè¨èªã®æ§è³ªä¸ãç¡éã«ã¼ããçããªãããã§ãã
b. å®è¡æéãã¹ãããæ°ã«ä¸éãè¨å®
- ããã°ã©ã ã«ãæ大ã¹ãããæ°ãããæ大è¨ç®æéãã®ä¸éã課ãã
- ãã®å¶éä¸ã§ã¯ãåæ¢ãããã©ãããããã°ã©ã ã®ã·ãã¥ã¬ã¼ã·ã§ã³ã«ãã£ã¦æ±ºå®ã§ãã¾ããåæ¢ããªããã°ãæéåããã¨å¤å®ããã°ããããã§ãã
ãã ããããã¯ãæéåãããåæ¢æ§ã®ä»£æ¿æ¡ä»¶ã¨ãããã®ã§ãããåæ¢æ§åé¡ãã®ãã®ãå®å ¨ã«è§£æ±ºãã¦ããããã§ã¯ããã¾ããã
2. è¨èªå¶é㨠ã®å¤å®å¯è½æ§
ãå¤å®å¯è½ã«ããããã«ã¯ã以ä¸ã®æ¡ä»¶ãæºããå¿ è¦ãããã¾ãï¼
1. è¨èªã®è¡¨ç¾åãæéã§ãããã¨
- ããã°ã©ã ãè¨ç®å¯è½ãªãã¹ã¦ã®å¦çãè¨è¿°ã§ããï¼ãã¥ã¼ãªã³ã°å®å ¨ã§ããï¼å ´åãåæ¢æ§åé¡ã®æ±ºå®ä¸å¯è½æ§ãããä¸è¬ã«ã¯ ãå¤å®ã§ãã¾ããã
- 表ç¾åãæéã«å¶éããå ´åï¼ä¾ï¼ãã¹ã¦ã®ã«ã¼ããæéåæ°ã§çµäºãããªã©ï¼ãåæ¢æ§ãå¤å®å¯è½ã«ãªãã¾ãã
2. ããã°ã©ã ã®æåãéç解æå¯è½ã§ãããã¨
- ããã°ã©ã ã®åæ¢æ§ãã³ã¼ãã®æ§é ãä»æ§ãã解æçã«å¤æã§ããå ´åï¼ä¾ï¼ãã¹ã¦ã®ã«ã¼ãåæ°ãéçã«è¨ç®å¯è½ï¼ã ãå¤å®ã§ãã¾ãã
3. å ·ä½ä¾
å¶éãããè¨èªã§ã®ä¾
- ã«ã¼ãåæ°ãæ示çã«åºå®ããã¦ããå ´åï¼
for (int i = 0; i < 10; i++) { /* å¦ç */ }ãã®å ´åãã«ã¼ããå¿ ãçµäºãããããåæ¢æ§ãä¿è¨¼ããã¾ãããããã£ã¦ã ãå¤å®ã§ãã¾ãã
- ç¡æ¡ä»¶ã§ç¡éã«ã¼ããå«ãå ´åï¼
while (true) { /* å¦ç */ }ãã®å ´åãåæ¢ããªããã¨ãéçã«å¤å®ã§ãã¾ãã
ãã¥ã¼ãªã³ã°å®å ¨ãªè¨èªã®ä¾
次ã®ãããªããã°ã©ã ã§ã¯ãéç解æã§ã¯åæ¢æ§ãå¤æã§ãã¾ããï¼
int f(int x) { if (x == 0) return 1; else return f(x - 1) + f(x - 2); }å ¥åã«ãã£ã¦è¨ç®ãåæ¢ãããã©ãããåçã«å¤ããããã ãä¸è¬çã«å¤å®ãããã¨ã¯ã§ãã¾ããã
4. çµè«
ããã°ã©ãã³ã°è¨èªã®æ©è½ãå¶éããã°ãç¹å®ã®ã±ã¼ã¹ã§ ã®å¤å®ãå¯è½ã§ããããããããã«ã¯ãã¬ã¼ããªããããã¾ãï¼
- è¨èªã®è¡¨ç¾åãå¶éãããæ±ç¨çãªè¨ç®è½åã失ãï¼ãã¥ã¼ãªã³ã°å®å ¨ã§ã¯ãªããªãï¼ã
- ãã¥ã¼ãªã³ã°å®å ¨ãªè¨èªã§ããã°ãèªå·±åç §æ§é ãå«ãããã°ã©ã ã®åæ¢æ§åé¡ã¯è§£æ±ºã§ããªãã
ãããã£ã¦ãè¨èªãå¶éãããã¨ã§åæ¢æ§ãå¤å®å¯è½ã«ãããã¨ã¯ã§ãã¾ãããããã¯æ±ç¨çãªããã°ã©ãã³ã°è¨èªã¨ãã¦ã®è½åãç ç²ã«ãããã¨ãæå³ãã¾ãã
æ¡ä»¶ã«ã¤ãã¦ã¯ããããããªãã£ãã®ã§ãä¸å®å ¨æ§å®çã¨ã¯ãªã«ã å®å ¨ç ã²ã¼ãã«ã¨ãã¥ã¼ãªã³ã° 天æã¯ãªã«ã証æããã®ã (ãã«ã¼ããã¯ã¹ B 2277)ããè¦ã¦ããããã¨æãã¾ãã