Maude is a programming language based on rewriting logic that allows both declarative and concurrent programming. It has applications in formal specification, model checking, and programming domains like DSL development. The document provides examples of defining natural numbers and a cigarette smoking simulation in Maude. It also describes using Maude's model checking capabilities to analyze a river crossing puzzle.
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>
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>