EventLattice.ipynb 7.74 KB
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "57fc5921-9d6b-4b43-a8f6-743a03650d63",
   "metadata": {},
   "outputs": [],
   "source": [
    "import event_lattice as el"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "00f0eb68",
   "metadata": {},
   "outputs": [],
   "source": [
    "def zoom_event(event_str, lattice, lower_op=el.sum_op, upper_op=el.prod_op):\n",
    "    event = el.Event.from_str(event_str)\n",
    "    event_class = lattice.event_class(event)\n",
    "    propagated = lattice.propagated_value(\n",
    "        event, lower_op=lower_op, upper_op=upper_op)\n",
    "\n",
    "    print(\n",
    "        f\"Event: {event}\\n\\tClass: {event_class} \\n\\tValue: {propagated}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "cdd8c6d6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "\t'stable_models': {\n",
      "\t\t A:     2,\n",
      "\t\tab:     3,\n",
      "\t\tac:     5 \n",
      "\t}\n",
      "\t'literals': { A,B,C,a,b,c } \n",
      "}\n"
     ]
    }
   ],
   "source": [
    "smodels = el.Lattice.parse({\n",
    "    \"A\": 2,\n",
    "    \"ab\": 3,\n",
    "    \"ac\": 5\n",
    "})\n",
    "\n",
    "lattice = el.Lattice(smodels)\n",
    "\n",
    "print(lattice)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "2b445339",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Event: abc\n",
      "\tClass: <|ac,ab> \n",
      "\tValue: 8\n",
      "Event: a\n",
      "\tClass: <ac,ab|> \n",
      "\tValue: 15\n",
      "Event: b\n",
      "\tClass: <ab|> \n",
      "\tValue: 3\n",
      "Event: bc\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: ac\n",
      "\tClass: <ac|ac> \n",
      "\tValue: 5\n"
     ]
    }
   ],
   "source": [
    "zoom_event(\"abc\", lattice)\n",
    "zoom_event(\"a\", lattice)\n",
    "zoom_event(\"b\", lattice)\n",
    "zoom_event(\"bc\", lattice)\n",
    "zoom_event(\"ac\", lattice)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f1b85255",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Event: \n",
      "\tClass: <A,ac,ab|> \n",
      "\tValue: 30\n",
      "Event: A\n",
      "\tClass: <A|A> \n",
      "\tValue: 2\n",
      "Event: b\n",
      "\tClass: <ab|> \n",
      "\tValue: 3\n",
      "Event: a\n",
      "\tClass: <ac,ab|> \n",
      "\tValue: 15\n",
      "Event: B\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: c\n",
      "\tClass: <ac|> \n",
      "\tValue: 5\n",
      "Event: C\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: Ab\n",
      "\tClass: <|A> \n",
      "\tValue: 2\n",
      "Event: Aa\n",
      "\tClass: <|A> \n",
      "\tValue: 0\n",
      "Event: AB\n",
      "\tClass: <|A> \n",
      "\tValue: 2\n",
      "Event: Ac\n",
      "\tClass: <|A> \n",
      "\tValue: 2\n",
      "Event: AC\n",
      "\tClass: <|A> \n",
      "\tValue: 2\n",
      "Event: ab\n",
      "\tClass: <ab|ab> \n",
      "\tValue: 3\n",
      "Event: Bb\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: bc\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: Cb\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: Ba\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: ac\n",
      "\tClass: <ac|ac> \n",
      "\tValue: 5\n",
      "Event: Ca\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: Bc\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: BC\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: Cc\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: Aab\n",
      "\tClass: <|A,ab> \n",
      "\tValue: 0\n",
      "Event: ABb\n",
      "\tClass: <|A> \n",
      "\tValue: 0\n",
      "Event: Abc\n",
      "\tClass: <|A> \n",
      "\tValue: 2\n",
      "Event: ACb\n",
      "\tClass: <|A> \n",
      "\tValue: 2\n",
      "Event: ABa\n",
      "\tClass: <|A> \n",
      "\tValue: 0\n",
      "Event: Aac\n",
      "\tClass: <|A,ac> \n",
      "\tValue: 0\n",
      "Event: ACa\n",
      "\tClass: <|A> \n",
      "\tValue: 0\n",
      "Event: ABc\n",
      "\tClass: <|A> \n",
      "\tValue: 2\n",
      "Event: ABC\n",
      "\tClass: <|A> \n",
      "\tValue: 2\n",
      "Event: ACc\n",
      "\tClass: <|A> \n",
      "\tValue: 0\n",
      "Event: Bab\n",
      "\tClass: <|ab> \n",
      "\tValue: 0\n",
      "Event: abc\n",
      "\tClass: <|ac,ab> \n",
      "\tValue: 8\n",
      "Event: Cab\n",
      "\tClass: <|ab> \n",
      "\tValue: 3\n",
      "Event: Bbc\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: BCb\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: Cbc\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: Bac\n",
      "\tClass: <|ac> \n",
      "\tValue: 5\n",
      "Event: BCa\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: Cac\n",
      "\tClass: <|ac> \n",
      "\tValue: 0\n",
      "Event: BCc\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: ABab\n",
      "\tClass: <|A,ab> \n",
      "\tValue: 0\n",
      "Event: Aabc\n",
      "\tClass: <|A,ac,ab> \n",
      "\tValue: 0\n",
      "Event: ACab\n",
      "\tClass: <|A,ab> \n",
      "\tValue: 0\n",
      "Event: ABbc\n",
      "\tClass: <|A> \n",
      "\tValue: 0\n",
      "Event: ABCb\n",
      "\tClass: <|A> \n",
      "\tValue: 0\n",
      "Event: ACbc\n",
      "\tClass: <|A> \n",
      "\tValue: 0\n",
      "Event: ABac\n",
      "\tClass: <|A,ac> \n",
      "\tValue: 0\n",
      "Event: ABCa\n",
      "\tClass: <|A> \n",
      "\tValue: 0\n",
      "Event: ACac\n",
      "\tClass: <|A,ac> \n",
      "\tValue: 0\n",
      "Event: ABCc\n",
      "\tClass: <|A> \n",
      "\tValue: 0\n",
      "Event: Babc\n",
      "\tClass: <|ac,ab> \n",
      "\tValue: 0\n",
      "Event: BCab\n",
      "\tClass: <|ab> \n",
      "\tValue: 0\n",
      "Event: Cabc\n",
      "\tClass: <|ac,ab> \n",
      "\tValue: 0\n",
      "Event: BCbc\n",
      "\tClass: <|> \n",
      "\tValue: 0\n",
      "Event: BCac\n",
      "\tClass: <|ac> \n",
      "\tValue: 0\n",
      "Event: ABabc\n",
      "\tClass: <|A,ac,ab> \n",
      "\tValue: 0\n",
      "Event: ABCab\n",
      "\tClass: <|A,ab> \n",
      "\tValue: 0\n",
      "Event: ACabc\n",
      "\tClass: <|A,ac,ab> \n",
      "\tValue: 0\n",
      "Event: ABCbc\n",
      "\tClass: <|A> \n",
      "\tValue: 0\n",
      "Event: ABCac\n",
      "\tClass: <|A,ac> \n",
      "\tValue: 0\n",
      "Event: BCabc\n",
      "\tClass: <|ac,ab> \n",
      "\tValue: 0\n",
      "Event: ABCabc\n",
      "\tClass: <|A,ac,ab> \n",
      "\tValue: 0\n"
     ]
    }
   ],
   "source": [
    "from itertools import *\n",
    "\n",
    "lits = lattice.literals()\n",
    "events = []\n",
    "for len_lit in range(len(lits)+1):\n",
    "    events = events + list(\"\".join(c) for c in combinations(lits, len_lit))\n",
    "for event in events:\n",
    "    zoom_event(event, lattice)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "07973a47",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.9.15"
  },
  "vscode": {
   "interpreter": {
    "hash": "a59afa236e16843183c59a167f072b6fa0409044b3c4938e82ac98aad91bf217"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}