(************** Content-type: application/mathematica ************** Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 14892, 469]*) (*NotebookOutlinePosition[ 15564, 492]*) (* CellTagsIndexPosition[ 15520, 488]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["AUTOMI FINITI: Esempi", "Subtitle", FontSize->18, FontColor->RGBColor[0, 0, 1], Background->RGBColor[1, 1, 0]], Cell[TextData[{ "\n\n", StyleBox["Ascensore con gettoniera", FontSize->18], StyleBox[".", FontSize->16], " \nLa prima parte riguarda solo la descrizione dell'automa che ha :\ncome \ insieme degli output \nX={m,1,2,3,...}, \n(dove il numero n rappresenta \ il pulsante per andare al piano n e la lettera e rappresenta il mettere una \ moneta di un euro) \n\ncome insieme degli autoput \nY={Print[\"sei andato al \ piano \",i],Print[\"paga altrimenti non mi muovo !\"],Print[\" scemo hai \ pagato pi\[UGrave] volte !, ora puoi scegliere il piano \"] , Print[\" \ grazie, ora puoi scegliere il piano \"]},\n\ncome insieme degli stati\nS = \ {p, np} (dove p significa pagato e np non pagato)\n\n Inoltre lo \ stato iniziale \[EGrave] np sono definite le due funzioni Ou : SxX\[Rule]Y \ ; Cs : SxX\[Rule]S." }], "Input", CellMargins->{{Inherited, 18}, {Inherited, Inherited}}, TextJustification->1, FontSize->14], Cell[BoxData[{ \(\(Ou[p, i_] := Print["\", i];\)\), "\n", \(Ou[np, i_] := Print["\"]\), "\n", \(Ou[p, e] := Print["\< scemo devi pagare una sola volta !, ora puoi scegliere il \ piano \>"]\), "\n", \(Ou[np, e] := Print["\< grazie, ora puoi scegliere il piano \>"]\), "\n", \(Cs[p, i_] := np\), "\n", \(Cs[np, i_] := np\), "\n", \(Cs[p, e] := p\), "\n", \(Cs[np, e] := p\)}], "Input"], Cell[BoxData[ \(Per\ simulare\ il\ funzionamento, \ un\ primo\ tentativo\ \[EGrave]\ il\ \(\(seguente\)\(:\)\)\)], "Input"], Cell[BoxData[ \(vai[s_] := \((a = Input[]; Ou[s, a]; vai[Cs[s, a]])\)\)], "Input"], Cell[BoxData[ \(Tuttavia\ \ in\ tale\ caso\ si\ creerebbe\ un\ ciclo\ infinito\ perch\ \[EGrave]\ il\ programma\ continua\ a\ chiedere\ un\ input . \ E'\ preferibile\ allora\ la\ seguente\ \(\(definizione\)\(.\)\)\)], \ "Input"], Cell[BoxData[ \(vai[s_] := \((a = Input[]; If[a === stop, Print["\< ciao \>"], Ou[s, a]; vai[Cs[s, a]]])\)\)], "Input"], Cell[BoxData[ \(Possiamo\ anche\ arricchire\ il\ programma\ con\ qualche\ \ \(\(commento\)\(.\)\)\)], "Input"], Cell[BoxData[ \(vai[ s_] := \((a = Input["\"]; If[a === stop, Print["\< ciao \>"], \((Ou[s, a]; vai[Cs[s, a]])\)])\)\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(vai[np]\)], "Input"], Cell[BoxData[ \(" grazie, ora puoi scegliere il piano "\)], "Print"], Cell[BoxData[ InterpretationBox[\("sei andato al piano "\[InvisibleSpace]3\), SequenceForm[ "sei andato al piano ", 3], Editable->False]], "Print"], Cell[BoxData[ \("paga altrimenti non mi muovo !"\)], "Print"], Cell[BoxData[ \("paga altrimenti non mi muovo !"\)], "Print"], Cell[BoxData[ \("paga altrimenti non mi muovo !"\)], "Print"], Cell[BoxData[ \(" grazie, ora puoi scegliere il piano "\)], "Print"], Cell[BoxData[ \(" ciao "\)], "Print"] }, Open ]], Cell[BoxData[ \(Una\ possibile\ variazione\ \[EGrave]\ un\ automa\ che\ ammetta\ anche\ \ cinquanta\ centesimi\ alla\ volta\ per\ raggiungere\ un\ euro . \ Indichiamo\ con\ c\ un\ tale\ tipo\ di\ imput\ mentre\ indichiamo\ \ con\ sp\ lo\ stato\ di\ \(\("\"\)\(.\)\)\)], "Input"], Cell[BoxData[{ \(\(ris[p, i_] := Print["\", i];\)\), "\n", \(ris[np, i_] := Print["\"]\), "\n", \(ris[sp, i_] := Print["\"]\), "\[IndentingNewLine]", \(ris[p, e] := Print["\< scemo devi pagare una sola volta !, ora puoi scegliere il \ piano \>"]\), "\n", \(ris[np, e] := Print["\< grazie, ora puoi scegliere il piano \>"]\), "\ \[IndentingNewLine]", \(ris[p, c] := Print["\< scemo devi pagare una sola volta !, ora puoi scegliere il \ piano \>"]\), "\[IndentingNewLine]", \(ris[sp, c] := Print["\< grazie, ora puoi scegliere il piano \>"]\), "\n", \(ris[sp, e] := Print["\< scemo devi pagare una sola volta !, ora puoi scegliere il \ piano \>"]\[IndentingNewLine]\), "\n", \(c[p, i_] := np\), "\n", \(c[np, i_] := np\n\), "\[IndentingNewLine]", \(c[p, e] := p\), "\[IndentingNewLine]", \(c[p, c] := p\), "\n", \(c[np, e] := p\), "\[IndentingNewLine]", \(c[np, c] := sp\), "\[IndentingNewLine]", \(c[sp, e] := p\), "\[IndentingNewLine]", \(c[sp, c] := p\n\), "\n", \(nuovovai[ s_] := \((a = Input["\"]; If[a === stop, Print["\< ciao \>"], \((ris[s, a]; nuovovai[c[s, a]])\)])\)\), "\[IndentingNewLine]", \(\)}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(nuovovai[p]\)], "Input"], Cell[BoxData[ InterpretationBox[\("sei andato al piano "\[InvisibleSpace]3\), SequenceForm[ "sei andato al piano ", 3], Editable->False]], "Print"], Cell[BoxData[ \("paga altrimenti non mi muovo !"\)], "Print"], Cell[BoxData[ \(" grazie, ora puoi scegliere il piano "\)], "Print"], Cell[BoxData[ InterpretationBox[\("sei andato al piano "\[InvisibleSpace]5\), SequenceForm[ "sei andato al piano ", 5], Editable->False]], "Print"], Cell[BoxData[ \("paga altrimenti non mi muovo !"\)], "Print"], Cell[BoxData[ \(" grazie, ora puoi scegliere il piano "\)], "Print"], Cell[BoxData[ InterpretationBox[\("sei andato al piano "\[InvisibleSpace]3\), SequenceForm[ "sei andato al piano ", 3], Editable->False]], "Print"], Cell[BoxData[ \(" ciao "\)], "Print"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Automi che effettuano l'addizione in maniera sequenziale", "Subtitle", Background->RGBColor[0, 1, 1]], Cell[BoxData[ \(Il\ seguente\ programma\ definisce\ un\ automa\ in\ grado\ di\ \ effettuare\ l' addizione\ in\ base\ due\ in\ maniera\ sequenziale . \ Si\ basa\ sulla\ funzione\ output\ "\"\ e\ sulla\ funzione\ \ di\ cambiamento\ di\ stato\ "\" . \ Potremmo\ definire\ la\ funzione\ output\ "\"\ assegnandone\ \ i\ valori\ negli\ otto\ modi\ possibili, \ cio\[EGrave]\ scrivendo\ somma2[0, 0, 0] := 0, \ somma2[1, 0, 0] := 1, \(\(...\)\(\ \)\(Per\)\(\ \)\(abbreviare\)\(\ \)\(utilizziamo\)\(\ \ \)\(invece\)\(\ \)\(la\)\(\ \)\(funzione\)\(\ \)\(Mod\ . \ Similmente\)\(\ \)\(invece\)\(\ \)\(di\)\(\ \)\(definire\)\(\ \)\(per\ \)\(\ \)\(esteso\)\(\ \)\(la\)\(\ \)\(funzione\)\(\ \)\(di\)\(\ \ \)\(cambiamento\)\(\ \)\(di\)\(\ \)\(stato\)\(\ \)\(riporto2\)\(\ \ \)\(utilizziamo\)\(\ \)\(la\)\(\ \)\(funzione\)\(\ \)\(\(If\)\(.\)\)\)\)], \ "Input"], Cell[BoxData[{ \(somma2[r_, x_, y_] := Mod[r + x + y, 2]; riporto2[r_, x_, y_] := If[r + x + y < 2, 0, 1]\), "\n", \(vai2[ r_] := \((x = Input["\"]; If[x === f, Print[r], y = Input["\"]; Print[somma2[r, x, y]]; vai2[riporto2[r, x, y]]])\)\)}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(vai2[0]\)], "Input"], Cell[BoxData[ \(1\)], "Print"], Cell[BoxData[ \(0\)], "Print"], Cell[BoxData[ \(0\)], "Print"], Cell[BoxData[ \(1\)], "Print"], Cell[BoxData[ \(1\)], "Print"] }, Open ]], Cell[BoxData[ \(Non\ \[EGrave]\ difficile\ modificare\ tale\ automa\ in\ modo\ che\ \ effettui\ l' addizione\ in\ base\ dieci\ \(\((oppure\ in\ una\ qualsiasi\ altra\ \ base)\)\(.\)\)\)], "Input"], Cell[BoxData[{ \(somma10[r_, x_, y_] := Mod[r + x + y, 10]; riporto10[r_, x_, y_] := If[r + x + y < 10, 0, 1]\), "\n", \(vai10[ r_] := \((x = Input["\"]; If[x === f, Print[r], y = Input["\"]; Print[somma10[r, x, y]]; vai10[riporto10[r, x, y]]])\)\)}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(vai10[0]\)], "Input"], Cell[BoxData[ \(1\)], "Print"], Cell[BoxData[ \(2\)], "Print"], Cell[BoxData[ \(2\)], "Print"], Cell[BoxData[ \(1\)], "Print"] }, Open ]], Cell[BoxData[ \(Possiamo\ anche\ scrivere\ un\ programma\ che\ funzione\ con\ qualsiasi\ \ base . \ Per\ fare\ questo\ dobbiamo\ introdurre\ la\ base\ \(\(b\)\(.\)\)\)], \ "Input"], Cell[BoxData[{ \(add[r_, x_, y_, b_] := Mod[r + x + y, b]; riporto[r_, x_, y_, b_] := If[r + x + y < b, 0, 1]\), "\n", \(vai[r_, b_] := \((\[IndentingNewLine]x = Input["\"]; \[IndentingNewLine]If[x === f, Print[r], \[IndentingNewLine]y = Input["\"]; Print[add[r, x, y, b]]; vai[riporto[r, x, y, b], b]]\[IndentingNewLine])\)\)}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(vai[0, 3]\)], "Input"], Cell[BoxData[ \(2\)], "Print"], Cell[BoxData[ \(0\)], "Print"], Cell[BoxData[ \(1\)], "Print"], Cell[BoxData[ \(1\)], "Print"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Automi riconoscitori di linguaggi", "Subtitle", Background->RGBColor[0, 1, 1]], Cell[BoxData[{ \(\[IndentingNewLine]Definiamo\ ora\ un\ automa\ che\ verifica\ se\ in\ \ una\ parola\ la\ lettera\ b\ compare\ un\ numero\ pari\ di\ volte . \ In\ questo\ caso\ \), "\[IndentingNewLine]", \(X\ = \ {a, b, c, ... }\), "\[IndentingNewLine]", \(Y\ = \ {Print[ i, "\< la lettera b \[EGrave] stata introdotta dispari volte \ \>"], Print[ i, "\< la lettera b \[EGrave] stata introdotta pari volte \ \>"]}\), "\[IndentingNewLine]", \(S\ = \ {pa, dispa}\), "\[IndentingNewLine]", \(\)}], "Input"], Cell[BoxData[{ \(\(Ou[s_, i_] := If[s === dispa, \ Print[i, "\< la lettera b \[EGrave] stata introdotta dispari \ volte \>"], Print[i, "\< la lettera b \[EGrave] stata inserita un numero pari \ volte \>"]];\)\), "\n", \(Cs[pa, i_] := If[i === b, dispa, pa]\), "\n", \(Cs[dispa, i_] := If[i === b, pa, dispa]\), "\n", \(\)}], "Input"], Cell[BoxData[ \(vai[s_] := \((a = Input[]; If[a === stop, Print["\< ciao \>"], \((Ou[cs[s, a], a]; vai[Cs[s, a]])\)])\)\)], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(vai[pa]\)], "Input"], Cell[BoxData[ InterpretationBox[\(s\[InvisibleSpace]" la lettera b \[EGrave] stata \ inserita pari volte "\), SequenceForm[ s, " la lettera b \[EGrave] stata inserita pari volte "], Editable->False]], "Print"], Cell[BoxData[ InterpretationBox[\(c\[InvisibleSpace]" la lettera b \[EGrave] stata \ inserita pari volte "\), SequenceForm[ c, " la lettera b \[EGrave] stata inserita pari volte "], Editable->False]], "Print"], Cell[BoxData[ InterpretationBox[\(b\[InvisibleSpace]" la lettera b \[EGrave] stata \ introdotta dispari volte "\), SequenceForm[ b, " la lettera b \[EGrave] stata introdotta dispari volte "], Editable->False]], "Print"], Cell[BoxData[ InterpretationBox[\(b\[InvisibleSpace]" la lettera b \[EGrave] stata \ inserita pari volte "\), SequenceForm[ b, " la lettera b \[EGrave] stata inserita pari volte "], Editable->False]], "Print"], Cell[BoxData[ InterpretationBox[\(b\[InvisibleSpace]" la lettera b \[EGrave] stata \ introdotta dispari volte "\), SequenceForm[ b, " la lettera b \[EGrave] stata introdotta dispari volte "], Editable->False]], "Print"], Cell[BoxData[ InterpretationBox[\(b\[InvisibleSpace]" la lettera b \[EGrave] stata \ inserita pari volte "\), SequenceForm[ b, " la lettera b \[EGrave] stata inserita pari volte "], Editable->False]], "Print"], Cell[BoxData[ InterpretationBox[\(f\[InvisibleSpace]" la lettera b \[EGrave] stata \ inserita pari volte "\), SequenceForm[ f, " la lettera b \[EGrave] stata inserita pari volte "], Editable->False]], "Print"], Cell[BoxData[ InterpretationBox[\(f\[InvisibleSpace]" la lettera b \[EGrave] stata \ inserita pari volte "\), SequenceForm[ f, " la lettera b \[EGrave] stata inserita pari volte "], Editable->False]], "Print"], Cell[BoxData[ \(" ciao "\)], "Print"] }, Open ]], Cell[BoxData[ RowBox[{" ", StyleBox[ ButtonBox[ StyleBox[ TagBox[ ButtonBox[\(\(TORNA\)\(\ \)\(ALL'\) \(INDICE\)\(\ \)\), ButtonFrame->"DialogBox", Background->RGBColor[0.300008, 1, 1]], DisplayForm], FontSize->12], ButtonData:>{"INDICE.nb", None}, ButtonStyle->"Hyperlink"], FontSize->12]}]], "Input"] }, Open ]] }, FrontEndVersion->"4.1 for Microsoft Windows", ScreenRectangle->{{0, 1280}, {0, 949}}, WindowToolbars->"RulerBar", WindowSize->{1016, 647}, WindowMargins->{{0, Automatic}, {Automatic, 0}} ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1727, 52, 122, 3, 74, "Subtitle"], Cell[1852, 57, 948, 19, 323, "Input"], Cell[2803, 78, 492, 11, 170, "Input"], Cell[3298, 91, 132, 2, 30, "Input"], Cell[3433, 95, 86, 1, 30, "Input"], Cell[3522, 98, 241, 4, 50, "Input"], Cell[3766, 104, 143, 3, 30, "Input"], Cell[3912, 109, 114, 2, 30, "Input"], Cell[4029, 113, 260, 6, 50, "Input"], Cell[CellGroupData[{ Cell[4314, 123, 40, 1, 30, "Input"], Cell[4357, 126, 72, 1, 25, "Print"], Cell[4432, 129, 163, 3, 25, "Print"], Cell[4598, 134, 65, 1, 25, "Print"], Cell[4666, 137, 65, 1, 25, "Print"], Cell[4734, 140, 65, 1, 25, "Print"], Cell[4802, 143, 72, 1, 25, "Print"], Cell[4877, 146, 41, 1, 25, "Print"] }, Open ]], Cell[4933, 150, 304, 4, 50, "Input"], Cell[5240, 156, 1485, 34, 450, "Input"], Cell[CellGroupData[{ Cell[6750, 194, 44, 1, 30, "Input"], Cell[6797, 197, 163, 3, 25, "Print"], Cell[6963, 202, 65, 1, 25, "Print"], Cell[7031, 205, 72, 1, 25, "Print"], Cell[7106, 208, 163, 3, 25, "Print"], Cell[7272, 213, 65, 1, 25, "Print"], Cell[7340, 216, 72, 1, 25, "Print"], Cell[7415, 219, 163, 3, 25, "Print"], Cell[7581, 224, 41, 1, 25, "Print"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[7671, 231, 109, 1, 80, "Subtitle"], Cell[7783, 234, 927, 16, 110, "Input"], Cell[8713, 252, 388, 8, 70, "Input"], Cell[CellGroupData[{ Cell[9126, 264, 40, 1, 30, "Input"], Cell[9169, 267, 34, 1, 25, "Print"], Cell[9206, 270, 34, 1, 25, "Print"], Cell[9243, 273, 34, 1, 25, "Print"], Cell[9280, 276, 34, 1, 25, "Print"], Cell[9317, 279, 34, 1, 25, "Print"] }, Open ]], Cell[9366, 283, 207, 4, 30, "Input"], Cell[9576, 289, 396, 8, 70, "Input"], Cell[CellGroupData[{ Cell[9997, 301, 41, 1, 30, "Input"], Cell[10041, 304, 34, 1, 25, "Print"], Cell[10078, 307, 34, 1, 25, "Print"], Cell[10115, 310, 34, 1, 25, "Print"], Cell[10152, 313, 34, 1, 25, "Print"] }, Open ]], Cell[10201, 317, 193, 4, 30, "Input"], Cell[10397, 323, 488, 9, 130, "Input"], Cell[CellGroupData[{ Cell[10910, 336, 42, 1, 30, "Input"], Cell[10955, 339, 34, 1, 25, "Print"], Cell[10992, 342, 34, 1, 25, "Print"], Cell[11029, 345, 34, 1, 25, "Print"], Cell[11066, 348, 34, 1, 25, "Print"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[11149, 355, 86, 1, 80, "Subtitle"], Cell[11238, 358, 564, 11, 130, "Input"], Cell[11805, 371, 387, 9, 110, "Input"], Cell[12195, 382, 169, 4, 30, "Input"], Cell[CellGroupData[{ Cell[12389, 390, 40, 1, 30, "Input"], Cell[12432, 393, 238, 5, 25, "Print"], Cell[12673, 400, 238, 5, 25, "Print"], Cell[12914, 407, 246, 5, 25, "Print"], Cell[13163, 414, 238, 5, 25, "Print"], Cell[13404, 421, 246, 5, 25, "Print"], Cell[13653, 428, 238, 5, 25, "Print"], Cell[13894, 435, 238, 5, 25, "Print"], Cell[14135, 442, 238, 5, 25, "Print"], Cell[14376, 449, 41, 1, 25, "Print"] }, Open ]], Cell[14432, 453, 444, 13, 42, "Input"] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)