From 70b1217d79891bbff316c68f0d1737b6178a9060 Mon Sep 17 00:00:00 2001
From: Michael Leuschel <leuschel@uni-duesseldorf.de>
Date: Mon, 17 Apr 2023 16:01:40 +0200
Subject: [PATCH] add Java version of DFA

Signed-off-by: Michael Leuschel <leuschel@uni-duesseldorf.de>
---
 info4/kapitel-2/DFA.ipynb | 318 ++++++++++++++++++++++++--------------
 1 file changed, 201 insertions(+), 117 deletions(-)

diff --git a/info4/kapitel-2/DFA.ipynb b/info4/kapitel-2/DFA.ipynb
index 1182c26..6af0483 100644
--- a/info4/kapitel-2/DFA.ipynb
+++ b/info4/kapitel-2/DFA.ipynb
@@ -86,7 +86,7 @@
     {
      "data": {
       "text/plain": [
-       "Machine constants set up using operation 0: $setup_constants()"
+       "Executed operation: SETUP_CONSTANTS()"
       ]
      },
      "execution_count": 2,
@@ -242,7 +242,27 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": 7,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "Preference changed: DOT = /opt/homebrew/bin/dot\n"
+      ]
+     },
+     "execution_count": 7,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    ":pref DOT=/opt/homebrew/bin/dot"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
    "metadata": {},
    "outputs": [
     {
@@ -251,94 +271,94 @@
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
        "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
        " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
-       "<!-- Generated by graphviz version 2.44.1 (0)\n",
+       "<!-- Generated by graphviz version 8.0.1 (20230327.1645)\n",
        " -->\n",
        "<!-- Title: prob_graph Pages: 1 -->\n",
-       "<svg width=\"540pt\" height=\"716pt\"\n",
-       " viewBox=\"0.00 0.00 540.00 716.10\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
-       "<g id=\"graph0\" class=\"graph\" transform=\"scale(0.98 0.98) rotate(0) translate(4 726.01)\">\n",
+       "<svg width=\"540pt\" height=\"717pt\"\n",
+       " viewBox=\"0.00 0.00 540.00 717.37\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
+       "<g id=\"graph0\" class=\"graph\" transform=\"scale(0.985401 0.985401) rotate(0) translate(4 724)\">\n",
        "<title>prob_graph</title>\n",
-       "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-726.01 546.49,-726.01 546.49,4 -4,4\"/>\n",
+       "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-724 544,-724 544,4 -4,4\"/>\n",
        "<!-- 0 -->\n",
        "<g id=\"node1\" class=\"node\">\n",
        "<title>0</title>\n",
-       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"59.74\" cy=\"-56\" rx=\"18.44\" ry=\"18.44\"/>\n",
-       "<ellipse fill=\"none\" stroke=\"black\" cx=\"59.74\" cy=\"-56\" rx=\"22.44\" ry=\"22.44\"/>\n",
-       "<text text-anchor=\"middle\" x=\"59.74\" y=\"-52.9\" font-family=\"Times,serif\" font-size=\"12.00\">z2</text>\n",
+       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"59.91\" cy=\"-55\" rx=\"18\" ry=\"18\"/>\n",
+       "<ellipse fill=\"none\" stroke=\"black\" cx=\"59.91\" cy=\"-55\" rx=\"22\" ry=\"22\"/>\n",
+       "<text text-anchor=\"middle\" x=\"59.91\" y=\"-51.9\" font-family=\"Times,serif\" font-size=\"12.00\">z2</text>\n",
        "</g>\n",
        "<!-- 0&#45;&gt;0 -->\n",
        "<g id=\"edge3\" class=\"edge\">\n",
        "<title>0&#45;&gt;0</title>\n",
-       "<path fill=\"none\" stroke=\"green\" d=\"M79.72,-66.43C90.44,-68.2 100.2,-64.72 100.2,-56 100.2,-50.28 96,-46.81 90.08,-45.61\"/>\n",
-       "<polygon fill=\"green\" stroke=\"green\" points=\"89.74,-42.11 79.72,-45.57 89.71,-49.11 89.74,-42.11\"/>\n",
-       "<text text-anchor=\"middle\" x=\"104.2\" y=\"-52.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
+       "<path fill=\"none\" stroke=\"green\" d=\"M79.67,-65.52C90.26,-67.3 99.91,-63.8 99.91,-55 99.91,-49.36 95.95,-45.9 90.32,-44.61\"/>\n",
+       "<polygon fill=\"green\" stroke=\"green\" points=\"90.71,-41.1 80.67,-44.48 90.63,-48.1 90.71,-41.1\"/>\n",
+       "<text text-anchor=\"middle\" x=\"103.41\" y=\"-51.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
        "</g>\n",
        "<!-- 0&#45;&gt;0 -->\n",
        "<g id=\"edge7\" class=\"edge\">\n",
        "<title>0&#45;&gt;0</title>\n",
-       "<path fill=\"none\" stroke=\"red\" d=\"M75.9,-71.61C95.36,-83.41 118.2,-78.2 118.2,-56 118.2,-37.27 101.94,-30.63 85.17,-36.1\"/>\n",
-       "<polygon fill=\"red\" stroke=\"red\" points=\"83.51,-33.02 75.9,-40.39 86.44,-39.37 83.51,-33.02\"/>\n",
-       "<text text-anchor=\"middle\" x=\"122.2\" y=\"-52.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
+       "<path fill=\"none\" stroke=\"red\" d=\"M75.94,-70.75C95.24,-82.64 117.91,-77.39 117.91,-55 117.91,-36.28 102.07,-29.54 85.6,-34.78\"/>\n",
+       "<polygon fill=\"red\" stroke=\"red\" points=\"84.55,-31.88 76.94,-39.25 87.49,-38.23 84.55,-31.88\"/>\n",
+       "<text text-anchor=\"middle\" x=\"121.41\" y=\"-51.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
        "</g>\n",
        "<!-- 1 -->\n",
        "<g id=\"node2\" class=\"node\">\n",
        "<title>1</title>\n",
-       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"282.74\" cy=\"-494\" rx=\"18.44\" ry=\"18.44\"/>\n",
-       "<text text-anchor=\"middle\" x=\"282.74\" y=\"-490.9\" font-family=\"Times,serif\" font-size=\"12.00\">z0</text>\n",
+       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"280.91\" cy=\"-492\" rx=\"18\" ry=\"18\"/>\n",
+       "<text text-anchor=\"middle\" x=\"280.91\" y=\"-488.9\" font-family=\"Times,serif\" font-size=\"12.00\">z0</text>\n",
        "</g>\n",
        "<!-- 2 -->\n",
        "<g id=\"node3\" class=\"node\">\n",
        "<title>2</title>\n",
-       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"211.74\" cy=\"-280\" rx=\"18.44\" ry=\"18.44\"/>\n",
-       "<text text-anchor=\"middle\" x=\"211.74\" y=\"-276.9\" font-family=\"Times,serif\" font-size=\"12.00\">z1</text>\n",
+       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"206.91\" cy=\"-278\" rx=\"18\" ry=\"18\"/>\n",
+       "<text text-anchor=\"middle\" x=\"206.91\" y=\"-274.9\" font-family=\"Times,serif\" font-size=\"12.00\">z1</text>\n",
        "</g>\n",
        "<!-- 1&#45;&gt;2 -->\n",
        "<g id=\"edge5\" class=\"edge\">\n",
        "<title>1&#45;&gt;2</title>\n",
-       "<path fill=\"none\" stroke=\"red\" d=\"M277.17,-476.36C264.88,-439.69 235.39,-351.63 220.56,-307.36\"/>\n",
-       "<polygon fill=\"red\" stroke=\"red\" points=\"223.87,-306.22 217.38,-297.85 217.24,-308.45 223.87,-306.22\"/>\n",
-       "<text text-anchor=\"middle\" x=\"253.74\" y=\"-383.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
+       "<path fill=\"none\" stroke=\"red\" d=\"M275.23,-474.72C262.53,-438.34 231.75,-350.17 216.21,-305.66\"/>\n",
+       "<polygon fill=\"red\" stroke=\"red\" points=\"219.21,-304.63 212.61,-296.34 212.6,-306.93 219.21,-304.63\"/>\n",
+       "<text text-anchor=\"middle\" x=\"250.41\" y=\"-381.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
        "</g>\n",
        "<!-- 3 -->\n",
        "<g id=\"node4\" class=\"node\">\n",
        "<title>3</title>\n",
-       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"354.74\" cy=\"-56\" rx=\"18.44\" ry=\"18.44\"/>\n",
-       "<text text-anchor=\"middle\" x=\"354.74\" y=\"-52.9\" font-family=\"Times,serif\" font-size=\"12.00\">z3</text>\n",
+       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"354.91\" cy=\"-55\" rx=\"18\" ry=\"18\"/>\n",
+       "<text text-anchor=\"middle\" x=\"354.91\" y=\"-51.9\" font-family=\"Times,serif\" font-size=\"12.00\">z3</text>\n",
        "</g>\n",
        "<!-- 1&#45;&gt;3 -->\n",
        "<g id=\"edge1\" class=\"edge\">\n",
        "<title>1&#45;&gt;3</title>\n",
-       "<path fill=\"none\" stroke=\"green\" d=\"M285.6,-475.64C296.67,-408.64 336.64,-166.59 350.2,-84.47\"/>\n",
-       "<polygon fill=\"green\" stroke=\"green\" points=\"353.69,-84.85 351.86,-74.41 346.78,-83.71 353.69,-84.85\"/>\n",
-       "<text text-anchor=\"middle\" x=\"324.74\" y=\"-276.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
+       "<path fill=\"none\" stroke=\"green\" d=\"M283.81,-473.95C295.1,-407.55 336.2,-165.95 350.2,-83.67\"/>\n",
+       "<polygon fill=\"green\" stroke=\"green\" points=\"353.8,-84.38 352.03,-73.93 346.9,-83.21 353.8,-84.38\"/>\n",
+       "<text text-anchor=\"middle\" x=\"322.41\" y=\"-274.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
        "</g>\n",
        "<!-- 2&#45;&gt;0 -->\n",
        "<g id=\"edge2\" class=\"edge\">\n",
        "<title>2&#45;&gt;0</title>\n",
-       "<path fill=\"none\" stroke=\"green\" d=\"M201.76,-264.43C176.57,-227.64 110.09,-130.55 77.82,-83.42\"/>\n",
-       "<polygon fill=\"green\" stroke=\"green\" points=\"80.57,-81.23 72.03,-74.96 74.79,-85.18 80.57,-81.23\"/>\n",
-       "<text text-anchor=\"middle\" x=\"144.74\" y=\"-169.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
+       "<path fill=\"none\" stroke=\"green\" d=\"M197.26,-262.5C173,-226.02 109.14,-130.02 77.79,-82.89\"/>\n",
+       "<polygon fill=\"green\" stroke=\"green\" points=\"80.25,-81.26 71.8,-74.87 74.42,-85.14 80.25,-81.26\"/>\n",
+       "<text text-anchor=\"middle\" x=\"141.41\" y=\"-168.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
        "</g>\n",
        "<!-- 2&#45;&gt;3 -->\n",
        "<g id=\"edge6\" class=\"edge\">\n",
        "<title>2&#45;&gt;3</title>\n",
-       "<path fill=\"none\" stroke=\"red\" d=\"M221.34,-264.09C245.71,-226.25 310.11,-126.28 339.6,-80.5\"/>\n",
-       "<polygon fill=\"red\" stroke=\"red\" points=\"342.7,-82.15 345.17,-71.85 336.82,-78.36 342.7,-82.15\"/>\n",
-       "<text text-anchor=\"middle\" x=\"287.74\" y=\"-169.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
+       "<path fill=\"none\" stroke=\"red\" d=\"M216.62,-262.5C241.66,-225.11 308.57,-125.19 339.2,-79.45\"/>\n",
+       "<polygon fill=\"red\" stroke=\"red\" points=\"342.51,-81.81 345.16,-71.55 336.69,-77.92 342.51,-81.81\"/>\n",
+       "<text text-anchor=\"middle\" x=\"284.41\" y=\"-168.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
        "</g>\n",
        "<!-- 3&#45;&gt;3 -->\n",
        "<g id=\"edge4\" class=\"edge\">\n",
        "<title>3&#45;&gt;3</title>\n",
-       "<path fill=\"none\" stroke=\"green\" d=\"M370.48,-65.92C380.98,-68.71 391.2,-65.4 391.2,-56 391.2,-49.83 386.8,-46.29 380.81,-45.37\"/>\n",
-       "<polygon fill=\"green\" stroke=\"green\" points=\"380.21,-41.9 370.48,-46.08 380.7,-48.88 380.21,-41.9\"/>\n",
-       "<text text-anchor=\"middle\" x=\"395.2\" y=\"-52.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
+       "<path fill=\"none\" stroke=\"green\" d=\"M370.45,-65C380.82,-67.82 390.91,-64.48 390.91,-55 390.91,-48.92 386.77,-45.37 381.07,-44.35\"/>\n",
+       "<polygon fill=\"green\" stroke=\"green\" points=\"381.22,-40.89 371.45,-45 381.65,-47.88 381.22,-40.89\"/>\n",
+       "<text text-anchor=\"middle\" x=\"394.41\" y=\"-51.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
        "</g>\n",
        "<!-- 3&#45;&gt;3 -->\n",
        "<g id=\"edge8\" class=\"edge\">\n",
        "<title>3&#45;&gt;3</title>\n",
-       "<path fill=\"none\" stroke=\"red\" d=\"M367.32,-69.88C385.92,-83.85 409.2,-79.22 409.2,-56 409.2,-36.41 392.63,-30.05 376.27,-36.93\"/>\n",
-       "<polygon fill=\"red\" stroke=\"red\" points=\"374.22,-34.08 367.32,-42.12 377.73,-40.14 374.22,-34.08\"/>\n",
-       "<text text-anchor=\"middle\" x=\"413.2\" y=\"-52.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
+       "<path fill=\"none\" stroke=\"red\" d=\"M367.11,-68.79C385.6,-83.13 408.91,-78.54 408.91,-55 408.91,-35.32 392.62,-28.88 376.48,-35.68\"/>\n",
+       "<polygon fill=\"red\" stroke=\"red\" points=\"374.94,-33.11 368.11,-41.21 378.5,-39.14 374.94,-33.11\"/>\n",
+       "<text text-anchor=\"middle\" x=\"412.41\" y=\"-51.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
        "</g>\n",
        "<!-- 4 -->\n",
        "<g id=\"node5\" class=\"node\">\n",
@@ -347,17 +367,17 @@
        "<!-- 4&#45;&gt;1 -->\n",
        "<g id=\"edge9\" class=\"edge\">\n",
        "<title>4&#45;&gt;1</title>\n",
-       "<path fill=\"none\" stroke=\"black\" d=\"M282.74,-658.97C282.74,-627.73 282.74,-561 282.74,-523\"/>\n",
-       "<polygon fill=\"black\" stroke=\"black\" points=\"286.24,-522.65 282.74,-512.65 279.24,-522.65 286.24,-522.65\"/>\n",
+       "<path fill=\"none\" stroke=\"black\" d=\"M280.91,-657.3C280.91,-626.29 280.91,-559.51 280.91,-521.32\"/>\n",
+       "<polygon fill=\"black\" stroke=\"black\" points=\"284.41,-521.46 280.91,-511.46 277.41,-521.46 284.41,-521.46\"/>\n",
        "</g>\n",
        "</g>\n",
-       "</svg>"
+       "</svg>\n"
       ],
       "text/plain": [
        "<Dot visualization: custom_graph []>"
       ]
      },
