{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7a4f5abe",
   "metadata": {},
   "outputs": [],
   "source": [
    "from utils import create_automata, print_automata, save_automata"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "961cdf49",
   "metadata": {},
   "source": [
    "# Creation of the DFA for Ordered Fashion MNIST"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c94de34c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Automata saved to ../data/automatons/ordered_fashion_mnist_automata.json\n"
     ]
    }
   ],
   "source": [
    "ltlf_formula = \"G(t_shirt_top => !F shirt) & G(t_shirt_top => !F dress) & G(t_shirt_top => WXG !t_shirt_top) & G(trouser => !F dress) & G(trouser => WXG !trouser) & G(pullover => !F dress) & G(pullover => !F t_shirt_top) & G(pullover => !F shirt) & G(pullover => WXG !pullover) & G(dress => !F t_shirt_top) & G(dress => !F shirt) & G(dress => !F trouser) & G(dress => !F pullover) & G(dress => WXG !dress) & G(coat => !F t_shirt_top) & G(coat => !F shirt) & G(coat => !F pullover) & G(coat => !F dress) & G(coat => WXG !coat) & G(sandal => !F sneaker) & G(sandal => !F trouser) & G(sandal => !F ankle_boot) & G(sandal => WXG !sandal) & G(shirt => !F t_shirt_top) & G(shirt => !F dress) & G(shirt => WXG !shirt) & G(sneaker => !F sandal) & G(sneaker => !F trouser) & G(sneaker => !F ankle_boot) & G(sneaker => WXG !sneaker) & G(bag => !F t_shirt_top) & G(bag => !F shirt) & G(bag => !F dress) & G(bag => !F pullover) & G(bag => !F coat) & G(bag => WXG !bag) & G(ankle_boot => !F sandal) & G(ankle_boot => !F trouser) & G(ankle_boot => !F sneaker) & G(ankle_boot => WXG !ankle_boot) & F(t_shirt_top || pullover || shirt || dress) & F(trouser || dress) & F(sandal || sneaker || ankle_boot)\"\n",
    "\n",
    "labels = [\"t_shirt_top\", \"trouser\", \"pullover\", \"dress\", \"coat\", \"sandal\", \"shirt\", \"sneaker\", \"bag\", \"ankle_boot\"]\n",
    "\n",
    "automata = create_automata(ltlf_formula, labels)\n",
    "\n",
    "save_automata(automata, \"../data/automata/ordered_fashion_mnist_automata.json\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ab062804",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "state          distance  | t_shirt_top  trouser      pullover     dress        coat         sandal       shirt        sneaker      bag          ankle_boot   \n",
      "-------------------------------------------------------------------------------------------------------------------------------------------------------------\n",
      "1               2         | 8            5            4            6            2            3            8            3            2            3            \n",
      "2(Deadlock)     inf       | 2            2            2            2            2            2            2            2            2            2            \n",
      "3               1         | 2            2            2            7            2            2            2            2            2            2            \n",
      "4               2         | 2            6            2            2            11           2            2            2            10           2            \n",
      "5               2         | 9            2            6            2            2            14           9            14           2            14           \n",
      "6               1         | 2            2            2            2            13           7            2            7            12           7            \n",
      "7(Accepting)    0         | 2            2            2            2            17           2            2            2            16           2            \n",
      "8               2         | 2            9            4            2            11           2            2            2            10           2            \n",
      "9               1         | 2            2            6            2            13           15           2            15           12           15           \n",
      "10              2         | 2            12           2            2            2            2            2            2            2            2            \n",
      "11              2         | 2            13           2            2            2            2            2            2            10           2            \n",
      "12              1         | 2            2            2            2            2            16           2            16           2            16           \n",
      "13              1         | 2            2            2            2            2            17           2            17           12           17           \n",
      "14              1         | 15           2            7            2            2            2            15           2            2            2            \n",
      "15(Accepting)   0         | 2            2            7            2            17           2            2            2            16           2            \n",
      "16(Accepting)   0         | 2            2            2            2            2            2            2            2            2            2            \n",
      "17(Accepting)   0         | 2            2            2            2            2            2            2            2            16           2            \n"
     ]
    }
   ],
   "source": [
    "print_automata(automata, labels)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a1e0bbd",
   "metadata": {},
   "source": [
    "# Creation of the DFA for CommonGen"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3ade50c",
   "metadata": {},
   "source": [
    "### 3 words automata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3e230175",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Automata saved to ../data/automatons/3_words_commongen_automata.json\n"
     ]
    }
   ],
   "source": [
    "ltlf_formula = \"(!(eos | dot) U (firstword)) & (!(eos | dot) U (secondword)) & (!(eos | dot) U (thirdword)) & F(eos) & G(dot -> X eos) & G(firstword | secondword | thirdword | dot | eos | nomatch)\"\n",
    " \n",
    "labels = [\"firstword\", \"secondword\", \"thirdword\", \"dot\", \"eos\", \"nomatch\"]\n",
    "\n",
    "automata = create_automata(ltlf_formula, labels)\n",
    "\n",
    "save_automata(automata, \"../data/automata/3_words_commongen_automata.json\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "07f26282",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "state          distance  | firstword    secondword   thirdword    dot          eos          nomatch      \n",
      "---------------------------------------------------------------------------------------------------------\n",
      "1               4         | 6            4            3            2            2            1            \n",
      "2(Deadlock)     inf       | 2            2            2            2            2            2            \n",
      "3               3         | 7            5            3            2            2            3            \n",
      "4               3         | 8            4            5            2            2            4            \n",
      "5               2         | 9            5            5            2            2            5            \n",
      "6               3         | 6            8            7            2            2            6            \n",
      "7               2         | 7            9            7            2            2            7            \n",
      "8               2         | 8            8            9            2            2            8            \n",
      "9               1         | 9            9            9            10           11           9            \n",
      "10              1         | 2            2            2            2            11           2            \n",
      "11(Accepting)   0         | 11           11           11           10           11           11           \n"
     ]
    }
   ],
   "source": [
    "print_automata(automata, labels)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "681b1388",
   "metadata": {},
   "source": [
    "### 4 words automata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2857648",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Automata saved to ../data/automatons/4_words_commongen_automata.json\n"
     ]
    }
   ],
   "source": [
    "ltlf_formula = \"(!(eos | dot) U (firstword)) & (!(eos | dot) U (secondword)) & (!(eos | dot) U (thirdword)) & (!(eos | dot) U (fourthword)) & F(eos) & G(dot -> X eos) & G(firstword | secondword | thirdword | fourthword | dot | eos | nomatch)\"\n",
    "\n",
    "labels = [\"firstword\", \"secondword\", \"thirdword\", \"fourthword\", \"dot\", \"eos\", \"nomatch\"]\n",
    "\n",
    "automata = create_automata(ltlf_formula, labels)\n",
    "\n",
    "save_automata(automata, \"../data/automata/4_words_commongen_automata.json\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9f6e875f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "state          distance  | firstword    secondword   thirdword    fourthword   dot          eos          nomatch      \n",
      "----------------------------------------------------------------------------------------------------------------------\n",
      "1               5         | 10           6            4            3            2            2            1            \n",
      "2(Deadlock)     inf       | 2            2            2            2            2            2            2            \n",
      "3               4         | 11           7            5            3            2            2            3            \n",
      "4               4         | 12           8            4            5            2            2            4            \n",
      "5               3         | 13           9            5            5            2            2            5            \n",
      "6               4         | 14           6            8            7            2            2            6            \n",
      "7               3         | 15           7            9            7            2            2            7            \n",
      "8               3         | 16           8            8            9            2            2            8            \n",
      "9               2         | 17           9            9            9            2            2            9            \n",
      "10              4         | 10           14           12           11           2            2            10           \n",
      "11              3         | 11           15           13           11           2            2            11           \n",
      "12              3         | 12           16           12           13           2            2            12           \n",
      "13              2         | 13           17           13           13           2            2            13           \n",
      "14              3         | 14           14           16           15           2            2            14           \n",
      "15              2         | 15           15           17           15           2            2            15           \n",
      "16              2         | 16           16           16           17           2            2            16           \n",
      "17              1         | 17           17           17           17           18           19           17           \n",
      "18              1         | 2            2            2            2            2            19           2            \n",
      "19(Accepting)   0         | 19           19           19           19           18           19           19           \n"
     ]
    }
   ],
   "source": [
    "print_automata(automata, labels)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d27c6f29",
   "metadata": {},
   "source": [
    "### 5 words automata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d3230fc9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Automata saved to ../data/automatons/5_words_commongen_automata.json\n"
     ]
    }
   ],
   "source": [
    "ltlf_formula = \"(!(eos | dot) U (firstword)) & (!(eos | dot) U (secondword)) & (!(eos | dot) U (thirdword)) & (!(eos | dot) U (fourthword)) & (!(eos | dot) U (fifthword)) & F(eos) & G(dot -> X eos) & G(firstword | secondword | thirdword | fourthword | fifthword | dot | eos | nomatch)\"\n",
    "\n",
    "labels = [\"firstword\", \"secondword\", \"thirdword\", \"fourthword\", \"fifthword\", \"dot\", \"eos\", \"nomatch\"]\n",
    "\n",
    "automata = create_automata(ltlf_formula, labels)\n",
    "\n",
    "save_automata(automata, \"../data/automata/5_words_commongen_automata.json\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "03646aa3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "state          distance  | firstword    secondword   thirdword    fourthword   fifthword    dot          eos          nomatch      \n",
      "-----------------------------------------------------------------------------------------------------------------------------------\n",
      "1               6         | 18           10           6            4            3            2            2            1            \n",
      "2(Deadlock)     inf       | 2            2            2            2            2            2            2            2            \n",
      "3               5         | 19           11           7            5            3            2            2            3            \n",
      "4               5         | 20           12           8            4            5            2            2            4            \n",
      "5               4         | 21           13           9            5            5            2            2            5            \n",
      "6               5         | 22           14           6            8            7            2            2            6            \n",
      "7               4         | 23           15           7            9            7            2            2            7            \n",
      "8               4         | 24           16           8            8            9            2            2            8            \n",
      "9               3         | 25           17           9            9            9            2            2            9            \n",
      "10              5         | 26           10           14           12           11           2            2            10           \n",
      "11              4         | 27           11           15           13           11           2            2            11           \n",
      "12              4         | 28           12           16           12           13           2            2            12           \n",
      "13              3         | 29           13           17           13           13           2            2            13           \n",
      "14              4         | 30           14           14           16           15           2            2            14           \n",
      "15              3         | 31           15           15           17           15           2            2            15           \n",
      "16              3         | 32           16           16           16           17           2            2            16           \n",
      "17              2         | 33           17           17           17           17           2            2            17           \n",
      "18              5         | 18           26           22           20           19           2            2            18           \n",
      "19              4         | 19           27           23           21           19           2            2            19           \n",
      "20              4         | 20           28           24           20           21           2            2            20           \n",
      "21              3         | 21           29           25           21           21           2            2            21           \n",
      "22              4         | 22           30           22           24           23           2            2            22           \n",
      "23              3         | 23           31           23           25           23           2            2            23           \n",
      "24              3         | 24           32           24           24           25           2            2            24           \n",
      "25              2         | 25           33           25           25           25           2            2            25           \n",
      "26              4         | 26           26           30           28           27           2            2            26           \n",
      "27              3         | 27           27           31           29           27           2            2            27           \n",
      "28              3         | 28           28           32           28           29           2            2            28           \n",
      "29              2         | 29           29           33           29           29           2            2            29           \n",
      "30              3         | 30           30           30           32           31           2            2            30           \n",
      "31              2         | 31           31           31           33           31           2            2            31           \n",
      "32              2         | 32           32           32           32           33           2            2            32           \n",
      "33              1         | 33           33           33           33           33           34           35           33           \n",
      "34              1         | 2            2            2            2            2            2            35           2            \n",
      "35(Accepting)   0         | 35           35           35           35           35           34           35           35           \n"
     ]
    }
   ],
   "source": [
    "print_automata(automata, labels)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3be513c",
   "metadata": {},
   "source": [
    "# Creation of the DFA for Ordered CommonGen"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "08b64a21",
   "metadata": {},
   "source": [
    "### 3 words automata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a6e27d2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Automata saved to ../data/automatons/3_words_ordered_commongen_automata.json\n"
     ]
    }
   ],
   "source": [
    "ltlf_formula = \"((!(secondword | dot) U (firstword)) & F(secondword)) & ((!(thirdword | dot) U (secondword)) & F(thirdword)) & ((!(eos | dot) U (thirdword)) & F(eos)) & G(dot -> X eos) & G(firstword | secondword | thirdword | dot | eos | nomatch)\"\n",
    "\n",
    "labels = [\"firstword\", \"secondword\", \"thirdword\", \"dot\", \"eos\", \"nomatch\"]\n",
    "\n",
    "automata = create_automata(ltlf_formula, labels)\n",
    "\n",
    "save_automata(automata, \"../data/automata/3_words_ordered_commongen_automata.json\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "bc7146d1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "state          distance  | firstword    secondword   thirdword    dot          eos          nomatch      \n",
      "---------------------------------------------------------------------------------------------------------\n",
      "1               4         | 3            2            2            2            2            1            \n",
      "2(Deadlock)     inf       | 2            2            2            2            2            2            \n",
      "3               3         | 3            4            2            2            2            3            \n",
      "4               2         | 4            4            5            2            2            4            \n",
      "5               1         | 5            5            5            7            6            5            \n",
      "6(Accepting)    0         | 6            6            6            7            6            6            \n",
      "7               1         | 2            2            2            2            6            2            \n"
     ]
    }
   ],
   "source": [
    "print_automata(automata, labels)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aa4f153c",
   "metadata": {},
   "source": [
    "### 4 words automata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c015aaf6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Automata saved to ../data/automatons/4_words_ordered_commongen_automata.json\n"
     ]
    }
   ],
   "source": [
    "ltlf_formula = \"((!(secondword | dot) U (firstword)) & F(secondword)) & ((!(thirdword | dot) U (secondword)) & F(thirdword)) & ((!(fourthword | dot) U (thirdword)) & F(fourthword))  & ((!(eos | dot) U (fourthword)) & F(eos)) & G(dot -> X eos) & G(firstword | secondword | thirdword | fourthword | dot | eos | nomatch)\"\n",
    "\n",
    "labels = [\"firstword\", \"secondword\", \"thirdword\", \"fourthword\", \"dot\", \"eos\", \"nomatch\"]\n",
    "\n",
    "automata = create_automata(ltlf_formula, labels)\n",
    "\n",
    "save_automata(automata, \"../data/automata/4_words_ordered_commongen_automata.json\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "36661c51",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "state          distance  | firstword    secondword   thirdword    fourthword   dot          eos          nomatch      \n",
      "----------------------------------------------------------------------------------------------------------------------\n",
      "1               5         | 3            2            2            2            2            2            1            \n",
      "2(Deadlock)     inf       | 2            2            2            2            2            2            2            \n",
      "3               4         | 3            4            2            2            2            2            3            \n",
      "4               3         | 4            4            5            2            2            2            4            \n",
      "5               2         | 5            5            5            6            2            2            5            \n",
      "6               1         | 6            6            6            6            8            7            6            \n",
      "7(Accepting)    0         | 7            7            7            7            8            7            7            \n",
      "8               1         | 2            2            2            2            2            7            2            \n"
     ]
    }
   ],
   "source": [
    "print_automata(automata, labels)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd9f0c99",
   "metadata": {},
   "source": [
    "### 5 words automata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ded40e6e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Automata saved to ../data/automatons/5_words_ordered_commongen_automata.json\n"
     ]
    }
   ],
   "source": [
    "ltlf_formula = \"((!(secondword | dot) U (firstword)) & F(secondword)) & ((!(thirdword | dot) U (secondword)) & F(thirdword)) & ((!(fourthword | dot) U (thirdword)) & F(fourthword)) & ((!(fifthword | dot) U (fourthword)) & F(fifthword)) & ((!(eos | dot) U (fifthword)) & F(eos)) & G(dot -> X eos) & G(firstword | secondword | thirdword | fourthword | fifthword | dot | eos | nomatch)\"\n",
    "\n",
    "labels = [\"firstword\", \"secondword\", \"thirdword\", \"fourthword\", \"fifthword\", \"dot\", \"eos\", \"nomatch\"]\n",
    "\n",
    "automata = create_automata(ltlf_formula, labels)\n",
    "\n",
    "save_automata(automata, \"../data/automata/5_words_ordered_commongen_automata.json\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "0dc6b5a2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "state          distance  | firstword    secondword   thirdword    fourthword   fifthword    dot          eos          nomatch      \n",
      "-----------------------------------------------------------------------------------------------------------------------------------\n",
      "1               6         | 3            2            2            2            2            2            2            1            \n",
      "2(Deadlock)     inf       | 2            2            2            2            2            2            2            2            \n",
      "3               5         | 3            4            2            2            2            2            2            3            \n",
      "4               4         | 4            4            5            2            2            2            2            4            \n",
      "5               3         | 5            5            5            6            2            2            2            5            \n",
      "6               2         | 6            6            6            6            7            2            2            6            \n",
      "7               1         | 7            7            7            7            7            9            8            7            \n",
      "8(Accepting)    0         | 8            8            8            8            8            9            8            8            \n",
      "9               1         | 2            2            2            2            2            2            8            2            \n"
     ]
    }
   ],
   "source": [
    "print_automata(automata, labels)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
