2011-01-10 12 views
0

Cellular Automata Mathematicaファイルからこれを見つけましたが、パターンと選択肢は何ですか?このコードブロックでMathematica /ノートブックソース、パターン、代替のセルオートマトンルール関数

、パターンは何を意味する:

CellularAutomaton[{ { 0, Blank[], 3} -> 0, 
         { Blank[], 2, 3} -> 3, 
         { 1, 1, 3 }  -> 4, 
         { Blank[], 1, 4} -> 4, 
         { Alternatives[1, 2] << 1 or 2 >>, 3, Blank[]} -> 5, 
         { Pattern[$CellContext`p, Alternatives[0, 1]], 4, Blank[]} -> 7 - $CellContext`p, 
         { 7, 2, 6} -> 3, 
         { 7, Blank[], Blank[]} -> 7, 
         { Blank[], 7, Pattern[$CellContext`p, Alternatives[1, 2]]} -> $CellContext`p, 
         { Blank[], Pattern[$CellContext`p, Alternatives[5, 6]], Blank[]} -> 7 - $CellContext`p, 
         { Alternatives[5, 6], Pattern[$CellContext`p, Alternatives[1, 2]], Blank[]} -> 7 - $CellContext`p, 
         { Alternatives[5, 6], 0, 0} -> 1, 
         { Blank[], Pattern[$CellContext`p, Alternatives[1, 2]], Blank[]} -> $CellContext`p, 
         { Blank[], Blank[], Blank[]} -> 0}, { 

答えて

2

あなたが明示的にセル・オートマトンを定義しています。

各行は進化ルールを定義します。

関連情報hereがあります。

コードを読み取るためのいくつかのヒントは:

Blank[] is the blank pattern "_" that matches any expression 

Pattern[] is Mathematica construct for pattern matching 

Alternatives[a,b,c] is the full form for a | b| c ... any of "a, b or c" 

Pattern[p, Alternatives[a, b]] names as p the matched expr (a or b) 

編集

ので、例として、以下のオートマトンが同等とされています

CellularAutomaton[{ 
    {1, 0} -> 1, 
    {1, 1} -> 0, 
    {0, 1} -> 1, 
    {0, 0} -> 1}, 
    {0, 1, 0}, 10] 

CellularAutomaton[{ 
    {1, Pattern[t, Alternatives[1, 0]]} -> Abs[1 - t], 
    {0, 1} -> 1, 
    {0, 0} -> 1 
    }, {0, 1, 0}, 10] 

注:例あなたが投稿したコードの理解を容易にするためのものです。このオートマトンを定義するより良い方法があります。

+0

ありがとう、私はそこにその質問を投げると思って、誰かが応答しました。 –

+0

私はまだパターンマッチの役割を理解していません。代替案と代替案とのパターンマッチの違いは何でしょうか。 –

+0

例:{Pattern [$ CellContext'p、Alternatives [0,1]]、4、Blank []} - > 7 - $ CellContext'p、...パターンP、(0または1)しかし、 "7 - $ CellContext'p"はどういう意味ですか?また、代替案だけでなく、なぜパターンがここで使われているのですか? –

関連する問題