-     "execution_count": 6,
+     "execution_count": 8,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -379,7 +399,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": 9,
    "metadata": {},
    "outputs": [
     {
@@ -391,7 +411,7 @@
        "z2"
       ]
      },
-     "execution_count": 7,
+     "execution_count": 9,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -422,7 +442,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 8,
+   "execution_count": 10,
    "metadata": {},
    "outputs": [
     {
@@ -431,7 +451,7 @@
        "Loaded machine: DFA"
       ]
      },
-     "execution_count": 8,
+     "execution_count": 10,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -474,16 +494,16 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 9,
+   "execution_count": 11,
    "metadata": {},
    "outputs": [
     {
      "data": {
       "text/plain": [
-       "Machine constants set up using operation 0: $setup_constants()"
+       "Executed operation: SETUP_CONSTANTS()"
       ]
      },
-     "execution_count": 9,
+     "execution_count": 11,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -501,7 +521,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
+   "execution_count": 12,
    "metadata": {},
    "outputs": [
     {
@@ -513,7 +533,7 @@
        "z2"
       ]
      },
-     "execution_count": 10,
+     "execution_count": 12,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -531,7 +551,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 11,
+   "execution_count": 13,
    "metadata": {},
    "outputs": [
     {
@@ -543,7 +563,7 @@
        "TRUE"
       ]
      },
-     "execution_count": 11,
+     "execution_count": 13,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -554,7 +574,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 12,
+   "execution_count": 14,
    "metadata": {},
    "outputs": [
     {
@@ -566,7 +586,7 @@
        "z3"
       ]
      },
-     "execution_count": 12,
+     "execution_count": 14,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -584,7 +604,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 13,
+   "execution_count": 15,
    "metadata": {},
    "outputs": [
     {
@@ -596,7 +616,7 @@
        "FALSE"
       ]
      },
-     "execution_count": 13,
+     "execution_count": 15,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -614,7 +634,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 14,
+   "execution_count": 16,
    "metadata": {},
    "outputs": [
     {
@@ -622,8 +642,8 @@
       "text/markdown": [
        "|w1|w2|w3|\n",
        "|---|---|---|\n",
-       "|$0$|$1$|$0$|\n",
-       "|$0$|$1$|$1$|\n"
+       "|0|1|0|\n",
+       "|0|1|1|\n"
       ],
       "text/plain": [
        "w1\tw2\tw3\n",
@@ -631,7 +651,7 @@
        "0\t1\t1\n"
       ]
      },
-     "execution_count": 14,
+     "execution_count": 16,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -642,7 +662,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 15,
+   "execution_count": 17,
    "metadata": {},
    "outputs": [
     {
@@ -650,10 +670,10 @@
       "text/markdown": [
        "|w1|w2|w3|w4|\n",
        "|---|---|---|---|\n",
-       "|$0$|$1$|$0$|$0$|\n",
-       "|$0$|$1$|$0$|$1$|\n",
-       "|$0$|$1$|$1$|$0$|\n",
-       "|$0$|$1$|$1$|$1$|\n"
+       "|0|1|0|0|\n",
+       "|0|1|0|1|\n",
+       "|0|1|1|0|\n",
+       "|0|1|1|1|\n"
       ],
       "text/plain": [
        "w1\tw2\tw3\tw4\n",
@@ -663,7 +683,7 @@
        "0\t1\t1\t1\n"
       ]
      },
-     "execution_count": 15,
+     "execution_count": 17,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -824,7 +844,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 21,
+   "execution_count": 18,
    "metadata": {},
    "outputs": [
     {
@@ -833,7 +853,7 @@
        "Loaded machine: DFA"
       ]
      },
-     "execution_count": 21,
+     "execution_count": 18,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -874,16 +894,16 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 22,
+   "execution_count": 19,
    "metadata": {},
    "outputs": [
     {
      "data": {
       "text/plain": [
-       "Machine constants set up using operation 0: $setup_constants()"
+       "Executed operation: SETUP_CONSTANTS()"
       ]
      },
-     "execution_count": 22,
+     "execution_count": 19,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -902,7 +922,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 23,
+   "execution_count": 20,
    "metadata": {},
    "outputs": [
     {
@@ -914,7 +934,7 @@
        "z0"
       ]
      },
-     "execution_count": 23,
+     "execution_count": 20,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -932,7 +952,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 24,
+   "execution_count": 21,
    "metadata": {},
    "outputs": [
     {
@@ -944,7 +964,7 @@
        "z1"
       ]
      },
-     "execution_count": 24,
+     "execution_count": 21,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -955,7 +975,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 25,
+   "execution_count": 22,
    "metadata": {},
    "outputs": [
     {
@@ -967,7 +987,7 @@
        "TRUE"
       ]
      },
-     "execution_count": 25,
+     "execution_count": 22,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -978,7 +998,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 26,
+   "execution_count": 23,
    "metadata": {},
    "outputs": [
     {
@@ -990,7 +1010,7 @@
        "FALSE"
       ]
      },
-     "execution_count": 26,
+     "execution_count": 23,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -1008,7 +1028,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 27,
+   "execution_count": 24,
    "metadata": {},
    "outputs": [
     {
@@ -1017,74 +1037,74 @@
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
        "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
        " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
-       "<!-- Generated by graphviz version 2.44.1 (0)\n",
+       "<!-- Generated by graphviz version 8.0.1 (20230327.1645)\n",
        " -->\n",
        "<!-- Title: prob_graph Pages: 1 -->\n",
-       "<svg width=\"540pt\" height=\"714pt\"\n",
-       " viewBox=\"0.00 0.00 540.00 713.63\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
-       "<g id=\"graph0\" class=\"graph\" transform=\"scale(0.98 0.98) rotate(0) translate(4 726.01)\">\n",
+       "<svg width=\"540pt\" height=\"717pt\"\n",
+       " viewBox=\"0.00 0.00 540.00 717.37\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
+       "<g id=\"graph0\" class=\"graph\" transform=\"scale(0.985401 0.985401) rotate(0) translate(4 724)\">\n",
        "<title>prob_graph</title>\n",
-       "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-726.01 548.39,-726.01 548.39,4 -4,4\"/>\n",
+       "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-724 544,-724 544,4 -4,4\"/>\n",
        "<!-- 0 -->\n",
        "<g id=\"node1\" class=\"node\">\n",
        "<title>0</title>\n",
-       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"232.28\" cy=\"-484\" rx=\"18.44\" ry=\"18.44\"/>\n",
-       "<ellipse fill=\"none\" stroke=\"black\" cx=\"232.28\" cy=\"-484\" rx=\"22.44\" ry=\"22.44\"/>\n",
-       "<text text-anchor=\"middle\" x=\"232.28\" y=\"-480.9\" font-family=\"Times,serif\" font-size=\"12.00\">z0</text>\n",
+       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"229.38\" cy=\"-482\" rx=\"18\" ry=\"18\"/>\n",
+       "<ellipse fill=\"none\" stroke=\"black\" cx=\"229.38\" cy=\"-482\" rx=\"22\" ry=\"22\"/>\n",
+       "<text text-anchor=\"middle\" x=\"229.38\" y=\"-478.9\" font-family=\"Times,serif\" font-size=\"12.00\">z0</text>\n",
        "</g>\n",
        "<!-- 1 -->\n",
        "<g id=\"node2\" class=\"node\">\n",
        "<title>1</title>\n",
-       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"86.28\" cy=\"-260\" rx=\"18.44\" ry=\"18.44\"/>\n",
-       "<text text-anchor=\"middle\" x=\"86.28\" y=\"-256.9\" font-family=\"Times,serif\" font-size=\"12.00\">z1</text>\n",
+       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"86.38\" cy=\"-258\" rx=\"18\" ry=\"18\"/>\n",
+       "<text text-anchor=\"middle\" x=\"86.38\" y=\"-254.9\" font-family=\"Times,serif\" font-size=\"12.00\">z1</text>\n",
        "</g>\n",
        "<!-- 0&#45;&gt;1 -->\n",
        "<g id=\"edge4\" class=\"edge\">\n",
        "<title>0&#45;&gt;1</title>\n",
-       "<path fill=\"none\" stroke=\"red\" d=\"M217.23,-466.78C198.51,-446.12 166.22,-408.84 143.28,-373.5 124.82,-345.06 107.83,-309.85 97.3,-286.48\"/>\n",
-       "<polygon fill=\"red\" stroke=\"red\" points=\"100.45,-284.96 93.19,-277.24 94.05,-287.8 100.45,-284.96\"/>\n",
-       "<text text-anchor=\"middle\" x=\"147.28\" y=\"-363.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
+       "<path fill=\"none\" stroke=\"red\" d=\"M215.21,-465.05C197.23,-444.37 165.85,-406.77 143.38,-371.5 125.22,-343 108.23,-307.97 97.61,-284.64\"/>\n",
+       "<polygon fill=\"red\" stroke=\"red\" points=\"100.49,-283.5 93.2,-275.81 94.1,-286.37 100.49,-283.5\"/>\n",
+       "<text text-anchor=\"middle\" x=\"146.88\" y=\"-361.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
        "</g>\n",
        "<!-- 2 -->\n",
        "<g id=\"node3\" class=\"node\">\n",
        "<title>2</title>\n",
-       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"213.28\" cy=\"-46\" rx=\"18.44\" ry=\"18.44\"/>\n",
-       "<text text-anchor=\"middle\" x=\"213.28\" y=\"-42.9\" font-family=\"Times,serif\" font-size=\"12.00\">z2</text>\n",
+       "<ellipse fill=\"lightgrey\" stroke=\"black\" cx=\"215.38\" cy=\"-45\" rx=\"18\" ry=\"18\"/>\n",
+       "<text text-anchor=\"middle\" x=\"215.38\" y=\"-41.9\" font-family=\"Times,serif\" font-size=\"12.00\">z2</text>\n",
        "</g>\n",
        "<!-- 0&#45;&gt;2 -->\n",
        "<g id=\"edge1\" class=\"edge\">\n",
        "<title>0&#45;&gt;2</title>\n",
-       "<path fill=\"none\" stroke=\"green\" d=\"M231.34,-461.38C228.19,-389.17 218.05,-156.34 214.51,-75.2\"/>\n",
-       "<polygon fill=\"green\" stroke=\"green\" points=\"217.99,-74.63 214.06,-64.79 211,-74.94 217.99,-74.63\"/>\n",
-       "<text text-anchor=\"middle\" x=\"227.28\" y=\"-256.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
+       "<path fill=\"none\" stroke=\"green\" d=\"M228.7,-459.72C226.39,-388.03 218.9,-155.21 216.29,-74.14\"/>\n",
+       "<polygon fill=\"green\" stroke=\"green\" points=\"219.76,-74.2 215.94,-64.32 212.76,-74.43 219.76,-74.2\"/>\n",
+       "<text text-anchor=\"middle\" x=\"226.88\" y=\"-254.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
        "</g>\n",
        "<!-- 1&#45;&gt;0 -->\n",
        "<g id=\"edge2\" class=\"edge\">\n",
        "<title>1&#45;&gt;0</title>\n",
-       "<path fill=\"none\" stroke=\"green\" d=\"M96.04,-275.83C120.33,-312.77 183.8,-409.27 214.77,-456.37\"/>\n",
-       "<polygon fill=\"green\" stroke=\"green\" points=\"211.92,-458.4 220.33,-464.83 217.76,-454.55 211.92,-458.4\"/>\n",
-       "<text text-anchor=\"middle\" x=\"163.28\" y=\"-363.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
+       "<path fill=\"none\" stroke=\"green\" d=\"M95.93,-273.83C119.63,-310.62 181.37,-406.47 211.85,-453.78\"/>\n",
+       "<polygon fill=\"green\" stroke=\"green\" points=\"209.32,-455.32 217.68,-461.83 215.21,-451.53 209.32,-455.32\"/>\n",
+       "<text text-anchor=\"middle\" x=\"161.88\" y=\"-361.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
        "</g>\n",
        "<!-- 1&#45;&gt;2 -->\n",
        "<g id=\"edge5\" class=\"edge\">\n",
        "<title>1&#45;&gt;2</title>\n",
-       "<path fill=\"none\" stroke=\"red\" d=\"M95.42,-243.75C117.29,-207.24 172.82,-114.54 199.09,-70.69\"/>\n",
-       "<polygon fill=\"red\" stroke=\"red\" points=\"202.1,-72.49 204.23,-62.11 196.09,-68.89 202.1,-72.49\"/>\n",
-       "<text text-anchor=\"middle\" x=\"158.28\" y=\"-149.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
+       "<path fill=\"none\" stroke=\"red\" d=\"M95.45,-242.16C117.43,-206.22 173.67,-114.22 200.59,-70.19\"/>\n",
+       "<polygon fill=\"red\" stroke=\"red\" points=\"204.09,-72.18 206.32,-61.82 198.12,-68.53 204.09,-72.18\"/>\n",
+       "<text text-anchor=\"middle\" x=\"154.88\" y=\"-148.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
        "</g>\n",
        "<!-- 2&#45;&gt;2 -->\n",
        "<g id=\"edge3\" class=\"edge\">\n",
        "<title>2&#45;&gt;2</title>\n",
-       "<path fill=\"none\" stroke=\"green\" d=\"M229.41,-55.15C239.77,-57.54 249.75,-54.49 249.75,-46 249.75,-40.43 245.45,-37.2 239.57,-36.31\"/>\n",
-       "<polygon fill=\"green\" stroke=\"green\" points=\"239.21,-32.83 229.41,-36.85 239.58,-39.82 239.21,-32.83\"/>\n",
-       "<text text-anchor=\"middle\" x=\"253.75\" y=\"-42.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
+       "<path fill=\"none\" stroke=\"green\" d=\"M231.3,-54.24C241.53,-56.65 251.38,-53.57 251.38,-45 251.38,-39.64 247.53,-36.43 242.15,-35.37\"/>\n",
+       "<polygon fill=\"green\" stroke=\"green\" points=\"242.16,-31.9 232.3,-35.76 242.42,-38.9 242.16,-31.9\"/>\n",
+       "<text text-anchor=\"middle\" x=\"254.88\" y=\"-41.9\" font-family=\"Times,serif\" font-size=\"12.00\">1</text>\n",
        "</g>\n",
        "<!-- 2&#45;&gt;2 -->\n",
        "<g id=\"edge6\" class=\"edge\">\n",
        "<title>2&#45;&gt;2</title>\n",
-       "<path fill=\"none\" stroke=\"red\" d=\"M226.41,-59.05C244.92,-71.36 267.75,-67.01 267.75,-46 267.75,-28.43 251.79,-22.51 235.75,-28.23\"/>\n",
-       "<polygon fill=\"red\" stroke=\"red\" points=\"233.76,-25.32 226.41,-32.95 236.91,-31.57 233.76,-25.32\"/>\n",
-       "<text text-anchor=\"middle\" x=\"271.75\" y=\"-42.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
+       "<path fill=\"none\" stroke=\"red\" d=\"M228.12,-57.99C246.52,-70.65 269.38,-66.32 269.38,-45 269.38,-27.35 253.7,-21.34 237.87,-26.99\"/>\n",
+       "<polygon fill=\"red\" stroke=\"red\" points=\"236.41,-24.32 229.12,-32.01 239.62,-30.54 236.41,-24.32\"/>\n",
+       "<text text-anchor=\"middle\" x=\"272.88\" y=\"-41.9\" font-family=\"Times,serif\" font-size=\"12.00\">0</text>\n",
        "</g>\n",
        "<!-- 3 -->\n",
        "<g id=\"node4\" class=\"node\">\n",
@@ -1093,17 +1113,17 @@
        "<!-- 3&#45;&gt;0 -->\n",
        "<g id=\"edge7\" class=\"edge\">\n",
        "<title>3&#45;&gt;0</title>\n",
-       "<path fill=\"none\" stroke=\"black\" d=\"M232.28,-658.71C232.28,-626.68 232.28,-557.66 232.28,-516.92\"/>\n",
-       "<polygon fill=\"black\" stroke=\"black\" points=\"235.78,-516.73 232.28,-506.73 228.78,-516.73 235.78,-516.73\"/>\n",
+       "<path fill=\"none\" stroke=\"black\" d=\"M229.38,-657.05C229.38,-625.24 229.38,-556.12 229.38,-515.2\"/>\n",
+       "<polygon fill=\"black\" stroke=\"black\" points=\"232.88,-515.22 229.38,-505.22 225.88,-515.22 232.88,-515.22\"/>\n",
        "</g>\n",
        "</g>\n",
-       "</svg>"
+       "</svg>\n"
       ],
       "text/plain": [
        "<Dot visualization: custom_graph []>"
       ]
      },
-     "execution_count": 27,
+     "execution_count": 24,
      "metadata": {},
      "output_type": "execute_result"
     }
@@ -1112,6 +1132,70 @@
     ":dot custom_graph"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "In Java sähe dieser Automat zB so aus:\n",
+    "```\n",
+    "public class DFA {\n",
+    "   public static int delta (int state, char next) {\n",
+    "    switch(state) {\n",
+    "       case 0: if (next == '0') return 1; else return 2;\n",
+    "       \n",
+    "       case 1: if (next == '1') return 0; else return 2;\n",
+    "       \n",
+    "       default: return 2;\n",
+    "    }\n",
+    "  }\n",
+    "  static int initial_state = 0;\n",
+    "  static boolean isFinal (int state) {\n",
+    "     return (state==0); \n",
+    "  }\n",
+    "   \n",
+    "   public static boolean accept(String s) {\n",
+    "     int state = initial_state;\n",
+    "     for (int i = 0; i < s.length(); i++){\n",
+    "        state = delta(state,s.charAt(i));\n",
+    "        System.out.println(\"-- \" + s.charAt(i) + \" --> State \" + state);\n",
+    "     }\n",
+    "     return isFinal(state);\n",
+    "   }\n",
+    "\n",
+    "   public static void main(String[] args) throws java.io.IOException {\n",
+    "        \n",
+    "         if (args.length > 0) {\n",
+    "            System.out.println(\"Processing \"+ args[0]);\n",
+    "            System.out.println(\"Accepted: \" + accept(args[0]));\n",
+    "         } else {\n",
+    "            System.out.println(\"Provide string to process as argument\");\n",
+    "         }\n",
+    "    }\n",
+    "}\n",
+    "```"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "```\n",
+    "$ java DFA 011\n",
+    "Processing 011\n",
+    "-- 0 --> State 1\n",
+    "-- 1 --> State 0\n",
+    "-- 1 --> State 2\n",
+    "Accepted: false\n",
+    "$ java DFA 0101\n",
+    "Processing 0101\n",
+    "-- 0 --> State 1\n",
+    "-- 1 --> State 0\n",
+    "-- 0 --> State 1\n",
+    "-- 1 --> State 0\n",
+    "Accepted: true\n",
+    "```"
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": null,
-- 
GitLab