Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Prologでλ→の型検査のプロ グラムを書いてみただけの話

Prologでλ→の型検査のプロ グラムを書いてみただけの話

ProofSummit 2016 発表予定資料

SUHARA Hiromichi

June 22, 2016
Tweet

More Decks by SUHARA Hiromichi

Other Decks in Programming

Transcript

  1. 5"1-ͷUZQFPGؔ਺ typeof : context ! term ! ty ྫɿtypeof []

    λx:Nat.(x+1) ὎ Nat!Nat ίϯςΩετͱЕࣜʢterm) Λೖྗͯ͠ɺͦͷܕ Λग़ྗ͢Δؔ਺ʢܕ෇͚Λ͢Δؔ਺ʣ ୈ10ষ ୯७ܕͷML࣮૷ ୈ17ষ ෦෼ܕ෇͚ͷML࣮૷ ୈ25ষ System FͷML࣮૷ ίϯςΩετɿม਺ͱͦͷܕͷ૊ 
  2. ཁࢫ ᶃTAPL ୈ10ষͷ typeof ΛPrologʹҠ২͢Δɻ ᶄde BruijnදݱͰͳ͘ɺ௨ৗͷЕࣜΛ࢖͏ɻ ᶅͪΐͬͱ֦ͨ͠ுɿ ͋.ɹܕએݴΛল͍ͯ΋ɺPrologͷʮ૒ํ޲ੑʯ Ͱਪ࿦Ͱ͖ΔɻЕࣜͷͳ͔ͷܕ஫ऍ

    ʢʮЕx:T.Eʯͷ TʣΛল͘͜ͱ͕Ͱ͖Δɻ ͍.ɹܕݕ͕ࠪܕ෇͚ͱಉ͡ίʔυʹͳΔɻܕݕ ࠪΛܕ෇͚ͷ݁Ռͱൺֱ͢Δ͜ͱͰߦ͏৔߹ ʢTAPLʣΑΓ΋ɺਂ͍?ݕ͕ࠪͰ͖Δɻ 
  3. ϓϩάϥϛϯάݴޠ1SPMPH ᶃ 130HSBNJO-0(JDɻ࿦ཧܕϓϩάϥϛϯάݴޠ ᶄ ܕ͸ͳ͍ɻ-JTQ૬౰ɻ ᶅ ୈҰ֊ड़ޠ࿦ཧʢϗʔϯઅʣͷఆཧͷূ໌Λϓϩ άϥϜͷ࣮ߦͱΈͳ͢ݴޠͰ͋Δɻ ఆཧূ໌ܥͱݟͨͱ͖ɺ݈શ͕ͩ׬શͰ͸ͳ͍ɻ ূ໌ઓུ͕ਂ͞༏ઌ͚ͩͳͷͰɺ୳ࡧ͕ࢭ·Βͳ͍ɺূ໌͕ऴΘΒͳ͍৔߹͕͋Δɻ

    ࣮͸ɺ݈શੑ΋৚݅෇͖ʢޙड़ʣɻ ᶆ ϢχϑΟέʔγϣϯͱόοΫτϥοΫʹجͮ͘ݴ ޠͰ͋Δɻ͜ΕʹΑΓʮ૒ํ޲ੑʯΛ࣮ݱ͢Δɻ ᶇ ୯ʹ1SPMPHͱ͍ͬͨͱ͖ɺ*40ඪ४1SPMPH %&$1SPMPH·ͨ͸&EJOCVSHI 1SPMPHͷޙܧݴޠॲཧܥ Λࢦ͢ɻࠓճ͸෭࡞༻΍ߴ֊ड़ޠ͸࢖༻͠ͳ͍ɻ ॲཧܥͷྫɿ w 48*1SPMPH ΞϜεςϧμϜେֶ ΞϜεςϧμϜࣗ༝େֶ  w (/61SPMPH %BOJFM%JB[ ύϦୈେֶ  w ";1SPMPH ιϑωοΫגࣜձࣾɺݸਓͱڭҭɾݚڀػؔ͸ແঈར༻Մೳ 
  4. ༻ޠͱදه ᶃ ఆ਺ ɿ খจࣈ͔Β࢝·Δɻ·ͨ͸ɺ਺஋ɻ ᶄ ม਺ ɿ • େจࣈ͔Β࢝·Δɻ

    • ʮ_ʯ͔Β࢝·Δɻ • ιʔείʔυͰ͸ɺϫΠϧυΧʔυɻ • ग़ྗͰ͸ະఆม਺Ͱɺ஋ΛܾఆͰ͖ͳ͔ͬͨ͜ͱΛࣔ͢ɻ ྫ:_G1167ɻͨͩ͠ɺಉ͡஋͸ಉ໊͡લʢ൪߸ʣʹͳΔɻ ᶅ ड़ޠɿ ड़ޠه߸ͷ͜ͱɻp(X, Y)ͷp͸ఆ਺Ͱ͋Δ͜ͱɻ ᶆ ؔ਺ɿ ؔ਺ه߸ͷ͜ͱɻf(X, Y)ͷf͸ఆ਺Ͱ͋Δ͜ͱɻ f͸ϢχϑΟέʔγϣϯͷର৅Ͱ͋Γɺσʔλߏ଄ͷίϯετϥΫλɻείʔϨϜؔ਺ɻ ᶇ અɿ P :- Q, R. (P :- true. ͸ P. ͱॻ͘) ᶈ ΰʔϧɿ ?- P, Q. ᶉ Ϧετɿɹɹ[X, y, z] [x, y | Z] % OCamlͰ͸ɺ x :: y :: Z ɹɹɹɹ[]ɹɹɹɹɹɹɹɹ % nil ᶊ X = Yɹɿ ม਺XͱY͕ϢχϑΟέʔγϣϯ͢Δɻ2߲໨ԋࢉࢠʮ=ʯ͸૊ࠐΈड़ޠɻ ᶋ true ৗʹ੒ޭ͢Δɺͭ·ΓਅͰ͋Δड़ޠɻ ᶌ false ৗʹࣦഊ͢Δɺͭ·ΓِͰ͋Δड़ޠɻ ᶍ fail ৗʹࣦഊ͢Δɺͭ·ΓِͰ͋Δड़ޠɻfalseͱಉ͡ɻ ᶎ ༧໿ޠ͸ͳ͍ɻtrue΍fail͸૊ࠐΈड़ޠɻ ᶏ ίϝϯτ %͔Βߦ຤ ·ͨ͸ɺ /* ͱ */Ͱғ·ΕΔൣғɻ 
  5. ϖΞϊ਺ͷՃࢉ add(X, Y, Z) ͸ɹX + Y = Zɹ add(0,

    Y, Y). add(s(X), Y, s(Z)) :- add(X, Y, Z). ࣮ߦྫɿ ?- add(s(s(0)), s(s(s(0))), Z). % 2 + 3 = Z Z = s(s(s(s(s(0))))). ɹɹɹɹɹɹɹɹɹɹ% Z = 5 ?- add(s(s(0)), s(s(s(0))), s(s(s(s(s(s(0))))))). % 2 + 3 = 5 true. % ਖ਼͍͠ɻ ?- add(s(s(s(0))), Y, s(s(s(s(s(s(0))))))). % 2 + Y = 5 Y = s(s(s(0))).ɹɹɹɹɹɹɹɹɹɹɹɹɹ % Y = 5 ?- add(X, s(s(0)), s(s(s(s(s(s(0))))))). % X + 3 = 5 X = s(s(s(s(0)))) . % X = 5 ?- add(X, Y, s(s(s(s(s(s(0))))))). % X + Y = 5 X = 0, Y = s(s(s(s(s(s(0)))))) ; % X = 0 ͔ͭ Y = 5 X = s(0), Y = s(s(s(s(s(0))))) ; % X = 1 ͔ͭ Y = 4 X = s(s(0)), Y = s(s(s(s(0)))) ; % X = 2 ͔ͭ Y = 3 X = s(s(s(s(0)))), Y = s(s(0)) ; % X = 3 ͔ͭ Y = 2 X = s(s(s(s(s(0))))), Y = s(0) ; % X = 4 ͔ͭ Y = 1 X = s(s(s(s(s(s(0)))))), Y = 0 ; % X = 5 ͔ͭ Y = 0 false. % ΋͏ղ͸ͳ͍ɻ -- Haskellʢ෩ʣ add 0 Y = Y add (s X) Y = s (add X Y) ·ͨ͸ add (s X) Y = let Z = (add X Y) in (s Z) 
  6. NFNCFSड़ޠ ͦͷ a͕Ϧετlʹؚ·ΕΔ͔ʁ ?- member(a, l). member(X,[X | _]). member(X,[_

    | L]):- member(X,L). Ϧετ͕ [1, 2, 3] ͷͱ͖ɺ • 2͸Ϧετʹؚ·ΕΔ͔ʁ ͸੒ޭ͢Δɻ ?- member(2, [1, 2, 3]). true. • 4͸Ϧετʹؚ·ΕΔ͔ʁ ͸ࣦഊ͢Δɻ ?- member(4, [1, 2, 3]). false. -- Haskellʢ෩ʣ member a [] = False member a (x : l) | a == x = True | otheriwze = member a l  • ద౰ͳʢ㱽ʣཁૉ͕Ϧετʹؚ·ΕΔ͔ʁ ?- member(X, [1, 2, 3]). X = 1; X = 2; X = 3; false.
  7. NFNCFSड़ޠ ͦͷ ࿈૝Ϧετ (1) Ωʔbͷ஋͸2͔ʁ ?- member((b : 2), [(a

    : 1), (b : 2), (c : 3)]). true. (2) Ωʔbͷ஋͸1͔ʁ ?- member((b : 1), [(a : 1), (b : 2), (c : 3)]). false. (3) Ωʔbͷ஋͸ʁ ?- member((b : B), [(a : 1), (b : 2), (c : 3)]). B = 2 . (4) ஋͕ܾ·͍ͬͯͳ͍৔߹ɺΩʔb͕஋2͔ʁ ?- member((b : 2), [(a : 1), (b : Y), (c : 3)]). Y = 2 . (5) ஋͕ܾ·͍ͬͯͳ͍৔߹ɺΩʔb͕஋1͔ʁ ?- member((b : 2), [(a : 1), (b : Y), (c : 3)]). Y = 1 . (6) ஋͕ܾ·͍ͬͯͳ͍৔߹ɺΩʔ஋͸ʁ ?- member((b : B), [(a : 1), (b : Y), (c : 3)]). B = Y .  ஫ҙɿ(4)΍(5)ͷ৔߹ɺίϯςΩετ͕ॻ͖ ׵͑ΒΕΔɺͱߟ͑ͯ΋Α͍͕ɺPrologࣗମ ʹ͸෭࡞༻͸ແ͍ͨΊɺίϯςΩετΛ֨ೲ͢ Δม਺ͷࢦ͢ʢҾ͖ճ͞ΕΔʣϦετ্ͰϢχ ϑΟέʔγϣϯͷ݁Ռ஋͕ઃఆ͞ΕΔɻ άϩʔόϧͳσʔλΛॻ͖׵͑ΔΑ͏ͳσʔλ ϕʔεॲཧͰ͸ͳ͍ɻ ิ଍આ໌ɿΩʔͷॏෳ͕͋ͬͨ৔߹ɺόοΫτ ϥοΫʹΑͬͯෳ਺ղΛ΋ͱΊͯ͠·͏ɻͨͩ ͠ɺࠓճͷ࿩୊Ͱ͸ͦΕ͸ى͖ͳ͍ͨΊɺলུ ͢Δɻ
  8. NFNCFSड़ޠ ͦͷ HFU5ZQF'SPN$POUFYU ௨ৗͷЕࣜͷ৔߹ɺίϯςΩετ͸࿈૝ϦετͰ͋Δɻ ࿈૝ϦετCTX ͔Βɺม਺XͷܕTΛٻΊΔɻ ม਺໊ΛΩʔͱͯ͠ɺม਺ͷܕΛ࿈૝͢Δɻ getTypeFromContext(CTX, X, T)

    :- member((X : T), CTX). ίϯςΩετʢ࿈૝Ϧετʣͷྫɿ[(a : nat), (b : bool)] ม਺bͷܕΛٻΊͯΈΔɿ ?- getTypeFromContext([(a : nat), (b : bool)], b, T). ?- member((b : T), [(a : nat), (b : bool)]). T = bool. 
  9. 5"1-ͷUZQFPGΛҠ২ɹʢͦͷʣ ܕ෇͚ର৅ͷ߲ɿ λx.y tm_abs(x, y) ܕ஫ऍͷͳ͍Еந৅ λx:T.y tm_abs(x:T, y) ܕ஫ऍͷ͋ΔЕந৅ɺʮ:ʯ͸தஔه๏

    f x tm_app(f, x) ద༻ x tm_var(x) ม਺ͷࢀর True tm_true ఆ਺ False tm_false ఆ਺ 0 0 1 1 2 2 ܕɿ t1!t2 t1->t2 ؔ਺ܕɺʮ->ʯ͸தஔه๏ɺӈ݁߹ Nat ty_nat ܕఆ਺ Bool ty_bool ܕఆ਺ ʮ:ʯΑΓʮ->ʯͷ༏ઌ౓͕ߴ͍ɻ 
  10. 5"1-ͷUZQFPGΛҠ২ɹʢͦͷʣ typeof(E, T) :- typeof([], E, T). typeof(CTX, tm_var(Tm), T)

    :- getTypeFromContext(CTX, Tm, T). typeof(CTX, tm_abs(Tm1:TyT1, Tm2), TyT1 -> TyT2) :- typeof([Tm1:TyT1 | CTX], Tm2, TyT2). typeof(CTX, tm_abs(Tm1 , Tm2), TyT1 -> TyT2) :- typeof([Tm1:TyT1 | CTX], Tm2, TyT2). typeof(CTX, tm_app(Tm1, Tm2), Ty12) :- typeof(CTX, Tm1, Ty11 -> Ty12), typeof(CTX, Tm2, Ty11). typeof(_, tm_true, ty_Bool). typeof(_, tm_false, ty_Bool). typeof(CTX, tm_if(T1, T2, T3), TyT2) :- typeof(CTX, T1, ty_Bool), typeof(CTX, T2, TyT12), typeof(CTX, T3, TyT12). typeof(_, 0, ty_Nat). typeof(_, 1, ty_Nat). typeof(_, 2, ty_Nat) ม਺͸ Tm_XͰ߲ɺTy_XͰܕΛࣔ͢ɻ͜Ε͸TAPLͱಉ͡ɻ ԼઢͷՕॴ͕TAPLͱҟͳΔɻܕ෇͚ର৅ʹ͓͍ͯɺЕͷ࣍ͷม਺ʢЕม਺ʣͷܕ஫ऍΛল͘͜ͱ͕Ͱ͖ΔɻTm1ͷܕͰ͋Δ TyT1 ͸ܕ෇͚ର৅ͷࣜʹݱΕͳ͍ɻͦͷ ৔߹Ͱ΋ɺίϯςΩετʹઃఆ͠ɺܕʢͷҰ෦ʣͱͯ͠ฦ͢͜ͱͰɺॲཧΛܧଓ͢ΔɻϢχϑΟέʔγϣϯʹΑ͍͔ͬͯͭܕ͕ܾ·Δ͔ɺ࠷ޙ·Ͱܾ·Βͳ͍ɻͦͷ৔ ߹Ͱ΋ɺಉ͡ܕ͕ಉ͡ม਺ʹϢχϑΟέʔγϣϯ͞ΕΔɻ 
  11. ࣮ߦྫɹʢͦͷͷʣ % λb:Bool->Nat. λa:Bool. b a ?- typeof(tm_abs(b:ty_Bool->ty_Nat, tm_abs(a:ty_Bool, tm_app(tm_var(b),tm_var(a)))),

    T). T = (ty_Bool->ty_Nat)->ty_Bool->ty_Nat .ɹ% (Bool->Nat)->Bool->Nat % λb:Bool->Nat. λa:Nat. b a ?- typeof(tm_abs(b:ty_Bool->ty_Nat, tm_abs(a:ty_Nat, tm_app(tm_var(b), tm_var(a)))), T). fail . % λb:Bool->Nat. λa. b a ?- typeof(tm_abs(b:ty_Bool->ty_Nat, tm_abs(a, tm_app(tm_var(b),tm_var(a)))), T). T = (ty_Bool->ty_Nat)->ty_Bool->ty_Nat . 
  12. ࣮ߦྫɹʢͦͷͷʣ % λb. λa:Nat. b a ?- typeof(tm_abs(b, tm_abs(a:ty_Bool, tm_app(tm_var(b),

    tm_var(a)))), T). T = (ty_Bool->_G225)->ty_Bool->_G225 . % λb. λa. b a : (Bool -> Nat) -> Bool -> Nat ?- typeof(tm_abs(b, tm_abs(a, tm_app(tm_var(b), tm_var(a)))), (ty_Bool->ty_Nat)->ty_Bool->ty_Nat). true . % λb. λa. b a ?- typeof(tm_abs(b, tm_abs(a, tm_app(tm_var(b), tm_var(a)))), T). T = (_G221->_G222)->_G221->_G222 . 
  13. ࣮ߦྫɹʢͦͷʣ ?- spy(typeof). % ϒϨʔΫϙΠϯτ ?- typeof(tm_abs(b:ty_Bool->ty_Nat, tm_abs(a:ty_Nat, % ؒҧ͍ʂ

    tm_app(tm_var(b), tm_var(a)))), T). * Call: (8) typeof(tm_abs(b:ty_Bool->ty_Nat, tm_abs(a:ty_Nat, tm_app(tm_var(b), tm_var(a)))), _G559) ? l * Call: (9) typeof([], tm_abs(b:ty_Bool->ty_Nat, tm_abs(a:ty_Nat, tm_app(tm_var(b), tm_var(a)))), _G559) ? l * Call: (10) typeof([b:ty_Bool->ty_Nat], tm_abs(a:ty_Nat, tm_app(tm_var(b), tm_var(a))), _G551) ? l * Call: (11) typeof([a:ty_Nat, b:ty_Bool->ty_Nat], tm_app(tm_var(b), tm_var(a)), _G560) ? l * Call: (12) typeof([a:ty_Nat, b:ty_Bool->ty_Nat], tm_var(b), _G568->_G560) ? l * Exit: (12) typeof([a:ty_Nat, b:ty_Bool->ty_Nat], tm_var(b), ty_Bool->ty_Nat) ? l * Call: (12) typeof([a:ty_Nat, b:ty_Bool->ty_Nat], tm_var(a), ty_Bool) ? l * Fail: (12) typeof([a:ty_Nat, b:ty_Bool->ty_Nat], tm_var(a), ty_Bool) ? l ?- typeof(tm_abs(b:ty_Bool->ty_Nat, tm_abs(a:ty_Bool, m_app(tm_var(b), tm_var(a)))), T). * Call: (8) typeof(tm_abs(b:ty_Bool->ty_Nat, tm_abs(a:ty_Bool, tm_app(tm_var(b), tm_var(a)))), _G1579) ? l * Call: (9) typeof([], tm_abs(b:ty_Bool->ty_Nat, tm_abs(a:ty_Bool, tm_app(tm_var(b), tm_var(a)))), _G1579) ? l * Call: (10) typeof([b:ty_Bool->ty_Nat], tm_abs(a:ty_Bool, tm_app(tm_var(b), tm_var(a))), _G1571) ? l * Call: (11) typeof([a:ty_Bool, b:ty_Bool->ty_Nat], tm_app(tm_var(b), tm_var(a)), _G1580) ? l * Call: (12) typeof([a:ty_Bool, b:ty_Bool->ty_Nat], tm_var(b), _G1588->_G1580) ? l * Exit: (12) typeof([a:ty_Bool, b:ty_Bool->ty_Nat], tm_var(b), ty_Bool->ty_Nat) ? l * Call: (12) typeof([a:ty_Bool, b:ty_Bool->ty_Nat], tm_var(a), ty_Bool) ? l * Exit: (12) typeof([a:ty_Bool, b:ty_Bool->ty_Nat], tm_var(a), ty_Bool) ? l * Exit: (11) typeof([a:ty_Bool, b:ty_Bool->ty_Nat], tm_app(tm_var(b), tm_var(a)), ty_Nat) ? l * Exit: (10) typeof([b:ty_Bool->ty_Nat], tm_abs(a:ty_Bool, tm_app(tm_var(b), tm_var(a))), ty_Bool->ty_Nat) ? l * Exit: (9) typeof([], tm_abs(b:ty_Bool->ty_Nat, tm_abs(a:ty_Bool, tm_app(tm_var(b), tm_var(a)))), (ty_Bool->ty_Nat)->ty_Bool->ty_Nat) ? l * Exit: (8) typeof(tm_abs(b:ty_Bool->ty_Nat, tm_abs(a:ty_Bool, tm_app(tm_var(b), tm_var(a)))), (ty_Bool->ty_Nat)->ty_Bool->ty_Nat) ? l 
  14. ૒ํ޲ͷϢχϑΟέʔγϣϯ ड़ޠݺͼग़࣌͠ͷҾ਺ͷ݁߹ɺ͓Αͼɺ ૊ࠐΈड़ޠʮ=ʯͷ྆ลͷؒͰɺ૒ํ޲ʹϢχ ϑΟέʔγϣϯ͕͓͖Δɻ Ҿ਺ʹʮೖྗʯͱʮग़ྗʯͷ۠ผ͕ͳ͍ɻʮ=ʯΛ୅ೖͱΈͳͨ͠ͱ͖ɺࠨลͱӈลͷ۠ ผ͕ͳ͍ɻ͞Βʹɺม਺ͱఆ਺Λࠞͥ߹Θͤͯͯ΋Α͍ɻ ʢྫ1ʣf(1, g(Y, U)) =

    f(X, g(2, Z)) X ͸ 1ɺY ͸ 2ɺ Z ͸ U ʹͳΔɻ ʢྫ2ʣ[X | Z] = [A, 2, C] X ͸ Aɺ Z ͸ [2, C] ʹͳΔɻ ʢྫ3ʣf(X) = X X ͸ f(f(f(f(f(f....))))) ʹͳΔɻ ʮX = Yʯͷ୅ΘΓʹɺunify_with_occurs_check(X, Y) Λ࢖͏ɻʢྫ3ʣͷΑ͏ ͳϢχϑΟέʔγϣϯ͸ࣦഊͤ͞Δ͜ͱͰېࢭ͢ΔɻOccurs Check ͱ͍͏ɻ ʢྫ3’ʣ unify_with_occurs_check(f(X), X) fail. set_prolog_flag(occurs_check, true). Λ࣮ߦ͢Δ͜ͱͰɺ͢΂ͯͷϢχϑΟέʔγϣϯͰOccurs CheckΛ͓͜ͳ͏͜ͱ ͕Ͱ͖Δɻͨͩ͠ɺΦʔόʔϔου͕૿͑ΔɻPrologͷ݈શੑ͸Occurs Check Λ͢Δ͜ͱΛ৚݅ͱ͍ͯ͠Δɻ 
  15. HFU5ZQF'SPN$POUFYUɹʢͦͷʣ % λx.(x x) ?- typeof(tm_abs(x, tm_app(tm_var(x), tm_var(x))), T). T

    =((……((_S1->_S1)->_S1)……->_S1)->_S1)->_S1 . ͋Δ͍͸ɺॲཧܥʹΑͬͯ͸ɺ T = _S1->_G488, % where _S1 = _S1->_G488 . ʮЕx.(x x)ʯ͸ܕ෇͚Ͱ͖ͳ͍͸ͣɻɻɻɻ ᶃ λx.(x x) ͷຊମ(x x)ͷશମͷܕΛT1ɺೋ൪໨ͷxͷܕΛTxͱ͢Δɻ ᶄ Ұ൪໨ͷxͷܕ͸Tx!T1͔ͩΒɺTx = Tx!T1 Ͱ͋Δɻ ᶅ xͷܕ͸ Tx ͔ͭ Tx!T1 ʹͳΔɻ͔͠͠ɺ͜Ε͸ܕͱ͓͔͍ͯ͠͠ɻ ᶆ ͓͔͍͠ܕ͕ಘΒΕͨɻɻɻɻPrologͷෆ݈શੑʂʂ 
  16. HFU5ZQF'SPN$POUFYUɹʢͦͷʣ ରࡦɿ Occures Check ΛೖΕΔɻ getTypeFromContext(CTX, X, T2) :- member((X

    : T1), CTX), unify_with_occurs_check(T1, T2). % λx.(x x) ?- typeof(tm_abs(x, tm_app(tm_var(x), tm_var(x))), T). fail. 
  17. ࢀߟจݙ [1] PierceஶɺॅҪ؂༁ɺԕ౻ଞ༁ ʮܕγεςϜೖ໳ ϓϩάϥϛϯάݴޠͱܕͷཧ࿦ʯΦʔϜࣾ [2] ϩΠυஶɺࠤ౻ଞ༁ ɹɹʮ࿦ཧϓϩάϥϛϯάͷجૅʯ࢈ۀਤॻ [3] ίϫϧεΩஶɺӜ؂༁ɺࢁాଞ༁

    ɹɹʮ࿦ཧʹΑΔ໰୊ͷղܾʯഓ෩ؗɹɹɹʢ஫ҙɿPrologͷຊͰ͸ͳ͍!ʣ [4] ాଜʮਆށେֶ Prolog ϗʔϜϖʔδʯ http://bach.istc.kobe-u.ac.jp/prolog/ [5] ஛Ԭʮ͚͓͔ͨͷ Prologϖʔδʯ http://www.takeoka.org/~take/ailabo/prolog/prolog-index.html 
  18. ॲཧܥ [1] SWI-Prolog http://www.swi-prolog.org [2] GNU Prolog ɹɹ http://www.gprolog.org [3]

    AZ-Prolog ιϑωοΫגࣜձࣾ https://az-prolog.com [4] K-Prolog גࣜձࣾKLSݚڀॴ http://www.kprolog.com [5] ޷͖͍ເ (ֶश༻Schemeॲཧܥ) http://homepage1.nifty.com/~skz/Scheme/ 
  19. "QQFOEJY A.1 de BruijnදݱΛ࢖͏৔߹ ίϯςΩετ͸഑ྻʹͳΔɻde Bruijn Index ͱͯ͠0͔Β࢖͏৔߹ɺ0͔Β ࢝·Δ഑ྻʹͳΔɻ nth0(N,

    L, T) ͸ɺϦετΛ0࢝·Γͷ഑ྻͱΈͳͯ͠ɺ(0͔Β਺͑ͯ)N൪Ί ͷཁૉΛฦ͢ɻmemberΛnth0ʹஔ͖׵͑Δɻ getTypeFromContext((X : T1), CTX) :- nth0(X, CTX, T2), unify_with_occurs_check(T1, T2). A.2 System F ΁ͷ֦ு http://qiita.com/suharahiromichi/items/9adc16a40ecb1bc36825 
  20. "QQFOEJY1SPMPHϓϩάϥϜͱ࿦ཧࣜ • ϗʔϯઅͷදه p(x, y) ← q(x, y), r(x, y)

    ֬ఆઅ s(x, y) ← true. ֬ఆઅʢ୯Ґઅʣ false ← g(x, y), h(x, y). ΰʔϧઅ • Prologͷදه p(x, y) :- q(x, y), r(x, y) s(x, y). ?- g(x, y), h(x, y). • ௨ৗͷ࿦ཧࣜʹม׵ͯ͠ΈΔɻͨͩ͠ɺp(x,y) Λ P ͷΑ͏ʹུ͢ɻ (1) ϗʔϯઅΛ࿦ཧࣜʹ௚༁͢ΔɻΰʔϧઅΛؚΉશମ͕ໃ६Ͱ͋Δ͜ͱɻ [∀x.∀y.(P ∨ ¬Q ∨ ¬R)] ∧ [∀x.∀y.(S ∨ ¬true)] ∧ [∀x.∀y.(false ∨ ¬G ∨ ¬H)] ⊢ false (2) ఆ߲Λফ͢ɻ [∀x.∀y.(P ∨ ¬Q ∨ ¬R)] ∧ [∀x.∀y.S] ∧ [∀x.∀y.(¬G ∨ ¬H)] ⊢ false (3) ֬ఆઅΛ P ∨ ¬Q 㱻 Q!P Ͱॻ͖׵͑ΔɻΰʔϧઅΛ υɾϞϧΨϯͷఆཧͰॻ͖׵͑Δɻ [∀x.∀y.(Q ∧ R ! P)] ∧ [∀x.∀y.S] ∧ ¬[∃x.∃y.(G ∧ H)] ⊢ false (4) ൱ఆͯ͠ɺ߃ਅͰ͋Δ͜ͱʹ͢Δɻ ⊢ ¬{[∀x.∀y.(Q ∧ R ! P)] ∧ [∀x.∀y.S] ∧ ¬[∃x.∃y.(G ∧ H)]} (5) શମʹυɾϞϧΨϯͷఆཧ ⊢ ¬{[∀x.∀y.(Q ∧ R ! P)] ∧ [∀x.∀y.S]} ∨ ¬¬[∃x.∃y.(G ∧ H)] (6) ΰʔϧઅʹೋॏ൱ఆআڈ ⊢ ¬{[∀x.∀y.(Q ∧ R ! P)] ∧ [∀x.∀y.S]} ∨ [∃x.∃y.(G ∧ H)] (7) શମΛ ¬Q ∨ P 㱻 Q!P Ͱॻ͖׵͑Δɻ ⊢ [∀x.∀y.(Q ∧ R ! P)] ∧ [∀x.∀y.S] ! [∃x.∃y.(G ∧ H)] (7) ΧδϡΞϧʹ͍͏ͱ ∀x.∀y.(Q ∧ R ! P) ͱ ∀x.∀y.S ͔Βɺ㱽x.∃y.(G ∧ H) ͕ಋ͔ΕΔɻ  member(X, [X | _]). member(X, [_ | L]) :- member(X, L). ?- member(X, [1, 2, 3]). ∀X.∀L.member(X, [X | L]) ∧ ∀X.∀Y.∀L.(member(X, L) ! member(X, [Y | L])) ! ∃X.member(X, [1, 2, 3]). forall x l, member x (x :: l) /\ forall x y l, member x l -> member x (y :: l) -> exists x, member x (1 :: 2 :: 3 :: nil).
  21. ূ໌໦ ?- member(2, [1, 2, 3]) ɹɹɹɹ/ ɹɹɹɹɹɹɹɹ \ member(2,

    [1 | _]) member(2, [_, 2, 3]) :- member(2, [2, 3]) | ɹɹɹɹɹɹɹɹɹɹɹɹ | ɹɹɹfail member(2, [2 | _]). ɹɹɹɹɹɹɹɹɹɹɹɹ | ɹ ɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹɹtrue.