SlideShare uma empresa Scribd logo
1 de 14
MaudeTerm Rewriting Logic簡単な紹介 2010/07/19 tmiya
Maude http://maude.cs.uiuc.edu/ Membership equational logic, Rewriting Logicに基づくプログラミング言語 OBJ系の仲間 宣言的。原理は明確でシンプルだが表現力は高い でもパフォーマンスも出る LTL -> Büchi automataの変換のJavaプログラムより3倍速かった 複数の用途 Deterministic:関数モジュール Concurrent, nondeterministic:システムモジュール OO:オブジェクトモジュール 何に使えるか プログラミング:DSL。宣言的プログラミング。 形式仕様記述:代数的仕様記述 モデル検査:停止性とかCR性とか色々
Maude 教科書 “All About Maude - A High-Performance Logical Framework: How to Specify, Program, and Verify Systems in Rewriting Logic” SpringerのLNCSシリーズ (2007) Maude 2 Primer : PDF(2003) A Maude Tutorial : PS(2000) インストール Core Maudeインストール Linux on Intel, MacOS on Intel -> 実行可能バイナリあり その他:ソースから頑張って Full Maude : Maudeで書かれている その他のツール Inductive Theorem Prover Maude Termination Tool : eq仕様の停止性 Church Rosser Checker : CR性の検査 Real-Time Maude : timed-rewriting, LTL, などなど。
Peano自然数(定義) Maude> fmod PEANO-NAT-EXTRA is	// 関数モジュール > sort Nat .										// sortは型とか集合みたいなもの > op 0 : -> Nat [ctor] .				// [ctor]はコンストラクタ > op s : Nat -> Nat [ctoriter] .	// [iter]は繰り返し有り > op _+_ : Nat Nat -> Nat .		// _でプレースホルダ > vars M N : Nat . > eq 0 + N = N .								// eqは書き換え規則 > eqs(M) + N = s(M + N) . > endfm Maude>
Peano自然数(簡約) Maude> set trace on .					// 変形をトレース表示 Maude> reduce s(0) + s(s(0)) . reduce in PEANO-NAT-EXTRA : s(0) + s^2(0) . *********** equation eqs(M) + N = s(M + N) . M --> 0 N --> s^2(0) s(0) + s^2(0) ---> s(0 + s^2(0)) *********** equation eq 0 + N = N . N --> s^2(0) 0 + s^2(0) ---> s^2(0) rewrites: 2 in 0ms cpu (0ms real) (9009 rewrites/second) result Nat: s^3(0) Maude>
タバコ(定義) Maude> mod CIGARETTE is			// モジュール > sort State . > op c : -> State [ctor] . *** cigarette > op b : -> State [ctor] . *** butt > op __ : State State -> State [ctor assoc comm] . > rl [smoke] : c => b .						// 状態遷移規則 > rl [makenew] : bbbb => c . > endm Maude>  [assoc comm] : 結合則、可換則 項書き換えの無限ループを避け、効率化するため、明示的に指定
タバコ(実行) rewrite [100] in CIGARETTE : cccccccccccccccc . *********** rule rlc => b [label smoke] . empty substitution c ---> b 中略 *********** rule rlbbbb => c [label makenew] . empty substitution ccccccccccccbbbb ---> (cccccccccccc) c 中略 *********** rule rlc => b [label smoke] . empty substitution c ---> b rewrites: 26 in 1ms cpu (1ms real) (14046 rewrites/second) result State: b Maude>
アーケードクレーン(定義) Maude> mod ARCADE-CRANE is > protecting QID . > sorts ToyID State . > subsortQid < ToyID . > op floor : ToyID -> State [ctor] . > op on : ToyIDToyID -> State [ctor] . > op clear : ToyID -> State [ctor] . > op hold : ToyID -> State [ctor] . > op empty : -> State [ctor] . > op 1 : -> State [ctor] . *** identity state > op _&_ : State State -> State [ctor assoc comm id: 1] . > vars X Y : ToyID . > rl [pickup] : empty & clear(X) & floor(X) => hold(X) . > rl [putdown] : hold(X) => empty & clear(X) & floor(X) . > rl [unstack] : empty & clear(X) & on(X,Y) => hold(X) & clear(Y) . > rl [stack] : hold(X) & clear(Y) => empty & clear(X) & on(X,Y) . > endm Maude>
アーケードクレーン(状態) Maude> search in ARCADE-CRANE : empty & floor('mothergoose) & on('teddybear, 'mothergoose) & on('soccerball, 'teddybear) & clear('soccerball) & floor('dragondude) & clear('dragondude) =>+ empty & floor('teddybear) & on ('mothergoose,'teddybear) & on('soccerball,'mothergoose) & clear('soccerball) & floor('dragondude) & clear('dragondude) . *********** rule rl empty & floor(X) & clear(X) => hold(X) [label pickup] . X --> 'dragondude empty & floor('dragondude) & floor('mothergoose) & clear('dragondude) & clear(     'soccerball) & on('soccerball, 'teddybear) & on('teddybear, 'mothergoose) ---> (floor('mothergoose) & clear('soccerball) & on('soccerball, 'teddybear) & on(     'teddybear, 'mothergoose)) & hold('dragondude) 中略 *********** rule rl empty & clear(X) & on(X, Y) => clear(Y) & hold(X) [label unstack] . X --> 'soccerball Y --> 'dragondude empty & floor('teddybear) & clear('soccerball) & on('dragondude, 'mothergoose)     & on('mothergoose, 'teddybear) & on('soccerball, 'dragondude) ---> (floor('teddybear) & on('dragondude, 'mothergoose) & on('mothergoose,     'teddybear)) & clear('dragondude) & hold('soccerball) No more solutions. states: 125  rewrites: 272 in 37ms cpu (391ms real) (7237 rewrites/second) Maude>
アーケードクレーン(状態) Maude> search in ARCADE-CRANE : empty & floor('mothergoose) & on('teddybear,'mothergoose) & on('soccerball,'teddybear) & clear('soccerball) & floor('dragondude) & clear('dragondude) =>+ empty & floor('teddybear) & floor('mothergoose) & clear('teddybear) & clear('mothergoose) & X:State . Solution 1 (state 10) states: 11  rewrites: 16 in 0ms cpu (0ms real) (49844 rewrites/second) X:State --> floor('dragondude) & clear('soccerball) & on('soccerball,     'dragondude) Solution 2 (state 15) states: 16  rewrites: 23 in 0ms cpu (0ms real) (40280 rewrites/second) X:State --> floor('dragondude) & floor('soccerball) & clear('dragondude) & clear('soccerball) Solution 3 (state 33) states: 34  rewrites: 54 in 1ms cpu (1ms real) (39560 rewrites/second) X:State --> floor('soccerball) & clear('dragondude) & on('dragondude,     'soccerball) No more solutions. states: 125  rewrites: 272 in 5ms cpu (5ms real) (50670 rewrites/second) Maude>  X
川渡しパズル(定義1) Maude> mod RIVER-CROSSING is > sorts Side Group . > ops left right : -> Side [ctor] . > op change : Side -> Side . > eqchange(left) = right . > eqchange(right) = left . > ops swlc : Side -> Group [ctor] . > op __ : Group Group -> Group [ctor assoc comm] . > var S : Side . > rl [shepherd] : s(S) => s(change(S)) . > rl [wolf] : s(S) w(S) => s(change(S)) w(change(S)) . > rl [lamb] : s(S) l(S) => s(change(S)) l(change(S)) . > rl [cabbage] : s(S) c(S) => s(change(S)) c(change(S)) . > endm
川渡しパズル(定義2) Maude> mod RIVER-CROSSING-PROP is > protecting RIVER-CROSSING . > including MODEL-CHECKER . > subsort Group < State . > op initial : -> Group . > eq initial = s(left) w(left) l(left) c(left) . > ops disaster success : -> Prop . > vars S S' S'' : Side . > ceq (w(S) l(S) s(S') c(S'') |= disaster) = true if S =/= S' . > ceq (w(S'') l(S) s(S') c(S) |= disaster) = true if S =/= S' . > eq (s(right) w(right) l(right) c(right) |= success) = true . > endm Maude>
川渡しパズル(実行) % ./maude.intelDarwin -interactive model-checker.maude Maude> red modelCheck(initial, > <> success -> (<> disaster /((success) U disaster))) . reduce in RIVER-CROSSING-PROP : modelCheck(initial, <> success -> <> disaster     /(success U disaster)) . rewrites: 76 in 1ms cpu (1ms real) (60995 rewrites/second) result ModelCheckResult: counterexample({s(left) w(left) l(left) c(left),'lamb}     {s(right) w(left) l(right) c(left),'shepherd} {s(left) w(left) l(right) c( left),'wolf} {s(right) w(right) l(right) c(left),'lamb} {s(left) w(right) l(left) c(left),'cabbage} {s(right) w(right) l(left) c(right),'shepherd} { s(left) w(right) l(left) c(right),'lamb} {s(right) w(right) l(right) c( right),'lamb} {s(left) w(right) l(left) c(right),'shepherd} {s(right) w(     right) l(left) c(right),'wolf} {s(left) w(left) l(left) c(right),'lamb} {s(     right) w(left) l(right) c(right),'cabbage} {s(left) w(left) l(right) c( left),'wolf}, {s(right) w(right) l(right) c(left),'lamb} {s(left) w(right) l(left) c(left),'lamb}) Maude>
触り始めたばかりだが Maudeは割と面白い 普通に項書き換え系プログラミングとして遊べる 例えば型無しλ計算とか、当たり前だけど書ける 違和感があるところ Subsorts Nat < NeList < List Nat は要素1個の (Nat)のList である!

Mais conteúdo relacionado

Mais procurados

CFD for Rotating Machinery using OpenFOAM
CFD for Rotating Machinery using OpenFOAMCFD for Rotating Machinery using OpenFOAM
CFD for Rotating Machinery using OpenFOAM
Fumiya Nozaki
 
The mighty js_function
The mighty js_functionThe mighty js_function
The mighty js_function
timotheeg
 

Mais procurados (13)

CFD for Rotating Machinery using OpenFOAM
CFD for Rotating Machinery using OpenFOAMCFD for Rotating Machinery using OpenFOAM
CFD for Rotating Machinery using OpenFOAM
 
LLVM Backend の紹介
LLVM Backend の紹介LLVM Backend の紹介
LLVM Backend の紹介
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScript
 
What is recursion?
What is recursion? What is recursion?
What is recursion?
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++
 
The Power of CSS
The Power of CSSThe Power of CSS
The Power of CSS
 
Implementing pattern-matching in JavaScript (full version)
Implementing pattern-matching in JavaScript (full version)Implementing pattern-matching in JavaScript (full version)
Implementing pattern-matching in JavaScript (full version)
 
Show innodb status
Show innodb statusShow innodb status
Show innodb status
 
Extreme JavaScript Performance
Extreme JavaScript PerformanceExtreme JavaScript Performance
Extreme JavaScript Performance
 
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
TMPA-2017: Predicate Abstraction Based Configurable Method for Data Race Dete...
 
The mighty js_function
The mighty js_functionThe mighty js_function
The mighty js_function
 
Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++
 
JDD2015: Frege - Introducing purely functional programming on the JVM - Dierk...
JDD2015: Frege - Introducing purely functional programming on the JVM - Dierk...JDD2015: Frege - Introducing purely functional programming on the JVM - Dierk...
JDD2015: Frege - Introducing purely functional programming on the JVM - Dierk...
 

Destaque

プログラミング・パラダイム
プログラミング・パラダイムプログラミング・パラダイム
プログラミング・パラダイム
Yusuke Matsushita
 

Destaque (7)

カークマンの女学生問題と有限幾何
カークマンの女学生問題と有限幾何カークマンの女学生問題と有限幾何
カークマンの女学生問題と有限幾何
 
代数的実数とCADの実装紹介
代数的実数とCADの実装紹介代数的実数とCADの実装紹介
代数的実数とCADの実装紹介
 
Shibuya.lisp #28: 仮題: R について
Shibuya.lisp #28: 仮題: R についてShibuya.lisp #28: 仮題: R について
Shibuya.lisp #28: 仮題: R について
 
プログラミング・パラダイム
プログラミング・パラダイムプログラミング・パラダイム
プログラミング・パラダイム
 
NPC April Fool's Contest 2014 累乗数
NPC April Fool's Contest 2014 累乗数NPC April Fool's Contest 2014 累乗数
NPC April Fool's Contest 2014 累乗数
 
Haskell超入門 Part.1
Haskell超入門 Part.1Haskell超入門 Part.1
Haskell超入門 Part.1
 
数学プログラムを Haskell で書くべき 6 の理由
数学プログラムを Haskell で書くべき 6 の理由数学プログラムを Haskell で書くべき 6 の理由
数学プログラムを Haskell で書くべき 6 の理由
 

Semelhante a Maude20100719

Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3
guesta3202
 
Yahoo! Mail antispam - Bay area Hadoop user group
Yahoo! Mail antispam - Bay area Hadoop user groupYahoo! Mail antispam - Bay area Hadoop user group
Yahoo! Mail antispam - Bay area Hadoop user group
Hadoop User Group
 
Laboratory Report Sample
Laboratory Report SampleLaboratory Report Sample
Laboratory Report Sample
Markus Flicke
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
alish sha
 

Semelhante a Maude20100719 (20)

What you forgot from your Computer Science Degree
What you forgot from your Computer Science DegreeWhat you forgot from your Computer Science Degree
What you forgot from your Computer Science Degree
 
Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3Erlang Introduction Bcberlin3
Erlang Introduction Bcberlin3
 
Python And GIS - Beyond Modelbuilder And Pythonwin
Python And GIS - Beyond Modelbuilder And PythonwinPython And GIS - Beyond Modelbuilder And Pythonwin
Python And GIS - Beyond Modelbuilder And Pythonwin
 
Oscon 2010 Specs talk
Oscon 2010 Specs talkOscon 2010 Specs talk
Oscon 2010 Specs talk
 
Macro
MacroMacro
Macro
 
05-Debug.pdf
05-Debug.pdf05-Debug.pdf
05-Debug.pdf
 
zen and the art of SQL optimization
zen and the art of SQL optimizationzen and the art of SQL optimization
zen and the art of SQL optimization
 
Introduction To Lisp
Introduction To LispIntroduction To Lisp
Introduction To Lisp
 
Prototype js
Prototype jsPrototype js
Prototype js
 
Osol Pgsql
Osol PgsqlOsol Pgsql
Osol Pgsql
 
Functional Gradient Boosting based on Residual Network Perception
Functional Gradient Boosting based on Residual Network PerceptionFunctional Gradient Boosting based on Residual Network Perception
Functional Gradient Boosting based on Residual Network Perception
 
Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....Scala + WattzOn, sitting in a tree....
Scala + WattzOn, sitting in a tree....
 
Yahoo! Mail antispam - Bay area Hadoop user group
Yahoo! Mail antispam - Bay area Hadoop user groupYahoo! Mail antispam - Bay area Hadoop user group
Yahoo! Mail antispam - Bay area Hadoop user group
 
Scala en
Scala enScala en
Scala en
 
Beholding the giant pyramid of application development; why Ajax applications...
Beholding the giant pyramid of application development; why Ajax applications...Beholding the giant pyramid of application development; why Ajax applications...
Beholding the giant pyramid of application development; why Ajax applications...
 
Laboratory Report Sample
Laboratory Report SampleLaboratory Report Sample
Laboratory Report Sample
 
The_ERICSSON_commands_listed_below_are_f (1) (1).pdf
The_ERICSSON_commands_listed_below_are_f (1) (1).pdfThe_ERICSSON_commands_listed_below_are_f (1) (1).pdf
The_ERICSSON_commands_listed_below_are_f (1) (1).pdf
 
SICP勉強会について
SICP勉強会についてSICP勉強会について
SICP勉強会について
 
Python and sysadmin I
Python and sysadmin IPython and sysadmin I
Python and sysadmin I
 
Bti1022 lab sheet 8
Bti1022 lab sheet 8Bti1022 lab sheet 8
Bti1022 lab sheet 8
 

Mais de tmiya (10)

Coq for ML users
Coq for ML usersCoq for ML users
Coq for ML users
 
Proofsummit2011a
Proofsummit2011aProofsummit2011a
Proofsummit2011a
 
Coq Tutorial at Proof Summit 2011
Coq Tutorial at Proof Summit 2011Coq Tutorial at Proof Summit 2011
Coq Tutorial at Proof Summit 2011
 
Typeclass
TypeclassTypeclass
Typeclass
 
Coq Tutorial
Coq TutorialCoq Tutorial
Coq Tutorial
 
RegExp20110305
RegExp20110305RegExp20110305
RegExp20110305
 
Coq setoid 20110129
Coq setoid 20110129Coq setoid 20110129
Coq setoid 20110129
 
Coq Party 20101127
Coq Party 20101127Coq Party 20101127
Coq Party 20101127
 
Formal methods20100529
Formal methods20100529Formal methods20100529
Formal methods20100529
 
Coq 20100208a
Coq 20100208aCoq 20100208a
Coq 20100208a
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Maude20100719

  • 2. Maude http://maude.cs.uiuc.edu/ Membership equational logic, Rewriting Logicに基づくプログラミング言語 OBJ系の仲間 宣言的。原理は明確でシンプルだが表現力は高い でもパフォーマンスも出る LTL -> Büchi automataの変換のJavaプログラムより3倍速かった 複数の用途 Deterministic:関数モジュール Concurrent, nondeterministic:システムモジュール OO:オブジェクトモジュール 何に使えるか プログラミング:DSL。宣言的プログラミング。 形式仕様記述:代数的仕様記述 モデル検査:停止性とかCR性とか色々
  • 3. Maude 教科書 “All About Maude - A High-Performance Logical Framework: How to Specify, Program, and Verify Systems in Rewriting Logic” SpringerのLNCSシリーズ (2007) Maude 2 Primer : PDF(2003) A Maude Tutorial : PS(2000) インストール Core Maudeインストール Linux on Intel, MacOS on Intel -> 実行可能バイナリあり その他:ソースから頑張って Full Maude : Maudeで書かれている その他のツール Inductive Theorem Prover Maude Termination Tool : eq仕様の停止性 Church Rosser Checker : CR性の検査 Real-Time Maude : timed-rewriting, LTL, などなど。
  • 4. Peano自然数(定義) Maude> fmod PEANO-NAT-EXTRA is // 関数モジュール > sort Nat . // sortは型とか集合みたいなもの > op 0 : -> Nat [ctor] . // [ctor]はコンストラクタ > op s : Nat -> Nat [ctoriter] . // [iter]は繰り返し有り > op _+_ : Nat Nat -> Nat . // _でプレースホルダ > vars M N : Nat . > eq 0 + N = N . // eqは書き換え規則 > eqs(M) + N = s(M + N) . > endfm Maude>
  • 5. Peano自然数(簡約) Maude> set trace on . // 変形をトレース表示 Maude> reduce s(0) + s(s(0)) . reduce in PEANO-NAT-EXTRA : s(0) + s^2(0) . *********** equation eqs(M) + N = s(M + N) . M --> 0 N --> s^2(0) s(0) + s^2(0) ---> s(0 + s^2(0)) *********** equation eq 0 + N = N . N --> s^2(0) 0 + s^2(0) ---> s^2(0) rewrites: 2 in 0ms cpu (0ms real) (9009 rewrites/second) result Nat: s^3(0) Maude>
  • 6. タバコ(定義) Maude> mod CIGARETTE is // モジュール > sort State . > op c : -> State [ctor] . *** cigarette > op b : -> State [ctor] . *** butt > op __ : State State -> State [ctor assoc comm] . > rl [smoke] : c => b . // 状態遷移規則 > rl [makenew] : bbbb => c . > endm Maude> [assoc comm] : 結合則、可換則 項書き換えの無限ループを避け、効率化するため、明示的に指定
  • 7. タバコ(実行) rewrite [100] in CIGARETTE : cccccccccccccccc . *********** rule rlc => b [label smoke] . empty substitution c ---> b 中略 *********** rule rlbbbb => c [label makenew] . empty substitution ccccccccccccbbbb ---> (cccccccccccc) c 中略 *********** rule rlc => b [label smoke] . empty substitution c ---> b rewrites: 26 in 1ms cpu (1ms real) (14046 rewrites/second) result State: b Maude>
  • 8. アーケードクレーン(定義) Maude> mod ARCADE-CRANE is > protecting QID . > sorts ToyID State . > subsortQid < ToyID . > op floor : ToyID -> State [ctor] . > op on : ToyIDToyID -> State [ctor] . > op clear : ToyID -> State [ctor] . > op hold : ToyID -> State [ctor] . > op empty : -> State [ctor] . > op 1 : -> State [ctor] . *** identity state > op _&_ : State State -> State [ctor assoc comm id: 1] . > vars X Y : ToyID . > rl [pickup] : empty & clear(X) & floor(X) => hold(X) . > rl [putdown] : hold(X) => empty & clear(X) & floor(X) . > rl [unstack] : empty & clear(X) & on(X,Y) => hold(X) & clear(Y) . > rl [stack] : hold(X) & clear(Y) => empty & clear(X) & on(X,Y) . > endm Maude>
  • 9. アーケードクレーン(状態) Maude> search in ARCADE-CRANE : empty & floor('mothergoose) & on('teddybear, 'mothergoose) & on('soccerball, 'teddybear) & clear('soccerball) & floor('dragondude) & clear('dragondude) =>+ empty & floor('teddybear) & on ('mothergoose,'teddybear) & on('soccerball,'mothergoose) & clear('soccerball) & floor('dragondude) & clear('dragondude) . *********** rule rl empty & floor(X) & clear(X) => hold(X) [label pickup] . X --> 'dragondude empty & floor('dragondude) & floor('mothergoose) & clear('dragondude) & clear( 'soccerball) & on('soccerball, 'teddybear) & on('teddybear, 'mothergoose) ---> (floor('mothergoose) & clear('soccerball) & on('soccerball, 'teddybear) & on( 'teddybear, 'mothergoose)) & hold('dragondude) 中略 *********** rule rl empty & clear(X) & on(X, Y) => clear(Y) & hold(X) [label unstack] . X --> 'soccerball Y --> 'dragondude empty & floor('teddybear) & clear('soccerball) & on('dragondude, 'mothergoose) & on('mothergoose, 'teddybear) & on('soccerball, 'dragondude) ---> (floor('teddybear) & on('dragondude, 'mothergoose) & on('mothergoose, 'teddybear)) & clear('dragondude) & hold('soccerball) No more solutions. states: 125 rewrites: 272 in 37ms cpu (391ms real) (7237 rewrites/second) Maude>
  • 10. アーケードクレーン(状態) Maude> search in ARCADE-CRANE : empty & floor('mothergoose) & on('teddybear,'mothergoose) & on('soccerball,'teddybear) & clear('soccerball) & floor('dragondude) & clear('dragondude) =>+ empty & floor('teddybear) & floor('mothergoose) & clear('teddybear) & clear('mothergoose) & X:State . Solution 1 (state 10) states: 11 rewrites: 16 in 0ms cpu (0ms real) (49844 rewrites/second) X:State --> floor('dragondude) & clear('soccerball) & on('soccerball, 'dragondude) Solution 2 (state 15) states: 16 rewrites: 23 in 0ms cpu (0ms real) (40280 rewrites/second) X:State --> floor('dragondude) & floor('soccerball) & clear('dragondude) & clear('soccerball) Solution 3 (state 33) states: 34 rewrites: 54 in 1ms cpu (1ms real) (39560 rewrites/second) X:State --> floor('soccerball) & clear('dragondude) & on('dragondude, 'soccerball) No more solutions. states: 125 rewrites: 272 in 5ms cpu (5ms real) (50670 rewrites/second) Maude> X
  • 11. 川渡しパズル(定義1) Maude> mod RIVER-CROSSING is > sorts Side Group . > ops left right : -> Side [ctor] . > op change : Side -> Side . > eqchange(left) = right . > eqchange(right) = left . > ops swlc : Side -> Group [ctor] . > op __ : Group Group -> Group [ctor assoc comm] . > var S : Side . > rl [shepherd] : s(S) => s(change(S)) . > rl [wolf] : s(S) w(S) => s(change(S)) w(change(S)) . > rl [lamb] : s(S) l(S) => s(change(S)) l(change(S)) . > rl [cabbage] : s(S) c(S) => s(change(S)) c(change(S)) . > endm
  • 12. 川渡しパズル(定義2) Maude> mod RIVER-CROSSING-PROP is > protecting RIVER-CROSSING . > including MODEL-CHECKER . > subsort Group < State . > op initial : -> Group . > eq initial = s(left) w(left) l(left) c(left) . > ops disaster success : -> Prop . > vars S S' S'' : Side . > ceq (w(S) l(S) s(S') c(S'') |= disaster) = true if S =/= S' . > ceq (w(S'') l(S) s(S') c(S) |= disaster) = true if S =/= S' . > eq (s(right) w(right) l(right) c(right) |= success) = true . > endm Maude>
  • 13. 川渡しパズル(実行) % ./maude.intelDarwin -interactive model-checker.maude Maude> red modelCheck(initial, > <> success -> (<> disaster /((success) U disaster))) . reduce in RIVER-CROSSING-PROP : modelCheck(initial, <> success -> <> disaster /(success U disaster)) . rewrites: 76 in 1ms cpu (1ms real) (60995 rewrites/second) result ModelCheckResult: counterexample({s(left) w(left) l(left) c(left),'lamb} {s(right) w(left) l(right) c(left),'shepherd} {s(left) w(left) l(right) c( left),'wolf} {s(right) w(right) l(right) c(left),'lamb} {s(left) w(right) l(left) c(left),'cabbage} {s(right) w(right) l(left) c(right),'shepherd} { s(left) w(right) l(left) c(right),'lamb} {s(right) w(right) l(right) c( right),'lamb} {s(left) w(right) l(left) c(right),'shepherd} {s(right) w( right) l(left) c(right),'wolf} {s(left) w(left) l(left) c(right),'lamb} {s( right) w(left) l(right) c(right),'cabbage} {s(left) w(left) l(right) c( left),'wolf}, {s(right) w(right) l(right) c(left),'lamb} {s(left) w(right) l(left) c(left),'lamb}) Maude>
  • 14. 触り始めたばかりだが Maudeは割と面白い 普通に項書き換え系プログラミングとして遊べる 例えば型無しλ計算とか、当たり前だけど書ける 違和感があるところ Subsorts Nat < NeList < List Nat は要素1個の (Nat)のList である!