免責事項:あなたの質問は非常に一般的であるため、この回答も同様です。私は TM の専門家ではないことに注意してください。このアプローチは通常、あまり効率的ではありません (常に効果的であるとは約束できません)。ここにちょっとだけ感想を書いておきます。
次のようなアプローチを試すことをお勧めします。擬似コードを取得して、a) ブール変数と b)if
ステートメントのみで構成されるように縮小します。例えば:
if THIS_LETTER_IS("A"):
found_an_even_number_of_A = not found_an_even_number_of_A
if THIS_LETTER_IS("Q") and previous_letter_was_X and found_an_even_number_of_A
and not checking_for_alternative_2:
# can't be a word of alternative 1, so check for alternative 2
going_back_to_start_to_check_for_alternative_2 = True
if going_back_to_start_to_check_for_alternative_2:
MOVE_TO_PREVIOUS
else:
MOVE_TO_NEXT
if going_back_to_start_to_check_for_alternative_2 and THIS_LETTER_IS(EMPTY):
# reached the beginning, so let's check for alternative 2
going_back_to_start_to_check_for_alternative_2 = False
checking_for_alternative_2 = True
sがネストされている場合はif
、それらを s に置き換えますand
。else
を使用してブロックを削除しnot
ます。
if something:
if something_else:
do_a
else:
do_b
になる
if something and something_else:
do_a
if something and not something_else:
do_b
各ブロックには、1 つまたは、場合によってはコマンドと、任意の数の変数割り当てif
のみを含める必要があります。MOVE_TO_PREVIOUS
MOVE_TO_NEXT
WRITE
ブール値のすべてif
と現在の文字が常にチェックされるようにすべての句を完成させ、必要に応じてブロックを複製します。例:
if something and something_else:
do_a
になる
if THIS_LETTER_IS("A") and something and something_else and something_i_dont_care_about_here:
do_a
if THIS_LETTER_IS("A") and something and something_else and not something_i_dont_care_about_here:
do_a
if THIS_LETTER_IS("Q") and something and something_else and something_i_dont_care_about_here:
do_a
if THIS_LETTER_IS("Q") and something and something_else and not something_i_dont_care_about_here:
do_a
n個のブール値とm個の文字がある場合、m * 2 n if
sが必要です。ブール値をビットフィールドに格納したと想像してください。したがって、ブール値の可能な組み合わせはそれぞれ整数を表します。したがって、上記は
if THIS_LETTER_IS("A") and bitfield[0] and bitfield[1] and bitfield[2]:
do_a
if THIS_LETTER_IS("A") and bitfield[0] and bitfield[1] and not bitfield[2]:
do_a
# ...
その後、
if THIS_LETTER_IS("A") and bitfield == 7:
do_a
if THIS_LETTER_IS("A") and bitfield == 3:
do_a
# ...
ビットフィールドのこの整数値は、チューリング マシンの状態です。このdo_a
部分はブール値への割り当て (つまり、ビットフィールド、つまり新しい状態)、書き込みコマンド (何もない場合は、既に存在していた文字を書き込むだけ)、および移動コマンドであり、明示的にチューリング マシンの遷移です。
上記のいずれかが理にかなっていることを願っています。