{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Edition, visualisation, traversal\n", "## Boolean automata\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "IPython.notebook.set_autosave_interval(0)" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "Autosave disabled\n" ] } ], "source": [ "# We disable autosave for technical reasons.\n", "# Replace 0 by 120 in next line to restore default.\n", "%autosave 0" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[Warning] The python module awalipy relies on compilation executed \"on-the-fly\" depending on the context (type of weights, of labels, etc.). As a result, the very first call to a given function in a given context may take up to 10 seconds. \n" ] } ], "source": [ "import awalipy # If import fails, check that \n", " # Python version used as Jupyter\n", " # kernel matches the one\n", " # Awalipy was compiled with." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "(The above warning is displayed every time awalipy is imported.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating an automaton" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alphabets we use are Python `str`\n", "- each `char` of the `str` is a letter the alphabet\n", "- order does not matter (`\"abc\"` and `\"bac\"` represent the same alphabet)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "alph1 = \"abc\" # represents {a,b,c}\n", "alph2 = \"01\" # represents {0,1}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "An **automaton** is built from an alphabet" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "A = awalipy.Automaton(alph1)\n", "# or directly `awalipy.Automaton(\"abc\")`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`A` is an automaton with no states and no transitions over the alphabet {a,b,c}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "Adding states\n", "\n", "By default the displayed name of the state is given by its index: the first state is named `\"s0\"`, the second `\"s1\"`, etc." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "stt_0 = A.add_state()\n", "stt_1 = A.add_state()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "Adding transitions" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "tr_0 = A.set_transition(stt_0,stt_1,'a')\n", "tr_1 = A.set_transition(stt_1,stt_0,'b')\n", "tr_2 = A.set_transition(stt_0,stt_0,'b')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "