æ¨æ©ææã§ãid:bonotakeããã¨id:ku-ma-meããã«ãä¼ãããã®ã§ãããku-ma-meãããbonotakeããã®ã¢ããã¤ã¹ï¼ããã®ããï¼ã«ãããSeven Treesããºã«ã解ãããããã§ãï¼http://d.hatena.ne.jp/ku-ma-me/20081023/p1 åç §ï¼ãããããªã¼ã
ãããã¯é£ããããºã«ã ãåãæ¥ãç´¹ä»ãã ãã§ã¯ãåé¡ãç解ãã«ããã¨ãããããã®ã§ãããå°ãæ£ç¢ºãªè¨è¿°ããã¾ãï¼ãåãæ¥ãç´¹ä»ãã®ã³ã¡ã³ãæ¬ãå ¨é¨èªãã¨ããã£ããããããªãã¾ãããï¼ãã«ã¼ã«ãæ£ç¢ºã«è¨è¿°ããã¨ãå¿ ç¶çã«ãã³ããä¸ãããã¨ã«ãªãã¾ããããããããã¼ãã³ãã§ã¯é£ããããåé¡ãªã®ã§ãé 次ãã³ãã追å ãã¦ããäºå®ã§ãã
解çä¾ã¯ã解ãã人ãï¼å°ãªãã¨ãku-ma-meãããï¼å ¬è¡¨ããã ããã¨æãã¾ãããâä»ã®äººã®ã楽ãã¿âã®ããã1,2é±éãããæéã空ãããããããããªãã®ããªã
å 容ï¼
- æ¨ãæä½ããé¢æ°é
- ãããã®é¢æ°éãããå°ã詳ãã
- ããã«ããå°ãè£è¶³
- éåTã®å¸°ç´çå®ç¾©ã¨æ¨ã表ãå¼
- å ´ååãå¦ç
- åé¡ã®è¨è¿°
- å®ä¾ å ¼ ãã³ã
æ¨ãæä½ããé¢æ°é
以ä¸ããæ¨ãã¨ããããªã¼ãã¨è¨ã£ããããããã¯é£ããããºã«ã ãåãæ¥ãç´¹ä»ãã«æ¸ããã©ãã«ãªããåæ¨ã®ãã¨ã§ãã
åºæ¬çã«ã¯ãã³ã¡ã³ãæ¬ã«æ¸ãã次ã®ãã¨ããããºã«ã®ã«ã¼ã«ã¨ãã¦æ¡ç¨ãã¾ãã
ãã³ãã¬ã¼ããããªãã¦ã次ã®ããã«è¨ã£ã¦ãããããããã¾ãããé¢æ°ã£ã½ãè¨èªã§ã¢ã«ã´ãªãºã ãæ¸ããã¨ã«ãã¦ã使ã£ã¦ããé¢æ°ã¯ï¼
- ããªã¼ã®å·¦ã®æãåãåºãé¢æ°ï¼åä¸ãã¼ãã®æ¨ã§ã¯æªå®ç¾©ï¼
- ããªã¼ã®å³ã®æãåãåºãé¢æ°
- ããªã¼ãåä¸ãã¼ããã©ãããå¤å®ããè¿°èª
- ã¿ãã«ã®åæåãåãåºãå°å½±é¢æ°
- å·¦æã¨å³æããããªã¼ãä½ãé¢æ°ï¼ãã¼ã1åå¢ããï¼
- æåéããã¿ãã«ãæ§æããé¢æ°
ããã ãã§ããããªã¼å®æ°ã¯ä½¿ãæ¾é¡ããã¨ã¯ã¤ã³ã¼ã«ãæ¡ä»¶åå²ãªã©ã使ã£ã¦æ¸ãã¦ãã ããã
ãããã®é¢æ°éãããå°ã詳ãã
ç¹å®ã®ããã°ã©ãã³ã°è¨èªã使ãã¨ããã¤ã¢ã¹ãçããããªã®ã§ãæ½è±¡çãªè¨æ³ã§æ¼ãéããã¨ã«ãã¾ãã以ä¸ã§ã¯ãã¤ã³ã¼ã«è¨å·ã¯ãçããããã¾ãã¯ã左辺ãå³è¾ºã§å®ç¾©ãããã¨ããæå³ã§ä½¿ãã¾ãã
æ¨å ¨ä½ã®éåãTã¨ãã¾ããtâT ã¯ãtã¯æ¨ã§ãããã¨åãã§ãããã¼ã1åã ãã®æ¨ãåãã¼ãæ¨ã¨å¼ã¶ãã¨ã«ãã¦ãè¨å·Îµã§è¡¨ãã¾ããεã¯å®æ°ã§ããä¸è¬ã«ãf:XâY ã¯ãfãéåXããéåYã¸ã®å ¨åçã«å®ç¾©ãããé¢æ°ï¼ååï¼ã§ãããã¨ã示ãã¾ããf:XââY ã¯ãfãé¨åé¢æ°ï¼å ¨åã§å®ç¾©ããã¦ããã¨ã¯éããªãï¼ã§ãããã¨ã表ãããã«ä½¿ãã¾ããããfããã¾ãã¾å ¨åã®ã¨ãã« f:XââY ã¨æ¸ãã¦ãééãã§ã¯ããã¾ããã
2å¼æ°ã®é¢æ°ã¨ã1åã®2-ã¿ãã«ãå¼æ°ã¨ããé¢æ°ã¯ãæ°å¦ã§ã¯ããã¦ãåºå¥ããã¾ãã*1ããããã°ã©ãã³ã°è¨èªã§ã¯åºå¥ããããã¨ãããã®ã§ãf:X,XâYãf':X2âY ã®ããã«åºå¥ãããã¨ã«ãã¾ãã
åã®ç¯ã§æããé¢æ°éã«ååãä»ãã¦ãåï¼domainï¼ã¨ä½åï¼codomainï¼ãããããªããã¾ããããã°ã«ã¼ãã³ã°ãä¸é©åã«æããã®ã§ãä¸ã¨é çªã¯å¤ãã¦ãã¾ãã
ãã¨ã®çªå· | é¢æ° | 説æ |
---|---|---|
1 | left : T ââ T | æ¨ã®å·¦ã®æãåãåºã |
2 | right : T ââ T | æ¨ã®å³ã®æãåãåºã |
5 | cons : T, T â T | å·¦æã¨å³æããæ¨ãä½ã |
3 | is_single : T â {true, false} | æ¨ãåãã¼ãæ¨ãã©ãããå¤å®ãã |
4 | proj<n>_<i> : Tn â T | ã¿ãã«ã®åæåãåãåºã |
6 | tuple<n> : T, ..., T â Tn | æåéããã¿ãã«ãæ§æãã |
is_single(t) ã¯ãªãã¦ããçå¼ t = ε ã§ä»£ç¨ã§ãã¾ãï¼ãªã®ã§ããåºã¦ãã¾ãã^^;ï¼ãtuple<n>ã¨proj<n>_<i>ã¯ãtuple3, proj3_1, proj3_2, proj3_3 ãªã©ãç·ç§°çã«è¡¨ãããã®ã§ããpair = tuple2ãp = proj2_1ãq = proj2_2 ã®3ã¤ã ãã§éã«åãã¾ããããããã§ã¯ tuple<n>, proj<n>_<i> æ¹å¼ã«ãã¾ãï¼è¶£å³çãªé¸æï¼ã
ããã«ããå°ãè£è¶³
Tããåãã¼ãæ¨Îµãåãé¤ããéåãTÎã¨ãã¾ããè¨å·Îã§ãå·¦å³ã®æãã¡ãã伸ã³ã¦ããé°å²æ°ãåºããã¤ãããå½ç¶ã«ãT = {ε}âªTÎ ã§ãããå ±éé¨åããªãéåã®åä½µã¯è¨å·ã+ãã使ã£ã¦æ¸ããç´åã¨å¼ã¶ã®ãç¿æ £ã§ãããã£ã¦ãT = {ε} + TÎãããã«ãI = {ε} ã¨ç´æãã¦ãT = I + TÎ ã¨ãªãã¾ãã
leftã¨rightã¯é¨åé¢æ°ã§ããããTÎã«å¶éããã°å ¨åé¢æ°ã§ããã¤ã¾ããleft : TÎ â Tãright : TÎ â T ã¨ã¿ãªãã¾ããleft(ε)ãright(ε) ã¯æªå®ç¾©ã§ããã便å®ä¸ left(ε) = undefãright(ε) = undef ã¨æ¸ããã¨ã«ãã¾ããããã°ã©ãã³ã°ã¨ãã¦ã¯ãundefã¯ä¾å¤ãæãããã¨ã ã¨è§£éããã®ãããã¨æãã¾ã -- ç¹æ®ãªå¤ã ã¨ãã¦ããããã©ãæ±ããé¢åã
ç¾å®çã«ã¯ãæ£ä½ä¸æã®ã¢ãxã«å¯¾ãã¦*2ããããæ¨ãã¿ãã«ã§ãããã©ãããå¤æããããã¨ãããã®ã§ãis_tree(x)ãis_tuple2(x) ã®ãããªè¿°èªã使ã£ã¦ããã¨ãã¾ãã
éåTã®å¸°ç´çå®ç¾©ã¨æ¨ã表ãå¼
åã ã®æ¨ãå ·ä½çã«ç¤ºãããã«ãæ¨ã®ãªãã©ã«è¡¨è¨ãããã¨ä¾¿å©ã§ãããæ¸ãã®ãé¢åãªã®ãææ ¢ããã°ãé¢æ°ã®çµã¿åããã§åã ã®æ¨ã表ãã¾ãã
- å®æ°Îµã¯æ¨ã表ãã¾ãã
- s, tãæ¨ã表ãå¼ã®ã¨ããcons(s, t)ã¯æ¨ã表ãã¾ãã
- ããã§ãã¹ã¦ã®æ¨ã表ããã¨ãã§ãã¾ãã
ä¾ãæããã°ãcons(ε, cons(ε, ε)) ã¨ã cons(cons(ε, cons(ε, ε)), cons(ε, ε)) ã¨ãã
ãã®è¡¨è¨ã使ã£ã¦ left, right ãå®ç¾©ããã°ã
- left(ε) = undef
- left(cons(s, t)) = s
- right(ε) = undef
- right(cons(s, t)) = t
å®æ°Îµãé¢æ°cons, left, rightãèªç±ã«ä½¿ã£ã¦çµã¿ç«ã¦ãå¼ã¯ããªãããã®æ¨ã表ããæªå®ç¾©ï¼ä¾å¤ï¼ã¨ãªãã¾ãããã®ãããªå¼ãæ¨ã表ãå¼ã¨å¼ã¶ãã¨ã«ãã¾ãã
å ´ååãå¦ç
E1ãE2ã¯æ¨ã表ãå¼ã ã¨ãã¾ããE1 = E2 ï¼çå¼ï¼ ã¯çå½å¤ã¾ãã¯undefãå¤ã¨ãã¦æã¡ã¾ã*3ãAND, OR, NOT ãèªç±ã«ä½¿ç¨ãã¦ãæ¨ã«é¢ããæ¡ä»¶ãè¨è¿°ã§ãã¾ããEãä½ã表ããä¸æã®ã¨ãã¯ãis_tree(E), is_tuple2(E) ãªã©ã®è¿°èªã使ã£ã¦ããã§ãã
ãã¦ãå ´ååãå¦çã¨ã¯ããtãæ¨ã«é¢ããæ¡ä»¶ãæºãããªããããã«ãããã¨ããè¨è¿°ã並ã¹ããã®ã§ãif-then-elseæãcaseæãä¸é å¼ï¼æ¡ä»¶? å¼1 : å¼2ï¼ã®ãããªãã®ã§ãã
åé¡ã®è¨è¿°
Seven Treesã®åé¡ã¯ãä¸ã§åæããé¢æ°ã®çµã¿åããã¨å ´ååãå¦çã«ãããéåTã¨éåT7ï¼é·ã7ã®ã¿ãã«ã®éåï¼ã®ããã ã®1:1対å¿ãä½ãã£ã¦ãã¨ã§ãã
ããã°ã©ãã³ã°è¨èªã§å®è£ ããã¨ãã¯ããã¹ã¦ã®é¢æ°ãã»ãã¨ã«å®ç¾©ããå¿ è¦ã¯ããã¾ãããäºåæ¨ã®ãã¿ã¼ã³ãããã使ããè¨èªãªããleft, rightãªãã¦ä¸è¦ã§ããæ¨ããªãã¸ã§ã¯ãã§æ¸ããªããt.left, t.right ã¨ãããã£ã¼ã«ãã§ãããã§ããããå¤ã®ä¸¦ã³ããã¿ãã«ãæé»ã«ä½ã£ã¦ãããè¨èªãªããtuple<n>ãè¦ããªãã§ããããproj<n>_<i>ãã¤ã³ããã¯ã¹ã¨ãã§ä»£ç¨ã§ãã¾ãããã®è¾ºã¯æè»ã«èãã¦ãã ããã
å®ä¾ å ¼ ãã³ã
T 㨠I + T2 ã®ååï¼1:1対å¿ï¼ãä½ã£ã¦ã¿ã¾ããå ´ååãã¯ä¸é å¼ã§æ¸ããã¨ã«ãã¾ããï¼ã:=ãã¯å®ç¾©ãããã=ãã¯çããã®æå³ï¼
// T --> I + T^2 ã®æ¹å
decompose(t) :=
t = ε ? ε :
tuple2(left(t), right(t))// I + T^2 --> T ã®æ¹å
compose(x) :=
x = ε ? ε :
// xã¯é·ã2ã®ã¿ãã«
cons(proj2_1(x), proj2_2(x))
[追è¨]KeisukeNakanoããã®ã³ã³ã«ããã³ã(?)ãè¼ã£ã¦ãã¾ãã[/追è¨]
*1:è¤åï¼multicategoryï¼ãå¤åï¼polycategoryï¼ã®è°è«ã§ã¯åºå¥ããã¾ãã
*2:ã»ãã¨ã«æ£ä½ä¸æã¨ããããã§ã¯ãªãã¦ãããªã¢ã³ããªå¤ã§ãã
*3:undefãä¾å¤ã¨ãã¦å®è£ ãããªãããçå½å¤ã¾ãã¯undefãå¤ã¨ãã¦æã¤ãã¯ãè¨ç®ãæåãã¦å¤ãçå½å¤ã¨ãªãããã¾ãã¯å¤±æãã¦ä¾å¤ãæãããããã¨ã§ãã