{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "brNDGX-kvzds"
   },
   "source": [
    "# Template for Notes for CIS 521 Midterm 1\n",
    "\n",
    "The midterm exam for CIS 521 will be **open notes**. No other matierals are allowed for the exam - you may not use the textbook, the internet, a Python envionement, or communicate with anyone during the exam. \n",
    "\n",
    "This python notebook is where you should save all of your notes.  It provides a structured template that allows you to add summaries for each of the textbook sections that are part of the required reading, plus room for lecture notes and definitions.\n",
    "\n",
    "Your summaries must be written in your own words.  Do not copy and paste from the textbook.  Do not share your notes with classmates, or copy any of your classmates' notes.  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "aPtM8g7R0Pds"
   },
   "source": [
    "# Instructions\n",
    "\n",
    "1. Make a copy of this Google Colab file. From the colab menu, pick **File > Save a copy in Drive**.  That will save a copy of this notebook in your Google drive.\n",
    "2. Go through each section of the notebook, and fill in all the summaries for each chapter and its corresponding sections.  Be sure to save your work frequently!\n",
    "3. Read the notes below about how you can format your summaries.\n",
    "4. In addition to these notes, you are allowed 1 page (both sides) for figures or handwritten notes.\n",
    "5. Submit your version of this notebook to Gradescope before you start the exam.\n",
    "6. If you are taking the exam in person, then you must print a copy of your notes for yourself.   Here's how to print: \n",
    "* Run the last cell of this notebook\n",
    "* Click the \"Mirror cell in tab\" button (this is located in the upper right corner of the cell, immediately to the right of the trash can).  This will open the cell.  \n",
    "* In Chrome, you can then print your notes using the **File > Print** option from the browser's menu.  \n",
    "* In the print options, change the layout from Landscape to Portrait. \n",
    "* Clicking the Save, will save a PDF that you can then print.\n",
    "\n",
    "## Formatting Notes\n",
    "\n",
    "1. The max length for each section's summary is 500 words / 3000 characters.\n",
    "2. You can also write a 2000 word summary of the lectures for each module.\n",
    "3. You may also write definitions of concepts for each module.  The definitions should be written in your own words (not copy and pasted), and they should be no more than 20 words long for each concept. \n",
    "2. You can use Markdown formatting for your summaries. \n",
    "3. You can use Latex formatting for equations. Put two dollar signs before and after your equation like this: \n",
    "$$ \\epsilon = \\frac{1}{mc^2} $$\n",
    "4. When you write python code or psuedocode algorithms, you should surround it with triple backticks like this:\n",
    "```\n",
    "def function():\n",
    "      print('hello world')\n",
    "```\n",
    "5. Write \\ whenever you want to keep writing on the next line without a newline being inserted."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "cw5IpDLCZa4W"
   },
   "source": [
    "## Example summary\n",
    "\n",
    "This is a sample summary of [Section 2.1.1](https://web.stanford.edu/~jurafsky/slp3/2.pdf ) of Jurfasky and Martin's Speech and Language Processing's book\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "lzaavW96tcxM",
    "outputId": "6bf32633-bfe7-43e0-e3d1-5267442c4483"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The example summary is 116 words long, so you could write an additional 384 words.\n"
     ]
    }
   ],
   "source": [
    "chapter_2_1_example = \"\"\"\n",
    "Regular expressions are an algebraic notation for characterizing \\\n",
    "a set of strings that are useful for searching for a pattern or through a corpus.\\\n",
    "Only the first matching result will be shown. The search string is case sensitive, \\\n",
    "but it can consist of a single character or a sequence of characters. \\\n",
    "While square braces specify a disjunction of characters, the dash can more easily look \\\n",
    "for characters over a range. The caret specifies the non-existence of a character. \\\n",
    "Additionally, the (?) is used to for flexibility on a single character, meaning \\\n",
    "\"the preceding character or nothing\". More importantly, the Kleene star means zero or \\\n",
    "more occurrences of the immediately previous character or regular expression in square braces.\\\n",
    "...\n",
    "\"\"\"\n",
    "\n",
    "length = len(chapter_2_1_example.split(\" \"))\n",
    "print(\"The example summary is {len} words long, so you could write an additional \\\n",
    "{remaining} words.\".format(len=length, remaining=(500-length)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "s3Uk9gQTevcj"
   },
   "source": [
    "## Example summary length\n",
    "\n",
    "The maximum summary length for each section is 500 words / 3000 characters.  Hopefully you'll find that to be quite generous. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "8DvZ57A-djo1",
    "outputId": "c87570dc-8da2-4427-b8ed-eff9ca311072"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The length in words is 500\n",
      "The length in characters is 3030\n"
     ]
    }
   ],
   "source": [
    "# This is an example of a 500 word placeholder\n",
    "placeholder = \"\"\"ultrices vitae auctor eu augue ut lectus arcu bibendum at varius \\\n",
    " vel pharetra vel turpis nunc eget lorem dolor sed viverra ipsum nunc aliquet \\\n",
    " bibendum enim facilisis gravida neque convallis a cras semper auctor neque vitae \\\n",
    " tempus quam pellentesque nec nam aliquam sem et tortor consequat id porta nibh \\\n",
    " venenatis cras sed felis eget velit aliquet sagittis id consectetur purus ut \\\n",
    " faucibus pulvinar elementum integer enim neque volutpat ac tincidunt vitae semper \\ \n",
    " quis lectus nulla at volutpat diam ut venenatis tellus in metus vulputate eu \\\n",
    " scelerisque felis imperdiet proin fermentum leo vel orci porta non pulvinar neque \\ \n",
    " laoreet suspendisse interdum consectetur libero id faucibus nisl tincidunt eget \\\n",
    " nullam non nisi est sit amet facilisis magna etiam tempor orci eu lobortis \\\n",
    " elementum nibh tellus molestie nunc non blandit massa enim nec dui nunc mattis \\\n",
    " enim ut tellus elementum sagittis vitae et leo duis ut diam quam nulla porttitor \\\n",
    " massa id neque aliquam vestibulum morbi blandit cursus risus at ultrices mi tempus \\\n",
    " imperdiet nulla malesuada pellentesque elit eget gravida cum sociis natoque \\\n",
    " penatibus et magnis dis parturient montes nascetur ridiculus mus mauris vitae \\\n",
    " ultricies leo integer malesuada nunc vel risus commodo viverra maecenas accumsan \\\n",
    " lacus vel facilisis volutpat est velit egestas dui id ornare arcu odio ut sem nulla \\\n",
    " pharetra diam sit amet nisl suscipit adipiscing bibendum est ultricies integer \\\n",
    " quis auctor elit sed vulputate mi sit amet mauris commodo quis imperdiet massa \\\n",
    " tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada proin libero nunc \\\n",
    " consequat interdum varius sit amet mattis vulputate enim nulla aliquet porttitor \\\n",
    " lacus luctus accumsan tortor posuere ac ut consequat semper viverra nam libero \\\n",
    " justo laoreet sit amet cursus sit amet dictum sit amet justo donec enim diam \\\n",
    " vulputate ut pharetra sit amet aliquam id diam maecenas ultricies mi eget mauris \\\n",
    " pharetra et ultrices neque ornare aenean euismod elementum nisi quis eleifend quam \\\n",
    " adipiscing vitae proin sagittis nisl rhoncus mattis rhoncus urna neque viverra justo \\\n",
    " nec ultrices dui sapien eget mi proin sed libero enim sed faucibus turpis in \\\n",
    " eu mi bibendum neque egestas congue quisque egestas diam in arcu cursus euismod \\\n",
    " quis viverra nibh cras pulvinar mattis nunc sed blandit libero volutpat sed cras \\\n",
    " ornare arcu dui vivamus arcu felis bibendum ut tristique et egestas quis ipsum \\\n",
    " suspendisse ultrices gravida dictum fusce ut placerat orci nulla pellentesque \\\n",
    " dignissim enim sit amet venenatis urna cursus eget nunc scelerisque viverra mauris \\\n",
    " in aliquam sem fringilla ut morbi tincidunt augue interdum velit euismod in \\\n",
    " pellentesque massa placerat duis ultricies lacus sed turpis tincidunt id aliquet \\\n",
    " risus feugiat in ante metus dictum at tempor commodo ullamcorper a lacus vestibulum \\\n",
    " sed arcu non odio euismod lacinia at quis risus sed vulputate odio ut enim blandit \\\n",
    " volutpat maecenas volutpat blandit aliquam etiam erat velit scelerisque in \\\n",
    " dictum non consectetur a erat nam at lectus urna\"\"\"\n",
    "\n",
    "print(\"The length in words is\", len(placeholder.split(' ')))\n",
    "print(\"The length in characters is\", len(placeholder))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "5yG3-YncJfTB"
   },
   "source": [
    "# Permissions to use your summaries\n",
    "\n",
    "We'd like to use your summaries to help develop better educational resources like [remember.school](https://remember.school) or a question-answering system about the textbook.  \n",
    "\n",
    "1. Please enter your name.  \n",
    "\n",
    "2. If you grant permission for us to use your summaries under a [Creative Commons License](https://creativecommons.org/licenses/by/4.0/), please set ```permission = True```.  If you do not grant permission, please set it to false. Your answer won't affect your grade.\n",
    "\n",
    "3. If you grant us permission, and you'd like to remain anonymous, set ```anonymous = True```.  We'll remove your name before sharing your summaries with anyone. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "id": "2RECnJArJew4"
   },
   "outputs": [],
   "source": [
    "name = \"\"\n",
    "permission = True\n",
    "anonymous = True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "GZZXyrV-xuAp"
   },
   "source": [
    "# Module 1 - Intro to AI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "id": "Y2NfE1CKxzS-"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA 4th Edition, Chapter 1 “Introduction”, Section 1.1 “What is AI”\n",
    "\n",
    "chapter1_1 = \"\"\" Chapter 1.1 summary. \n",
    "Four approaches to develpoing AI:\n",
    "- Creating systems that act human\n",
    "  - Validate with Turing test\n",
    "- Create systems that think humanly\n",
    "  - Roots in cognitive science. Study the brain\n",
    "- Create systems that think rationally:\n",
    "  - Fomral logic (Chapter 7 - Logical agents)\n",
    "- Create systems that act rationally\n",
    "  - Maximize expected utility\n",
    "  - Approach taken in this course and texbook\n",
    "  - More of an \"engineering\" approach. Does it do what it is supposed to?\n",
    "  - \"Do the right thing\" = Maximize expected utility\n",
    "\"\"\" \n",
    "\n",
    "# Russell and Norvig, AIMA 4th Edition, Chapter 27 “Philosophical Foundations”, Sections 27.1 “The Limits of AI” and 27.2 “Can Machines Really Think?”\n",
    "chapter27_1 = \"\"\" \n",
    "**Arguments for limits of AI**:\n",
    "- human behavior too complex to model with formal logic in computer (qualification problem)\n",
    "- Can't study functioning of brain outside of body (*embodied cognititon*)\n",
    "- Qualificatoin problem: Computer can never do X\n",
    "  - Computers have been able to do a lot that have been predicted that they can't\n",
    "  - People fall in love with Teddy Bears\n",
    "- Godels' incompleteness theorem (In any formal axiomatic framework, can construct a sentence that cannot be proven, but is still true)\n",
    "  - Claims that computers need to obey, but humans do not, so AI can never be as good as human intelligence\n",
    "  - but only applies to math, not cognitiion\n",
    "  - Not really a big deal, and human brains don't really have special properties\n",
    " \"\"\"\n",
    "chapter27_2 = \"\"\" \n",
    "- Conciusness is ill defined\n",
    "- Chinese room problem by Searle: Computers just blindly following instructions, don't really understand\n",
    "  - Counter argument: Human cells, just blindly following instructions, don't really understand.\"\"\"\n",
    "\n",
    "# Russell and Norvig, AIMA 4th Edition, Chapter 2 “Intelligent Agents” (whole chapter)\n",
    "chapter2_1 = \"\"\"\n",
    "- Percept: What an agent perceives (at current time)\n",
    "- Actuators: act upon environment\n",
    "- Percept sequence: history of everything agent has perceived\n",
    "- Agent function vs agent program:\n",
    "  - Agent function maps percepts sequences to actoins\n",
    "  - Agent program is an implementation of agent function\n",
    "  -  \"\"\"\n",
    "chapter2_2 = \"\"\" \n",
    "In desigining rational agents, give them performance measures. Rational agents need to \\\n",
    "maximize expcted performance measure by choosing best actions given percept sqeunce. \\\n",
    "Note that agent only needs to maximize **expected** performance meaure, not actual. ]\n",
    "Don't say that an agent isn't rational due to bad luck. Can't expect ominisinece. \n",
    "\n",
    "Can say that a thermometer is an agent.\n",
    "\"\"\"\n",
    "chapter2_3 = \"\"\" \n",
    "Group **P**erformance measure, **E**nvironment, **A**ctuators, and **S**ensors under the \\\n",
    "acronym **PEAS**. \n",
    "\n",
    "## Properties of task environments:\n",
    "- Fully observable vs partially observable \n",
    "  - Could also have unobservable environments...\n",
    "- Single agent vs multiagent\n",
    "  - In this context, another entity can be considered to be an agent if it is trying to maximize\\\n",
    "  a performance measure that is affected by principal's agent's actions\n",
    "- Deterministic vs non-determinstic\n",
    "  - Partially observable environments or very complex ones can be effectively non-deterministic\n",
    "  - textbook uses stochastic to refer to environments with explicit probabilities, while non-determnistic is used\n",
    "  for environments where probablities not explicitly defined, but know that outcome of actions not always the same\n",
    "- Static vs dynamic\n",
    "  - Does the environment change even when agent doesn't take an action?\n",
    "- episodic vs sequential?\n",
    "  - Is performance measure evaluated after single percept followed by single action,\n",
    "  with future percepts not depending on action? (episodic)\n",
    "    - Ex: clasification problems\n",
    "  - Or does agent make series of actions, where future percepts/state of world depends on\n",
    "  action? (sequential)\n",
    "    - Ex: chess\n",
    "- Discrete vs continous\n",
    "  - Way time is handled\n",
    "  - chess is discrete, playing starcraft is effectively continous (even if everything is discrete in computer representation)\n",
    "- Known vs unknown\n",
    "  - are rules of environment codified into agent?\n",
    "\n",
    "Hardest environment is partially observable, multiaent, non-determnistic, sequential, continours, and unknown.\\\n",
    "Autonomous cars checks most of these boxes, except most things are known (such as rules of road, physics etcc..)\n",
    "Could make more difficult by trying to drive in new country where rules of road are unknown, or install on janky car... \n",
    " \"\"\"\n",
    "chapter2_4 = \"\"\" \n",
    "Agent program runs on a certain architeture (physical computing device, sensors and actuators, etc..)\n",
    "\n",
    "Different kind of agents:\n",
    "- table lookups\n",
    "  - percept sequences quickly become too large for this approach\n",
    "- reflex agents\n",
    "  - just choose action on current percept, ignore history\n",
    "- Model-based reflex agents\n",
    "  - Keep track of (relevant) unobserved world. Take into account in addition to current percept.\n",
    "- Goal based agents\n",
    "  - Model how actions will affect world, so can plan better\n",
    "  - Search problems are examples of goal based agents\n",
    "- Utility based agents\n",
    "  - Model performance measure with utility function\n",
    "  - try to maximize utiltiy\n",
    "  - Helps make tradeoffs and choose between different goals\n",
    "  - Try to maximize expected utiltiy\n",
    "\n",
    "Can combine different approaches. Put reflexive actions inside of more complex utility based agents when decision is clear.\n",
    "\n",
    "Want agent programs that learn, so we don't need to code everything in advance.\n",
    "\n",
    "Can have atomic represenations of world (states with no internal, such as for simple search), \\\n",
    "factored (states have internal variables or attributes such as in CSPs or logic agents),\\\n",
    "or structured (first order logic and natural language).\n",
    "\"\"\"\n",
    "\n",
    "# Lecture notes \n",
    "module1_lecture_notes = \"\"\"\n",
    "- Things that can be viewed as agents:\n",
    "  - pet hamster\n",
    "  - thermostat\n",
    "  - touchless faucet\n",
    "  - (but not bathroom faucet turned on by handle)\n",
    "\"\"\"\n",
    "\n",
    "\n",
    "# Definitions of concepts from Module 1.\n",
    "# You can define any bolded term in the textbook, \n",
    "# but you most use your own words for the definitions.\n",
    "# Each definition should be at most 20 words long.\n",
    "module1_definitions = {\n",
    "\"agent\" : \"anything that can perceive and act in an environment\",\n",
    "\"percept\" : \"your definitions here\",\n",
    "\"other concept\" : \"your definitions here\",\n",
    "\"etc.\": \"your definitions here\",\n",
    "}\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "elCCgY64spuq"
   },
   "source": [
    "## Preview of your notes for Module 1\n",
    "\n",
    "Here's a preview of your how your notes will be displayed.  At the end of this Python notebook, we'll aggregate your notes for all modules together into a single display.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "gYYeNcdM_maE",
    "outputId": "ed4d1341-abac-415a-a784-8f1b74c35208"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 1: Rational Agents and Task Environments\n",
       "## AIMA Chapter 1.1 What is AI?\n",
       " Chapter 1.1 summary. \n",
       "Four approaches to develpoing AI:\n",
       "- Creating systems that act human\n",
       "  - Validate with Turing test\n",
       "- Create systems that think humanly\n",
       "  - Roots in cognitive science. Study the brain\n",
       "- Create systems that think rationally:\n",
       "  - Fomral logic (Chapter 7 - Logical agents)\n",
       "- Create systems that act rationally\n",
       "  - Maximize expected utility\n",
       "  - Approach taken in this course and texbook\n",
       "  - More of an \"engineering\" approach. Does it do what it is supposed to?\n",
       "  - \"Do the right thing\" = Maximize expected utility\n",
       "\n",
       "\n",
       "## AIMA Chapter 27.1 The Limits of AI\n",
       " \n",
       "**Arguments for limits of AI**:\n",
       "- human behavior too complex to model with formal logic in computer (qualification problem)\n",
       "- Can't study functioning of brain outside of body (*embodied cognititon*)\n",
       "- Qualificatoin problem: Computer can never do X\n",
       "  - Computers have been able to do a lot that have been predicted that they can't\n",
       "  - People fall in love with Teddy Bears\n",
       "- Godels' incompleteness theorem (In any formal axiomatic framework, can construct a sentence that cannot be proven, but is still true)\n",
       "  - Claims that computers need to obey, but humans do not, so AI can never be as good as human intelligence\n",
       "  - but only applies to math, not cognitiion\n",
       "  - Not really a big deal, and human brains don't really have special properties\n",
       " \n",
       "\n",
       "## AIMA Chapter 27.1 Can Machines Really Think?\n",
       " \n",
       "- Conciusness is ill defined\n",
       "- Chinese room problem by Searle: Computers just blindly following instructions, don't really understand\n",
       "  - Counter argument: Human cells, just blindly following instructions, don't really understand.\n",
       "\n",
       "## AIMA 2.1 Agents and Environments\n",
       "\n",
       "- Percept: What an agent perceives (at current time)\n",
       "- Actuators: act upon environment\n",
       "- Percept sequence: history of everything agent has perceived\n",
       "- Agent function vs agent program:\n",
       "  - Agent function maps percepts sequences to actoins\n",
       "  - Agent program is an implementation of agent function\n",
       "  -  \n",
       "\n",
       "## AIMA 2.2 Good Behavior: The Concept of Rationality\n",
       " \n",
       "In desigining rational agents, give them performance measures. Rational agents need to maximize expcted performance measure by choosing best actions given percept sqeunce. Note that agent only needs to maximize **expected** performance meaure, not actual. ]\n",
       "Don't say that an agent isn't rational due to bad luck. Can't expect ominisinece. \n",
       "\n",
       "Can say that a thermometer is an agent.\n",
       "\n",
       "\n",
       "## AIMA 2.3 The Nature of Environments\n",
       " \n",
       "Group **P**erformance measure, **E**nvironment, **A**ctuators, and **S**ensors under the acronym **PEAS**. \n",
       "\n",
       "## Properties of task environments:\n",
       "- Fully observable vs partially observable \n",
       "  - Could also have unobservable environments...\n",
       "- Single agent vs multiagent\n",
       "  - In this context, another entity can be considered to be an agent if it is trying to maximize  a performance measure that is affected by principal's agent's actions\n",
       "- Deterministic vs non-determinstic\n",
       "  - Partially observable environments or very complex ones can be effectively non-deterministic\n",
       "  - textbook uses stochastic to refer to environments with explicit probabilities, while non-determnistic is used\n",
       "  for environments where probablities not explicitly defined, but know that outcome of actions not always the same\n",
       "- Static vs dynamic\n",
       "  - Does the environment change even when agent doesn't take an action?\n",
       "- episodic vs sequential?\n",
       "  - Is performance measure evaluated after single percept followed by single action,\n",
       "  with future percepts not depending on action? (episodic)\n",
       "    - Ex: clasification problems\n",
       "  - Or does agent make series of actions, where future percepts/state of world depends on\n",
       "  action? (sequential)\n",
       "    - Ex: chess\n",
       "- Discrete vs continous\n",
       "  - Way time is handled\n",
       "  - chess is discrete, playing starcraft is effectively continous (even if everything is discrete in computer representation)\n",
       "- Known vs unknown\n",
       "  - are rules of environment codified into agent?\n",
       "\n",
       "Hardest environment is partially observable, multiaent, non-determnistic, sequential, continours, and unknown.Autonomous cars checks most of these boxes, except most things are known (such as rules of road, physics etcc..)\n",
       "Could make more difficult by trying to drive in new country where rules of road are unknown, or install on janky car... \n",
       " \n",
       "\n",
       "## AIMA 2.4 The Structure of Agents\n",
       " \n",
       "Agent program runs on a certain architeture (physical computing device, sensors and actuators, etc..)\n",
       "\n",
       "Different kind of agents:\n",
       "- table lookups\n",
       "  - percept sequences quickly become too large for this approach\n",
       "- reflex agents\n",
       "  - just choose action on current percept, ignore history\n",
       "- Model-based reflex agents\n",
       "  - Keep track of (relevant) unobserved world. Take into account in addition to current percept.\n",
       "- Goal based agents\n",
       "  - Model how actions will affect world, so can plan better\n",
       "  - Search problems are examples of goal based agents\n",
       "- Utility based agents\n",
       "  - Model performance measure with utility function\n",
       "  - try to maximize utiltiy\n",
       "  - Helps make tradeoffs and choose between different goals\n",
       "  - Try to maximize expected utiltiy\n",
       "\n",
       "Can combine different approaches. Put reflexive actions inside of more complex utility based agents when decision is clear.\n",
       "\n",
       "Want agent programs that learn, so we don't need to code everything in advance.\n",
       "\n",
       "Can have atomic represenations of world (states with no internal, such as for simple search), factored (states have internal variables or attributes such as in CSPs or logic agents),or structured (first order logic and natural language).\n",
       "\n",
       "\n",
       "## Module 1 Lecture Notes\n",
       "\n",
       "- Things that can be viewed as agents:\n",
       "  - pet hamster\n",
       "  - thermostat\n",
       "  - touchless faucet\n",
       "  - (but not bathroom faucet turned on by handle)\n",
       "\n",
       "\n",
       "## Module 1 Definitions\n",
       "* **Agent** - anything that can perceive and act in an environment\n",
       "* **Percept** - your definitions here\n",
       "* **Other concept** - your definitions here\n",
       "* **Etc.** - your definitions here\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "from IPython.display import display, Markdown, Latex\n",
    "\n",
    "module1_sections = [\n",
    "  (\"AIMA Chapter 1.1 What is AI?\", chapter1_1),\n",
    "  (\"AIMA Chapter 27.1 The Limits of AI\", chapter27_1),\n",
    "  (\"AIMA Chapter 27.1 Can Machines Really Think?\", chapter27_2),\n",
    "  (\"AIMA 2.1 Agents and Environments\", chapter2_1),\n",
    "  (\"AIMA 2.2 Good Behavior: The Concept of Rationality\", chapter2_2),\n",
    "  (\"AIMA 2.3 The Nature of Environments\", chapter2_3),\n",
    "  (\"AIMA 2.4 The Structure of Agents\", chapter2_4),\n",
    "  (\"Module 1 Lecture Notes\", module1_lecture_notes),\n",
    "]\n",
    "\n",
    "\n",
    "def length_check(sections):\n",
    "  warnings = \"\"\n",
    "  for section, summary in sections:\n",
    "    max_word_length = 500\n",
    "    max_character_length = 3000\n",
    "    if \"lecture\" in section.lower():\n",
    "      # It's OK to do longer summaries of the lectures\n",
    "      max_word_length = 2000\n",
    "      max_character_length = 12000  \n",
    "    if (len(summary) > max_character_length or len(summary.split(' ')) > max_word_length):\n",
    "      warnings += \"WARNING: Your summary of '{section}' is too long!\\n\".format(section=section)\n",
    "  return warnings\n",
    "\n",
    "def length_check_definitions(definitions):\n",
    "  warnings = \"\"\n",
    "  for concept, definition in definitions.items():\n",
    "    if(len(definition.split(' ')) > 20):\n",
    "      warnings += \"WARNING: Your definition of '{concept}' is too long!\\n\".format(concept=concept)\n",
    "  return warnings\n",
    "\n",
    "\n",
    "def format_module(module_num, title, sections, definitions, show_placeholder=False):\n",
    "  markdown = \"\"\n",
    "\n",
    "  # Check summary lengths\n",
    "  warnings = length_check(sections)\n",
    "  if warnings != \"\":\n",
    "    markdown += \"## \" + warnings\n",
    "\n",
    "  # Check definition lengths\n",
    "  warnings = length_check_definitions(definitions)\n",
    "  if warnings != \"\":\n",
    "    markdown += \"## \" + warnings\n",
    "\n",
    "  markdown += \"# Module {num}: {title}\\n\".format(num=module_num, title=title)\n",
    "\n",
    "\n",
    "  for section, summary in sections:\n",
    "    if show_placeholder and summary == \" Your summary here \":\n",
    "      summary = placeholder\n",
    "    markdown += \"## {section}\\n{summary}\\n\\n\".format(section=section, summary=summary)\n",
    "  \n",
    "  markdown += \"## Module {num} Definitions\\n\".format(num=module_num)\n",
    "  for concept, definition in definitions.items():\n",
    "    markdown += \"* **{concept}** - {definition}\\n\".format(concept=concept.capitalize(), definition=definition)\n",
    "  return markdown\n",
    "\n",
    "\n",
    "module1_markdown = format_module(1, \"Rational Agents and Task Environments\", module1_sections, module1_definitions)\n",
    "display(Markdown(module1_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "9xRbdqDox2zD"
   },
   "source": [
    "#Module 2 - Python"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "id": "DpBvu7EMx7sy"
   },
   "outputs": [],
   "source": [
    "# No readings for this module.  Instead you can summarize the lecture instead.\n",
    "\n",
    "# Lecture notes \n",
    "module2_lecture_notes = \"\"\" \n",
    "- Can have (pointers to) None objects in list\n",
    "- Can repeat a string by multiplying by an integer: `\"a\" * 3 = \"aaa\"`\n",
    "- Python is both dynamically typed and strongly typed\n",
    "  - Dynamically means that variables can be reassigned to objects of different types\n",
    "  - Strongly means that every object has type, and that properties of type are respected\n",
    "- Python uses Duck typing: don't check if object is of certain type, just assume that it can do certain things, and catch exceptions\n",
    "- lst[:] returns a copy\n",
    "- Can't add sets `{1} + {2}` gives an error\n",
    "  - but can do subtraction `{1} - {2}` gives `{1}`\n",
    "- Last part of Python index always excluded. `a = [1,2,3]; a[:-1] = [1,2]`\n",
    "- To slice by steps or backwads, add extra colon. `a[::-1] = [3,2,1]; a[::2] = [1,3]; a[-2::-1] = a[1::-1] = [2,1]`\n",
    "- slicing creates copies (of references)\n",
    "- can make generator just by adding `yield` keyword. Generally have in a loop. Then can use `for foo in generator()`\n",
    "- WHen doing list comprehension `[(x,y) for x in foo1 for y in foo2]` gives cartesian product. SO if both foo1 and foo2 have 3 elements, then result is 9 elemtns\n",
    "- To filter in list comprhension, put conditional statment at end: `[(x,y) for x in foo1 for y in foo2 if x > 1]` \n",
    "- if have `if` statement earlier, then it is ternary statment: `[(x,y) if x > 1 else x for x in foo1 for y in foo2]` \n",
    "\"\"\"\n",
    "\n",
    "# Each definition should be at most 20 words long.\n",
    "module2_definitions = {\n",
    "\"mutability\" : \"Attibutes/internal of object can change after creation. Therefore not hashable. Therefore can't assign as key to dictionaryy\",\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 529
    },
    "id": "ydOK__lwWgdp",
    "outputId": "735f1ba5-ff91-4823-fac8-b1dd74471f93"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 2: Python\n",
       "## Module 2 Lecture Notes\n",
       " \n",
       "- Can have (pointers to) None objects in list\n",
       "- Can repeat a string by multiplying by an integer: `\"a\" * 3 = \"aaa\"`\n",
       "- Python is both dynamically typed and strongly typed\n",
       "  - Dynamically means that variables can be reassigned to objects of different types\n",
       "  - Strongly means that every object has type, and that properties of type are respected\n",
       "- Python uses Duck typing: don't check if object is of certain type, just assume that it can do certain things, and catch exceptions\n",
       "- lst[:] returns a copy\n",
       "- Can't add sets `{1} + {2}` gives an error\n",
       "  - but can do subtraction `{1} - {2}` gives `{1}`\n",
       "- Last part of Python index always excluded. `a = [1,2,3]; a[:-1] = [1,2]`\n",
       "- To slice by steps or backwads, add extra colon. `a[::-1] = [3,2,1]; a[::2] = [1,3]; a[-2::-1] = a[1::-1] = [2,1]`\n",
       "- slicing creates copies (of references)\n",
       "- can make generator just by adding `yield` keyword. Generally have in a loop. Then can use `for foo in generator()`\n",
       "- WHen doing list comprehension `[(x,y) for x in foo1 for y in foo2]` gives cartesian product. SO if both foo1 and foo2 have 3 elements, then result is 9 elemtns\n",
       "- To filter in list comprhension, put conditional statment at end: `[(x,y) for x in foo1 for y in foo2 if x > 1]` \n",
       "- if have `if` statement earlier, then it is ternary statment: `[(x,y) if x > 1 else x for x in foo1 for y in foo2]` \n",
       "\n",
       "\n",
       "## Module 2 Definitions\n",
       "* **Mutability** - Attibutes/internal of object can change after creation. Therefore not hashable. Therefore can't assign as key to dictionaryy\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "\n",
    "module2_sections = [\n",
    "  (\"Module 2 Lecture Notes\", module2_lecture_notes),\n",
    "]\n",
    "\n",
    "module2_markdown = format_module(2, \"Python\", module2_sections, module2_definitions)\n",
    "display(Markdown(module2_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "46MQLR-Gx8dZ"
   },
   "source": [
    "#Module 3 - Search Problems"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "id": "BN0b1eVYx-nd"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA 4th Edition, AIMA Chapter 3 “Problem Solving by Search” (3.1-3.4)\n",
    "chapter3_1 = \"\"\" \n",
    "A search problem takes place in an environment that is is assumed to be fully observable, deterministic and known.\n",
    "\n",
    "Informally, we are trying to get from one location to another through a series of \\\n",
    "actions with a minimum cost.\n",
    "\n",
    "Formally, a serach problem is deinfed as:\n",
    "- a space state that consists of possible states\n",
    "  - state correspond to real world, such at what city we are in or layout of a board\n",
    "- a starting space that the agents starts in\n",
    "- a *GOAL(s) function that indicates if state s is a goal state\n",
    "- a set of actions that are applicable in each state\n",
    "-  a transition model that tells use what state we end up in based on the state we are currenly in and the action we take\n",
    "- an action cost funtion that gives us the cost based on taking action *a* to get to state *s_j* from state $$s_i$$\n",
    "\n",
    "Trying to find the sequence of actions from initital state to goal state with minimum cost\n",
    "\n",
    "Can represent states as nodes in graph, with edges between nodes when we can transition between the two nodes\n",
    "\n",
    "Level of abstraction is important. If planning shortest trip, abstracting away details on driving and such. Just assume it works out.\n",
    "\n",
    "\"\"\"\n",
    "chapter3_2 = \"\"\" \n",
    "- can have an infinite state spaces\n",
    "  - Knuth's conjecture that we can get to any integer starting from 4 just by applying square root, factorial and floor operations\n",
    "- touring problems: travelling salemen. \n",
    "- VLSI layout: Channel routing to find shortest path for wires throguh gaps in cells.\n",
    " \"\"\"\n",
    "chapter3_3 = \"\"\"\n",
    "- Search algorithm takes as input a search problem and either returns path from start to goal or indicates that no solution exists\n",
    "- Algorithms create search tree, consisting of nodes with attributes of state and path cost\n",
    "  - same state can appear multiple times in tree in different nodes\n",
    "  - Edges correspond to actions\n",
    "- Important concepts:\n",
    "  - $$Expand(n)$$: take a node and generates all succesor nodes (states we can reach from input node/state, based on single action)\n",
    "  - **frontier**: set of nodes which of have been generated by *Expand()*, but not yet expanded themselves\n",
    "  - **reached**: a state has been reached when any node has been generated for it. For best first search, a data struture that maps from state to a node. \\\n",
    "    - For breadth first search, returns True or False when given a state\n",
    "\n",
    "**Best First Search**\n",
    "General algorithm that models frontier as a priority queue with evaluation function $$f(n)$$\n",
    "- start with root node/initial state in priority queue\n",
    "- while priority queue is not empty, pop a node (get node with lowest evaluation function)\n",
    "- If the node is goal, return it (success!)\n",
    "  - can get path from node, since node contains pointer to parent\n",
    "- Expand node to get children\n",
    "- for each child, add it to frontier if either child.state not in reached, or if reached[child.state].path_cost > child.path_cost\n",
    "  - if adding to frontier, update reached data structure so that child.state points to this node\n",
    "\n",
    "**Redundant Paths**\n",
    "Can be many different ways of reaching same state. Can cause slowdowns by needlesly checking paths that we know aren't efficient.\\\n",
    "Can handle by keeping track of reached states like in Best First Search. Call algorithms that check for redundant paths *graph search* algorithms. They use more memory because they keep track of reached nodes. \\\n",
    "Don't have to keep track of redundant paths if we know that there aren't many. Algorithms that don't keep track of redundant paths are called *tree search* algorithms. Ex: Depth first search. Saves memory.\\\n",
    "Can also check for cycles (using pointers stored in nodes) instead of redundant paths. Doesn't uses extra memory but requires extra computation. Can just check for cycles of certain length.\n",
    "\n",
    "\n",
    "\n",
    "In computer science, use number of nodes |V| and edges |E| to evaluate complexity. But often don't know this in AI. Instead,\\\n",
    " consider depth *d* at which optimal solution lies, *m* maximum number depth of tree and *b* the branching factor or number of successor nodes considered at each point in search tree.\\\n",
    "\n",
    "\"\"\"\n",
    "chapter3_4 = \"\"\" \n",
    "- breadth-first search\n",
    "  - used when all actions have same cost\n",
    "  - expands nodes in order they are generated (first in first out FIFO)\n",
    "  - Could use best first search, but can make more efficient by:\n",
    "    - using FIFO queue instead of priotiy\n",
    "    - *Early goal test*: check if node is solution as soon as generated, rather than when popped off queue\n",
    "      - Since nodes generated later will always have higher cost\n",
    "  - have *reached* data stucture just contain True/False, rather than pointers to nodes.\n",
    "  - Bread first search is:\n",
    "    - complete\n",
    "    - optimal if all actions cost one\n",
    "    - has space and time complexity of $O(b^d)$\n",
    "      - time complexity is fine, space complexity is high: run out of memory\n",
    "- uniform cost search/Dijkstra's algorithm\n",
    " - for when actions have different costs\n",
    " - use best first search, with evaluation funciton being path cost\n",
    " - is complete, optimal. Space and time complexity is $O(b^{1+C^{*}/\\epsilon})$ where C* is cost of optimal solution and e is lower bound on cost of each action\n",
    "   - can be much larger than b^d, because uniform cost explores many branches with low cost before explroing higher cost branches with potentially better actions\n",
    " - Dijkstra algoithm is uniform search without a goal\n",
    "- depth first search\n",
    "  - is tree search, don't track if reached\n",
    "  - not complete if infinite depth/cycles. Not optimal\n",
    "  - more memory efficient: O(bm): *m* is maximum depth of tree. Can be even less with backtracking searching: generate only one succesor at a time\n",
    "  - time: O(b^m): if **m** is infinte, that is bad\n",
    "- iterative deepening\n",
    "  - over come limitations of DFS by restricting depth so don't run infinitely. Gradually increase depth\n",
    "  - complete and optimal\n",
    "  - time complexity is O(b^d) when there is solution, O(b^m) when no solution. *m* is max depth...\n",
    "- bidirectional\n",
    "  - start from goal and intitial state\n",
    "  - complexity: O(b^d/2)\n",
    "\"\"\"\n",
    "\n",
    "\n",
    "# Lecture notes \n",
    "module3_lecture_notes = \"\"\" \n",
    "\n",
    "** Measuring performance**\n",
    "Evaluate search algorithms on:\n",
    "- Completeness: Is the algorithm guranteed to return a solution if one exists?\n",
    "  - Algorithm needs to be *systematic* to be complete = able to reach any state. Since solution could be any state. If space is infinite, algorithm can't ever be certain that solution doesn't exist \n",
    "- Cost optimilaty: Is returned solution lowest cost?\n",
    "- Time complexity: Amount of time or computation needed to find solution\n",
    "- Space complexity: Amount of space (physical or abstact) needed \"\"\"\n",
    "\n",
    "# Definitions of concepts from Module 3.\n",
    "# You can define any bolded term in the textbook, \n",
    "# but you most use your own words for the definitions.\n",
    "# Each definition should be at most 20 words long.\n",
    "module3_definitions = {\n",
    "\"problem-solving agent\" : \"an agent that can formulate a plan via search\",\n",
    "\"open loop system\" : \"agent ignores percepts - can do this since world is deterministic, known and single player\",    \n",
    "}\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "lvtN3p7ET3Tx",
    "outputId": "4421c49d-3457-4ae9-df17-9e220d617bb0"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 3: Search Problems\n",
       "## AIMA Chapter 3.1 Problem-Solving Agents\n",
       " \n",
       "A search problem takes place in an environment that is is assumed to be fully observable, deterministic and known.\n",
       "\n",
       "Informally, we are trying to get from one location to another through a series of actions with a minimum cost.\n",
       "\n",
       "Formally, a serach problem is deinfed as:\n",
       "- a space state that consists of possible states\n",
       "  - state correspond to real world, such at what city we are in or layout of a board\n",
       "- a starting space that the agents starts in\n",
       "- a *GOAL(s) function that indicates if state s is a goal state\n",
       "- a set of actions that are applicable in each state\n",
       "-  a transition model that tells use what state we end up in based on the state we are currenly in and the action we take\n",
       "- an action cost funtion that gives us the cost based on taking action *a* to get to state *s_j* from state $$s_i$$\n",
       "\n",
       "Trying to find the sequence of actions from initital state to goal state with minimum cost\n",
       "\n",
       "Can represent states as nodes in graph, with edges between nodes when we can transition between the two nodes\n",
       "\n",
       "Level of abstraction is important. If planning shortest trip, abstracting away details on driving and such. Just assume it works out.\n",
       "\n",
       "\n",
       "\n",
       "## AIMA Chapter 3.2 Example Problems\n",
       " \n",
       "- can have an infinite state spaces\n",
       "  - Knuth's conjecture that we can get to any integer starting from 4 just by applying square root, factorial and floor operations\n",
       "- touring problems: travelling salemen. \n",
       "- VLSI layout: Channel routing to find shortest path for wires throguh gaps in cells.\n",
       " \n",
       "\n",
       "## AIMA Chapter 3.3 Search Algorithms\n",
       "\n",
       "- Search algorithm takes as input a search problem and either returns path from start to goal or indicates that no solution exists\n",
       "- Algorithms create search tree, consisting of nodes with attributes of state and path cost\n",
       "  - same state can appear multiple times in tree in different nodes\n",
       "  - Edges correspond to actions\n",
       "- Important concepts:\n",
       "  - $$Expand(n)$$: take a node and generates all succesor nodes (states we can reach from input node/state, based on single action)\n",
       "  - **frontier**: set of nodes which of have been generated by *Expand()*, but not yet expanded themselves\n",
       "  - **reached**: a state has been reached when any node has been generated for it. For best first search, a data struture that maps from state to a node.     - For breadth first search, returns True or False when given a state\n",
       "\n",
       "**Best First Search**\n",
       "General algorithm that models frontier as a priority queue with evaluation function $$f(n)$$\n",
       "- start with root node/initial state in priority queue\n",
       "- while priority queue is not empty, pop a node (get node with lowest evaluation function)\n",
       "- If the node is goal, return it (success!)\n",
       "  - can get path from node, since node contains pointer to parent\n",
       "- Expand node to get children\n",
       "- for each child, add it to frontier if either child.state not in reached, or if reached[child.state].path_cost > child.path_cost\n",
       "  - if adding to frontier, update reached data structure so that child.state points to this node\n",
       "\n",
       "**Redundant Paths**\n",
       "Can be many different ways of reaching same state. Can cause slowdowns by needlesly checking paths that we know aren't efficient.Can handle by keeping track of reached states like in Best First Search. Call algorithms that check for redundant paths *graph search* algorithms. They use more memory because they keep track of reached nodes. Don't have to keep track of redundant paths if we know that there aren't many. Algorithms that don't keep track of redundant paths are called *tree search* algorithms. Ex: Depth first search. Saves memory.Can also check for cycles (using pointers stored in nodes) instead of redundant paths. Doesn't uses extra memory but requires extra computation. Can just check for cycles of certain length.\n",
       "\n",
       "\n",
       "\n",
       "In computer science, use number of nodes |V| and edges |E| to evaluate complexity. But often don't know this in AI. Instead, consider depth *d* at which optimal solution lies, *m* maximum number depth of tree and *b* the branching factor or number of successor nodes considered at each point in search tree.\n",
       "\n",
       "\n",
       "## AIMA Chapter 3.4 Uninformed Search Strategies\n",
       " \n",
       "- breadth-first search\n",
       "  - used when all actions have same cost\n",
       "  - expands nodes in order they are generated (first in first out FIFO)\n",
       "  - Could use best first search, but can make more efficient by:\n",
       "    - using FIFO queue instead of priotiy\n",
       "    - *Early goal test*: check if node is solution as soon as generated, rather than when popped off queue\n",
       "      - Since nodes generated later will always have higher cost\n",
       "  - have *reached* data stucture just contain True/False, rather than pointers to nodes.\n",
       "  - Bread first search is:\n",
       "    - complete\n",
       "    - optimal if all actions cost one\n",
       "    - has space and time complexity of $O(b^d)$\n",
       "      - time complexity is fine, space complexity is high: run out of memory\n",
       "- uniform cost search/Dijkstra's algorithm\n",
       " - for when actions have different costs\n",
       " - use best first search, with evaluation funciton being path cost\n",
       " - is complete, optimal. Space and time complexity is $O(b^{1+C^{*}/\\epsilon})$ where C* is cost of optimal solution and e is lower bound on cost of each action\n",
       "   - can be much larger than b^d, because uniform cost explores many branches with low cost before explroing higher cost branches with potentially better actions\n",
       " - Dijkstra algoithm is uniform search without a goal\n",
       "- depth first search\n",
       "  - is tree search, don't track if reached\n",
       "  - not complete if infinite depth/cycles. Not optimal\n",
       "  - more memory efficient: O(bm): *m* is maximum depth of tree. Can be even less with backtracking searching: generate only one succesor at a time\n",
       "  - time: O(b^m): if **m** is infinte, that is bad\n",
       "- iterative deepening\n",
       "  - over come limitations of DFS by restricting depth so don't run infinitely. Gradually increase depth\n",
       "  - complete and optimal\n",
       "  - time complexity is O(b^d) when there is solution, O(b^m) when no solution. *m* is max depth...\n",
       "- bidirectional\n",
       "  - start from goal and intitial state\n",
       "  - complexity: O(b^d/2)\n",
       "\n",
       "\n",
       "## Module 3 Lecture Notes\n",
       " \n",
       "\n",
       "** Measuring performance**\n",
       "Evaluate search algorithms on:\n",
       "- Completeness: Is the algorithm guranteed to return a solution if one exists?\n",
       "  - Algorithm needs to be *systematic* to be complete = able to reach any state. Since solution could be any state. If space is infinite, algorithm can't ever be certain that solution doesn't exist \n",
       "- Cost optimilaty: Is returned solution lowest cost?\n",
       "- Time complexity: Amount of time or computation needed to find solution\n",
       "- Space complexity: Amount of space (physical or abstact) needed \n",
       "\n",
       "## Module 3 Definitions\n",
       "* **Problem-solving agent** - an agent that can formulate a plan via search\n",
       "* **Open loop system** - agent ignores percepts - can do this since world is deterministic, known and single player\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "module3_sections = [\n",
    "  (\"AIMA Chapter 3.1 Problem-Solving Agents\", chapter3_1),\n",
    "  (\"AIMA Chapter 3.2 Example Problems\", chapter3_2),\n",
    "  (\"AIMA Chapter 3.3 Search Algorithms\", chapter3_3),\n",
    "  (\"AIMA Chapter 3.4 Uninformed Search Strategies\", chapter3_4),\n",
    "  (\"Module 3 Lecture Notes\", module3_lecture_notes),\n",
    "]\n",
    "\n",
    "module3_markdown = format_module(3, \"Search Problems\", module3_sections, module3_definitions)\n",
    "display(Markdown(module3_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "WHREsHSSyA-h"
   },
   "source": [
    "#Module 4 - Informed Search"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "id": "tuFC8w7CyCns"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA Chapter 3 “Problem Solving by Search” (3.5-3.6)\n",
    "chapter3_5 = \"\"\"\n",
    " - A\\* is cost optimal with consistent $h(n)$\n",
    "   - \"prunes\" away nodes/paths \n",
    " - satisficing solutions = \"good enough\"\n",
    "   - if use an inadmisible heuristic (pesimistic), then reduce number of nodes expanded at risk of missing optimal solution\n",
    "   - Variants of A\\* that find solutions less than C or within $\\epsilon$ of optimal solution\n",
    "   - Weighted A\\* search puts more weight on heuristic, equivalent to a pessimistic heuristic\n",
    "     - Greedy search puts all the weight on heuristic\n",
    "  - memory issues\n",
    "    - Main issue with A\\* is use of memory. Usually *reached* much larger than *frontier*\n",
    "    - Bidirectional A\\*\n",
    "    - RBFS\n",
    "    - Beam search\n",
    "      - limit size of frontier\n",
    "    - Iterative deepening A\\* (IDA\\*)\n",
    "    - SMA\\*:\n",
    "      - Adds nodes to *reached* until it fills, then \n",
    "      - Keeps track of f-value of forgotten node in parent so knows if worth expanding parent later.\n",
    "      - Deleting and adding can lead to thrashing.\n",
    "\"\"\"\n",
    "chapter3_6 = \"\"\"\n",
    "- if A\\* find solution at depth $d$ and generates $N$ nodes, then its *effective branching factor* $b*$ is such that $N + 1 = 1 + b* + (b*)^2 + ... + (b*) ^d$\n",
    "  - is the branching factor that a uniform tree of depth $d$ would need to have to generate N + 1 nodes\n",
    "  - charactizes the quality of a heuristic: lower is better\n",
    "  - *effective depth* is another measure\n",
    "- A heuristic $h^1$ dominates another heuristic $h^2$ if for any n, $h^1(b) \\geq h^2(n)$\n",
    "  - dominating heuristic will have lower *effective branching factor*  and be more efficient\n",
    "    - can see this since dominating heuristic will have less \"surely expanded nodes\" (nodes with $f(n) \\leq C*$ where C* is cost of optimal path)\n",
    "- Can generate heuristics to a problem by relaxing constraints\n",
    "  - Ex: for 8-puzzle, allowing squares to be moved through other squares produces heuristic of manhattan distance\n",
    "  - Works because any solution to actual problem is also solution to relaxed problem, so any solution to relaxed problem will have cost no more than cost to actual problem\n",
    "  - can take max of a collection of heuristics\n",
    "- *pattern databases* stores exact solution costs to subproblems (eg. for 8-puzzle, getting 4/8 in right place)\n",
    "  - is admissible heuristic\n",
    "  - can take the max of several problems\n",
    "  - if subproblems are disjoint, then can add costs\n",
    "  - can be very efficient (but require memory/storage space)\n",
    "- GPS and google Maps calculate routes quickly by using *landmarks*\n",
    "  - Store costs of going from any point to land mark\n",
    "  - THen heuristic is cost of going to closest landmark, then to goal\n",
    "    - Can be inadmissible (overstimate cost)\n",
    "- learning\n",
    "  - can use machine learning to estimate heuristic from current state based on features\n",
    "  - can also treat search like a search problem? metalevel learning?\n",
    " \"\"\"\n",
    "\n",
    "\n",
    "# Lecture notes \n",
    "module4_lecture_notes = \"\"\"\n",
    "- heuristic function $h(n)$ estimates shortest path distance between node *n* and a goal state\n",
    "- *Greedy search* is an implementation of *Best First Search* where the evaluation function $f(n) = h(n)$\n",
    "  - Complete on finite states, not infinte  (can get stuck in cycles)\n",
    "  - With good $h(n)$, complexity of $O(bm)$\n",
    "- * A\\* search* is Best First Search implementation thartuses an evaluation function of $f(n) = g(n) + h(n)$\n",
    "  - * A\\* is complete\n",
    "  - If $h(n)$ is admissible (i.e. optimistic so is always less than or equal to actual cost to reach goal), then A\\* is optimal\n",
    "     - Sketch of proof:\n",
    "      - If A\\* returns non-optimal solution with cost $C$, then some node $n$ that is on optimal path must be on frontier and unexpanded. Thus $f(n) > C$.\n",
    "      - $f(n) \\leq C* \\leq C$ since $h(n)$ is admissible. But this is contradiction\n",
    "  - consistency\n",
    "    - *Consistency* is stronger than admissibility: $h(n) \\leq c(n,a,n1) + h(n')$\n",
    "      - Basically requirement for heuristic to obey triangle inequality\n",
    "      - if $h(n)$ is consistent, then can be like BFS - ignore later nodes for same state since pathcost for first node will be optimal\n",
    "        - if consistent, can use tree search (don't need to keep track of reached)\n",
    "        - quiz is wrong, says is False that the graph search of A\\* is optimal as long as the heuristic is admissible. This is in fact true.\n",
    "- search contours\n",
    " - A\\* search spreads out in contours that \"stretch\" towards goal, compared to uniform-cost search, where contours are circular\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "# Definitions\n",
    "module4_definitions = {\n",
    "\"reference counts\" : \"track number of times a state has been reached and remove from reached datastructure when no more ways to reach\",\n",
    "\"beam search\": \"limit size of frontier by keeping *k* nodes with best *f*scores\",\n",
    "\"IDA\\*\": \"Each round, increase 'depth' to smallest f-score that exceeded last iteration's depth. Works well for integer valued f-scores\",\n",
    "\"Recursive best-first search (RBFS)\": \"No *reached* datastructure. Each node remembers f-score of best alternative path. Backsup when f-value of current path exceeds best alternaitve.\",\n",
    "\"Bidirectional heurisitc search\": \"Full page in text book.\"\n",
    "}\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "vqtEs0gHs9sO",
    "outputId": "38f786cf-1852-4f59-dd84-ca5b6993f80a"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 4: Informed Search\n",
       "## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n",
       "\n",
       " - A\\* is cost optimal with consistent $h(n)$\n",
       "   - \"prunes\" away nodes/paths \n",
       " - satisficing solutions = \"good enough\"\n",
       "   - if use an inadmisible heuristic (pesimistic), then reduce number of nodes expanded at risk of missing optimal solution\n",
       "   - Variants of A\\* that find solutions less than C or within $\\epsilon$ of optimal solution\n",
       "   - Weighted A\\* search puts more weight on heuristic, equivalent to a pessimistic heuristic\n",
       "     - Greedy search puts all the weight on heuristic\n",
       "  - memory issues\n",
       "    - Main issue with A\\* is use of memory. Usually *reached* much larger than *frontier*\n",
       "    - Bidirectional A\\*\n",
       "    - RBFS\n",
       "    - Beam search\n",
       "      - limit size of frontier\n",
       "    - Iterative deepening A\\* (IDA\\*)\n",
       "    - SMA\\*:\n",
       "      - Adds nodes to *reached* until it fills, then \n",
       "      - Keeps track of f-value of forgotten node in parent so knows if worth expanding parent later.\n",
       "      - Deleting and adding can lead to thrashing.\n",
       "\n",
       "\n",
       "## AIMA Chapter 3.6 Heuristic Functions\n",
       "\n",
       "- if A\\* find solution at depth $d$ and generates $N$ nodes, then its *effective branching factor* $b*$ is such that $N + 1 = 1 + b* + (b*)^2 + ... + (b*) ^d$\n",
       "  - is the branching factor that a uniform tree of depth $d$ would need to have to generate N + 1 nodes\n",
       "  - charactizes the quality of a heuristic: lower is better\n",
       "  - *effective depth* is another measure\n",
       "- A heuristic $h^1$ dominates another heuristic $h^2$ if for any n, $h^1(b) \\geq h^2(n)$\n",
       "  - dominating heuristic will have lower *effective branching factor*  and be more efficient\n",
       "    - can see this since dominating heuristic will have less \"surely expanded nodes\" (nodes with $f(n) \\leq C*$ where C* is cost of optimal path)\n",
       "- Can generate heuristics to a problem by relaxing constraints\n",
       "  - Ex: for 8-puzzle, allowing squares to be moved through other squares produces heuristic of manhattan distance\n",
       "  - Works because any solution to actual problem is also solution to relaxed problem, so any solution to relaxed problem will have cost no more than cost to actual problem\n",
       "  - can take max of a collection of heuristics\n",
       "- *pattern databases* stores exact solution costs to subproblems (eg. for 8-puzzle, getting 4/8 in right place)\n",
       "  - is admissible heuristic\n",
       "  - can take the max of several problems\n",
       "  - if subproblems are disjoint, then can add costs\n",
       "  - can be very efficient (but require memory/storage space)\n",
       "- GPS and google Maps calculate routes quickly by using *landmarks*\n",
       "  - Store costs of going from any point to land mark\n",
       "  - THen heuristic is cost of going to closest landmark, then to goal\n",
       "    - Can be inadmissible (overstimate cost)\n",
       "- learning\n",
       "  - can use machine learning to estimate heuristic from current state based on features\n",
       "  - can also treat search like a search problem? metalevel learning?\n",
       " \n",
       "\n",
       "## Module 4 Lecture Notes\n",
       "\n",
       "- heuristic function $h(n)$ estimates shortest path distance between node *n* and a goal state\n",
       "- *Greedy search* is an implementation of *Best First Search* where the evaluation function $f(n) = h(n)$\n",
       "  - Complete on finite states, not infinte  (can get stuck in cycles)\n",
       "  - With good $h(n)$, complexity of $O(bm)$\n",
       "- * A\\* search* is Best First Search implementation thartuses an evaluation function of $f(n) = g(n) + h(n)$\n",
       "  - * A\\* is complete\n",
       "  - If $h(n)$ is admissible (i.e. optimistic so is always less than or equal to actual cost to reach goal), then A\\* is optimal\n",
       "     - Sketch of proof:\n",
       "      - If A\\* returns non-optimal solution with cost $C$, then some node $n$ that is on optimal path must be on frontier and unexpanded. Thus $f(n) > C$.\n",
       "      - $f(n) \\leq C* \\leq C$ since $h(n)$ is admissible. But this is contradiction\n",
       "  - consistency\n",
       "    - *Consistency* is stronger than admissibility: $h(n) \\leq c(n,a,n1) + h(n')$\n",
       "      - Basically requirement for heuristic to obey triangle inequality\n",
       "      - if $h(n)$ is consistent, then can be like BFS - ignore later nodes for same state since pathcost for first node will be optimal\n",
       "        - if consistent, can use tree search (don't need to keep track of reached)\n",
       "        - quiz is wrong, says is False that the graph search of A\\* is optimal as long as the heuristic is admissible. This is in fact true.\n",
       "- search contours\n",
       " - A\\* search spreads out in contours that \"stretch\" towards goal, compared to uniform-cost search, where contours are circular\n",
       "\n",
       "\n",
       "\n",
       "## Module 4 Definitions\n",
       "* **Reference counts** - track number of times a state has been reached and remove from reached datastructure when no more ways to reach\n",
       "* **Beam search** - limit size of frontier by keeping *k* nodes with best *f*scores\n",
       "* **Ida\\*** - Each round, increase 'depth' to smallest f-score that exceeded last iteration's depth. Works well for integer valued f-scores\n",
       "* **Recursive best-first search (rbfs)** - No *reached* datastructure. Each node remembers f-score of best alternative path. Backsup when f-value of current path exceeds best alternaitve.\n",
       "* **Bidirectional heurisitc search** - Full page in text book.\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "module4_sections = [\n",
    "  (\"AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\", chapter3_5),\n",
    "  (\"AIMA Chapter 3.6 Heuristic Functions\", chapter3_6),\n",
    "  (\"Module 4 Lecture Notes\", module4_lecture_notes),\n",
    "]\n",
    "\n",
    "module4_markdown = format_module(4, \"Informed Search\", \n",
    "                         module4_sections, \n",
    "                         module4_definitions)\n",
    "display(Markdown(module4_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "F3FPMzG9yUls"
   },
   "source": [
    "#Module 5 - Adversarial Search and Games"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "id": "iEIOpL7vyWcc"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA chapter 5 \"Adversarial Search\"”\" (5.1-5.3, and 5.5).\n",
    "chapter5_1 = \"\"\" ==\n",
    "- A game has:\n",
    "  - Two players: MAX and MIN\n",
    "    - Alternate turns\n",
    "    - MAX goes first: calcuulations done from perspective of Max\n",
    "  - An initial state, $$S_0$$\n",
    "  - terminal states\n",
    "  - A utility function that returns utility for finishing in a certain state\n",
    "- \n",
    "\"\"\"\n",
    "chapter5_2 = \"\"\"\n",
    "- *minimax search*\n",
    "  - recurisve - max picks from results of minimax from MINS perspecitve with highest ulitiy. MIN picks from results of minimax from MAX's perpective with lowest utiltiy. If leaf, then just reutnr uitliy.\n",
    "- if muitl;p[layer, then replace single uiltiy, with vector at each node\n",
    "- alpha bata rpunig: alpha is Max best utlity in this branch so far. Starts off at negative infinty at root. If min finds better result than alpha (lower), then know that max will nvber go down this branch, so stop serarhcing this brnabn\n",
    "  - update alpha wwith best value. First time get reuslt from branch updater, Then if find betterm update gain. Provide al;phah to mininmax form MIN's perepctive so MIN knoiw to sto searhc\n",
    "  - beta is iquiovalnt for MIN. Start off at iniftity. If find lower (better) update.\n",
    "- can try move ordering to improve alpgha beta- : stop searching faster\n",
    "\n",
    "\"\"\"\n",
    "chapter5_3 = \"\"\"\n",
    "- sually cn't search too deep, so have heistic ebaultion funciton that can be evaulted at any baord state. Shoudl appocate ulity funciton\n",
    "- can stop searching early. Searhc to certia depth. (cutooff)\n",
    "- foerard pruning is method of narrpwing moves consider oto look at best. Fawster, but risk of not being optmal Beam search keep top n.\n",
    "- Can uise lookeup for board states where bst m ove know. Start omces and end mocves in chess.\n",
    " \"\"\"\n",
    "chapter5_5 = \"\"\" \n",
    "- in socahistc games, have chance nodes. Priblairyes for whioch acitons will be takne. Rahter than reutnrin min or max, retuned average/expectd values of eultiy..\n",
    "\n",
    " \"\"\"\n",
    "\n",
    "# Russell and Norvig, AIMA Chapter 16 “Making Simple Decisions” (16.1-16.3)\n",
    "chapter16_1 = \"\"\" Your summary here \"\"\"\n",
    "chapter16_2 = \"\"\"\n",
    "6 constrinats on prferences:\n",
    "- orceability (can always choose between 2 loteries\n",
    "- trnaisviity\n",
    "- subitiylaiblity (weight loteries so can be indeffernet))\n",
    "- montocity: if prfer otciumoe A o B, then must prefer lottery that gives higher prob to outcome A\n",
    "- Domcpaislity: can reduce compound lotereis into simpler ones using laws of problality\n",
    "\n",
    "- based on raitonal prfernces, can always have a wel bahbed utiltyi funtion\n",
    "  - well baheved, because utiliy of lotters is sum of problaity o foutocme times utiltiy of outome\n",
    " \"\"\"\n",
    "chapter16_3 = \"\"\" \n",
    "- utilfuncitons can be normalier between 1 and 0 \n",
    "- standard lotteirs: best and worse otucomes - probialtiy are asjuted until indernt to another ocuome\n",
    "- montic prefernce for money\n",
    "  - dopnes'y mean that it is linear\n",
    "- people risk adverse\n",
    "- insurnce premium \n",
    "- even if esimtates are ubniaes, always have diapalintment, since chosing loteir with highest epxectd utiltiy. Erros means lays going to have lower.\n",
    "  -optimaixzer curse.\n",
    "  - betterto choose lower vialbil;y, even if expected otuomce is lwoer...\n",
    "- achoring effcet\n",
    "- frmaing effct...\n",
    "- poeple don't liek abiguity.\n",
    " \"\"\"\n",
    "\n",
    "# Lecture notes \n",
    "module5_lecture_notes = \"\"\"\n",
    "- minimax: Don't play hope chess\n",
    "\"\"\"\n",
    "\n",
    "# Definitions\n",
    "module5_definitions = {\n",
    "\"ply\" : \"one move per player - layerlevel in search tree\",    \n",
    "}\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "KUc_LgzDvWf-",
    "outputId": "d1c1e5e1-71eb-475b-9860-666ff7032b2f"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 5: Adversarial Search and Games\n",
       "## AIMA Chapter 5.1 Game Theory\n",
       " ==\n",
       "- A game has:\n",
       "  - Two players: MAX and MIN\n",
       "    - Alternate turns\n",
       "    - MAX goes first: calcuulations done from perspective of Max\n",
       "  - An initial state, $$S_0$$\n",
       "  - terminal states\n",
       "  - A utility function that returns utility for finishing in a certain state\n",
       "- \n",
       "\n",
       "\n",
       "## AIMA Chapter 5.2 Optimal Decisions in Games\n",
       "\n",
       "- *minimax search*\n",
       "  - recurisve - max picks from results of minimax from MINS perspecitve with highest ulitiy. MIN picks from results of minimax from MAX's perpective with lowest utiltiy. If leaf, then just reutnr uitliy.\n",
       "- if muitl;p[layer, then replace single uiltiy, with vector at each node\n",
       "- alpha bata rpunig: alpha is Max best utlity in this branch so far. Starts off at negative infinty at root. If min finds better result than alpha (lower), then know that max will nvber go down this branch, so stop serarhcing this brnabn\n",
       "  - update alpha wwith best value. First time get reuslt from branch updater, Then if find betterm update gain. Provide al;phah to mininmax form MIN's perepctive so MIN knoiw to sto searhc\n",
       "  - beta is iquiovalnt for MIN. Start off at iniftity. If find lower (better) update.\n",
       "- can try move ordering to improve alpgha beta- : stop searching faster\n",
       "\n",
       "\n",
       "\n",
       "## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n",
       "\n",
       "- sually cn't search too deep, so have heistic ebaultion funciton that can be evaulted at any baord state. Shoudl appocate ulity funciton\n",
       "- can stop searching early. Searhc to certia depth. (cutooff)\n",
       "- foerard pruning is method of narrpwing moves consider oto look at best. Fawster, but risk of not being optmal Beam search keep top n.\n",
       "- Can uise lookeup for board states where bst m ove know. Start omces and end mocves in chess.\n",
       " \n",
       "\n",
       "## AIMA Chapter 5.5 Stochastic Games\n",
       " \n",
       "- in socahistc games, have chance nodes. Priblairyes for whioch acitons will be takne. Rahter than reutnrin min or max, retuned average/expectd values of eultiy..\n",
       "\n",
       " \n",
       "\n",
       "## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 16.2 The Basis of Utility Theory\n",
       "\n",
       "6 constrinats on prferences:\n",
       "- orceability (can always choose between 2 loteries\n",
       "- trnaisviity\n",
       "- subitiylaiblity (weight loteries so can be indeffernet))\n",
       "- montocity: if prfer otciumoe A o B, then must prefer lottery that gives higher prob to outcome A\n",
       "- Domcpaislity: can reduce compound lotereis into simpler ones using laws of problality\n",
       "\n",
       "- based on raitonal prfernces, can always have a wel bahbed utiltyi funtion\n",
       "  - well baheved, because utiliy of lotters is sum of problaity o foutocme times utiltiy of outome\n",
       " \n",
       "\n",
       "## AIMA Chapter 16.3 Utility Functions\n",
       " \n",
       "- utilfuncitons can be normalier between 1 and 0 \n",
       "- standard lotteirs: best and worse otucomes - probialtiy are asjuted until indernt to another ocuome\n",
       "- montic prefernce for money\n",
       "  - dopnes'y mean that it is linear\n",
       "- people risk adverse\n",
       "- insurnce premium \n",
       "- even if esimtates are ubniaes, always have diapalintment, since chosing loteir with highest epxectd utiltiy. Erros means lays going to have lower.\n",
       "  -optimaixzer curse.\n",
       "  - betterto choose lower vialbil;y, even if expected otuomce is lwoer...\n",
       "- achoring effcet\n",
       "- frmaing effct...\n",
       "- poeple don't liek abiguity.\n",
       " \n",
       "\n",
       "## Module 5 Lecture Notes\n",
       "\n",
       "- minimax: Don't play hope chess\n",
       "\n",
       "\n",
       "## Module 5 Definitions\n",
       "* **Ply** - one move per player - layerlevel in search tree\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "module5_sections = [\n",
    "  (\"AIMA Chapter 5.1 Game Theory\", chapter5_1),\n",
    "  (\"AIMA Chapter 5.2 Optimal Decisions in Games\", chapter5_2),\n",
    "  (\"AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\", chapter5_3),\n",
    "  (\"AIMA Chapter 5.5 Stochastic Games\", chapter5_5),\n",
    "  (\"AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\", chapter16_1),\n",
    "  (\"AIMA Chapter 16.2 The Basis of Utility Theory\", chapter16_2),\n",
    "  (\"AIMA Chapter 16.3 Utility Functions\", chapter16_3),\n",
    "  (\"Module 5 Lecture Notes\", module5_lecture_notes),\n",
    "]\n",
    "\n",
    "module5_markdown = format_module(5, \"Adversarial Search and Games\", \n",
    "                         module5_sections, \n",
    "                         module5_definitions)\n",
    "display(Markdown(module5_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "qVSQhTVSyYYO"
   },
   "source": [
    "#Module 6 - \"Constraint Satisfaction Problems\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "id": "Wm4mfW82yaRH"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA, Chapter 6 “Constraint Satisfaction Problems” (6.1-6.5)\n",
    "chapter6_1 = \"\"\"\n",
    "- set of vairables, domains for variabvles and ocntaints (allwoable cominbtions of vlaues\n",
    "- contriats can be modled as rlaitons between varibles\n",
    "- all contriants can be modelled as binary byb introiducing aucilary vairbles\n",
    "- global contsint = more than two bvaile,s not a all variables\n",
    " \"\"\"\n",
    "chapter6_2 = \"\"\" \n",
    "- node consitency is just unary contrints beingh siatifed\n",
    "- arc consitncy is satisicaiont of bianry contrintys \n",
    "  - rmember, can concrrt contrints to binary...\n",
    "- path consitcy: assignment to set of two vairbles still allows for assiignemnt to a thrid (3-consinmcy)\n",
    "- k-consitncy: gnerlaiziton: for any consintnetto a  set of k-1 vaitrbles, consinten vlaue can be asisgned to a kth vailes\n",
    "- stonhly k-consint: if k consintent, also k-1 conmsint, k-2 consint... ec. down to uanry...\n",
    "- all difff is impolrtant globe constitrn\n",
    "- AC_3 by sitlef only solves easit suko....\n",
    "- AC_3 is rmeoves vairles form domain that don't siafie acr consitny\n",
    "- start with queu of all arcs (contrina has tail on left, arrow pint right to head)\n",
    "  - check that for all values in tail, there is value in head that allows siaifiaciton of contint\n",
    "  - if not, rmeove vlaue from tail\n",
    "  - if removce any valeus form tial (X), add arc to que that have X as head 9since less values in domain of X, might need to udpate variabvles that have contrinst swith X)\n",
    "\n",
    " \"\"\"\n",
    "chapter6_3 = \"\"\" \n",
    "- can do bakcrtaking searh also: depth first sarch\n",
    "- to make more ficitn, try mopst contrint variables first. Fial fast\n",
    "  - fi tied: choose vairable invl.ed in most contrints... (dggre heuisitcs)\n",
    "- then, choose least continaing values.\n",
    "- van interlave inference 9rmeoveal of contrints =forad checking.\n",
    "  - foeward checknig only does one pass on vaiable that is asisnged\n",
    "  - better to do aAC-3\n",
    "-= can do smar bakctacking\n",
    "  - backjiumpiomnhg: not needed with foward cehcking/einfernce\n",
    "\n",
    "e \"\"\"\n",
    "chapter6_4 = \"\"\"\n",
    "- for n-queuens: can randomize, then adjust one queen to rduce conflict\n",
    "  - chosoe whic quweento ajust frnaomly\n",
    "  - works very for alrge problem, becuae soltuion space is dense.... (so rnaomied start not to far from solutonm..)\n",
    "\"\"\"\n",
    "chapter6_5 = \"\"\"\n",
    "- can model CPS as gpahs\n",
    "- toplogfical sort\n",
    "- custset: rmoce viarbles; make into a tree. Asisng to thes e virables., then easy to find vbalieus in tre ..\n",
    "- tre doemcpisno:: make into a tre where each nos is a set o f vbiarbles. Vairbvle sin oringal poroblem msut apa in a t one node tobert.\n",
    "  0 apply tre-cps soler\n",
    "- vlaue smmyert\n",
    " \"\"\"\n",
    "\n",
    "\n",
    "# Lecture notes \n",
    "module6_lecture_notes = \"\"\"\n",
    "- Wlltz-mackor contirnt propagiton not a goo as AC-3: donsne't add to que aerficntly.\n",
    "- - make bracktracking searhc more siiecintg since viable aisngment is conutv e(ordr dones' tmatter)\n",
    "\"\"\"\n",
    "\n",
    "# Definitions\n",
    "module6_definitions = {\n",
    "\"concept\" : \"definition\",    \n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "kKWbCsbfxL3R",
    "outputId": "feabc5a3-0187-484d-db66-de1590d4d3c6"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 6: Constraint Satisfaction Problems\n",
       "## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n",
       "\n",
       "- set of vairables, domains for variabvles and ocntaints (allwoable cominbtions of vlaues\n",
       "- contriats can be modled as rlaitons between varibles\n",
       "- all contriants can be modelled as binary byb introiducing aucilary vairbles\n",
       "- global contsint = more than two bvaile,s not a all variables\n",
       " \n",
       "\n",
       "## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n",
       " \n",
       "- node consitency is just unary contrints beingh siatifed\n",
       "- arc consitncy is satisicaiont of bianry contrintys \n",
       "  - rmember, can concrrt contrints to binary...\n",
       "- path consitcy: assignment to set of two vairbles still allows for assiignemnt to a thrid (3-consinmcy)\n",
       "- k-consitncy: gnerlaiziton: for any consintnetto a  set of k-1 vaitrbles, consinten vlaue can be asisgned to a kth vailes\n",
       "- stonhly k-consint: if k consintent, also k-1 conmsint, k-2 consint... ec. down to uanry...\n",
       "- all difff is impolrtant globe constitrn\n",
       "- AC_3 by sitlef only solves easit suko....\n",
       "- AC_3 is rmeoves vairles form domain that don't siafie acr consitny\n",
       "- start with queu of all arcs (contrina has tail on left, arrow pint right to head)\n",
       "  - check that for all values in tail, there is value in head that allows siaifiaciton of contint\n",
       "  - if not, rmeove vlaue from tail\n",
       "  - if removce any valeus form tial (X), add arc to que that have X as head 9since less values in domain of X, might need to udpate variabvles that have contrinst swith X)\n",
       "\n",
       " \n",
       "\n",
       "## AIMA Chapter 6.3 Backtracking Search for CSPs\n",
       " \n",
       "- can do bakcrtaking searh also: depth first sarch\n",
       "- to make more ficitn, try mopst contrint variables first. Fial fast\n",
       "  - fi tied: choose vairable invl.ed in most contrints... (dggre heuisitcs)\n",
       "- then, choose least continaing values.\n",
       "- van interlave inference 9rmeoveal of contrints =forad checking.\n",
       "  - foeward checknig only does one pass on vaiable that is asisnged\n",
       "  - better to do aAC-3\n",
       "-= can do smar bakctacking\n",
       "  - backjiumpiomnhg: not needed with foward cehcking/einfernce\n",
       "\n",
       "e \n",
       "\n",
       "## AIMA Chapter 6.4 Local Search for CSPs\n",
       "\n",
       "- for n-queuens: can randomize, then adjust one queen to rduce conflict\n",
       "  - chosoe whic quweento ajust frnaomly\n",
       "  - works very for alrge problem, becuae soltuion space is dense.... (so rnaomied start not to far from solutonm..)\n",
       "\n",
       "\n",
       "## AIMA Chapter 6.5 The Structure of Problems\n",
       "\n",
       "- can model CPS as gpahs\n",
       "- toplogfical sort\n",
       "- custset: rmoce viarbles; make into a tree. Asisng to thes e virables., then easy to find vbalieus in tre ..\n",
       "- tre doemcpisno:: make into a tre where each nos is a set o f vbiarbles. Vairbvle sin oringal poroblem msut apa in a t one node tobert.\n",
       "  0 apply tre-cps soler\n",
       "- vlaue smmyert\n",
       " \n",
       "\n",
       "## Module 6 Lecture Notes\n",
       "\n",
       "- Wlltz-mackor contirnt propagiton not a goo as AC-3: donsne't add to que aerficntly.\n",
       "- - make bracktracking searhc more siiecintg since viable aisngment is conutv e(ordr dones' tmatter)\n",
       "\n",
       "\n",
       "## Module 6 Definitions\n",
       "* **Concept** - definition\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "module6_sections = [\n",
    "  (\"AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\", chapter6_1),\n",
    "  (\"AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\", chapter6_2),\n",
    "  (\"AIMA Chapter 6.3 Backtracking Search for CSPs\", chapter6_3),\n",
    "  (\"AIMA Chapter 6.4 Local Search for CSPs\", chapter6_4),\n",
    "  (\"AIMA Chapter 6.5 The Structure of Problems\", chapter6_5),\n",
    "  (\"Module 6 Lecture Notes\", module6_lecture_notes),\n",
    "]\n",
    "\n",
    "module6_markdown = format_module(6, \"Constraint Satisfaction Problems\", \n",
    "                         module6_sections, \n",
    "                         module6_definitions)\n",
    "display(Markdown(module6_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "RYESi2kMybL8"
   },
   "source": [
    "#Module 7 - Logical Agents"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "id": "qIRJ4YYCzNHL"
   },
   "outputs": [],
   "source": [
    "# Russell and Norvig, AIMA Chapter 7 “Logical Agents” (Sections 7.1-7.5)\n",
    "\n",
    "chapter7_1 = \"\"\" \n",
    "- axiom: given, no need to inger - simialr to bakground knowldge\n",
    "- knowlege bse: set of sentence\n",
    "infernece: deive new snences\n",
    " \"\"\"\n",
    "chapter7_2 = \"\"\" Your summary here \"\"\"\n",
    "chapter7_3 = \"\"\" \n",
    "- enitalment: sentnce tneitgals another if first sentce is ture in all worls/wmodels that esocnd snentece is true (models in which firest snentce is true is sunbet of scenod)\n",
    "- knlwodsge bnase i false in models that contricts what agne tknows\n",
    "- inernce algoirthms should be sound (only infer true tings) andncmplete: can derie any senence that is enitals\n",
    "= also wahnt to b eforunded: have logical sybtax translte to real world...\n",
    "\"\"\"\n",
    "chapter7_4 = \"\"\"\n",
    "- model checking: check all possible models, see if query holds in model in which knowldge base holds\n",
    "\n",
    " \"\"\"\n",
    "chapter7_5 = \"\"\"\n",
    "- A entails B if and only if there is no model in which both A and not B are True\n",
    "- modnes mones: if pemrise is ture, than can infer conlusino\n",
    "- and-lmiaiton: if AND sentnce, and knwo it is true, then know that cmponts are tur.\n",
    "- logical quilcance\n",
    "- proofg by  roelsiton: cancel out negative and positve, gives a solbnet:\n",
    "- can use in conjecitve n4eagice form\n",
    "- rolsiuotn algrioth - progof by contadicitnog. resolve clauses, get smalelr. keep on doing until get cmepty clause (contatidiont, so teruen ture), or can resolve any more (reutn false - can't prove by contadicont)\n",
    "- horn clause is dijcnin of listers (OR), where  at emost one is true\n",
    " - osninent unde rhreusltiojnL: roslving two horn clauses gives a  hron clasiue\n",
    " - dinigt is tpye of honr clause. Exactly one is ture\n",
    "   - quicanlt to an nmplkciaioptn..\n",
    "-  with fienite clasue, can use fowar chaing:\n",
    "  - keep track of number of litera in prmeis. If know that al ae tue, then get conlucsion. ... add to symbvols/litersl..\n",
    "\n",
    " \"\"\"\n",
    "\n",
    "# Lecture notes \n",
    "module7_lecture_notes = \"\"\"\n",
    "Inference rules:\n",
    "- Modus Ponens: if given implication and premise is True, then know that conlcusion is also True:\n",
    "- And Elmination: If and statement is True, then know that both sides are also True:\n",
    "- Logical Equivalence:\n",
    "  - Can infer other forms based on logical equivalnce. Ex: biconditional elmination, implication elimination, De Morgan's rules, etc...\n",
    " \"\"\"\n",
    "\n",
    "# Definitions\n",
    "module7_definitions = {\n",
    "\"Commutativity of\" : \"definition\",    \n",
    "}\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "cellView": "form",
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 972
    },
    "id": "lXNcHuKjyNXa",
    "outputId": "1f4d5532-cdda-45f5-e5e9-3653fe44f5e9"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 7: Logical Agents\n",
       "## AIMA Chapter 7.1 Knowledge-Based Agents\n",
       " \n",
       "- axiom: given, no need to inger - simialr to bakground knowldge\n",
       "- knowlege bse: set of sentence\n",
       "infernece: deive new snences\n",
       " \n",
       "\n",
       "## AIMA Chapter 7.2 The Wumpus World\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 7.3 Logic\n",
       " \n",
       "- enitalment: sentnce tneitgals another if first sentce is ture in all worls/wmodels that esocnd snentece is true (models in which firest snentce is true is sunbet of scenod)\n",
       "- knlwodsge bnase i false in models that contricts what agne tknows\n",
       "- inernce algoirthms should be sound (only infer true tings) andncmplete: can derie any senence that is enitals\n",
       "= also wahnt to b eforunded: have logical sybtax translte to real world...\n",
       "\n",
       "\n",
       "## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n",
       "\n",
       "- model checking: check all possible models, see if query holds in model in which knowldge base holds\n",
       "\n",
       " \n",
       "\n",
       "## AIMA 7.5 Propositional Theorem Proving\n",
       "\n",
       "- A entails B if and only if there is no model in which both A and not B are True\n",
       "- modnes mones: if pemrise is ture, than can infer conlusino\n",
       "- and-lmiaiton: if AND sentnce, and knwo it is true, then know that cmponts are tur.\n",
       "- logical quilcance\n",
       "- proofg by  roelsiton: cancel out negative and positve, gives a solbnet:\n",
       "- can use in conjecitve n4eagice form\n",
       "- rolsiuotn algrioth - progof by contadicitnog. resolve clauses, get smalelr. keep on doing until get cmepty clause (contatidiont, so teruen ture), or can resolve any more (reutn false - can't prove by contadicont)\n",
       "- horn clause is dijcnin of listers (OR), where  at emost one is true\n",
       " - osninent unde rhreusltiojnL: roslving two horn clauses gives a  hron clasiue\n",
       " - dinigt is tpye of honr clause. Exactly one is ture\n",
       "   - quicanlt to an nmplkciaioptn..\n",
       "-  with fienite clasue, can use fowar chaing:\n",
       "  - keep track of number of litera in prmeis. If know that al ae tue, then get conlucsion. ... add to symbvols/litersl..\n",
       "\n",
       " \n",
       "\n",
       "## Module 7 Lecture Notes\n",
       "\n",
       "Inference rules:\n",
       "- Modus Ponens: if given implication and premise is True, then know that conlcusion is also True:\n",
       "- And Elmination: If and statement is True, then know that both sides are also True:\n",
       "- Logical Equivalence:\n",
       "  - Can infer other forms based on logical equivalnce. Ex: biconditional elmination, implication elimination, De Morgan's rules, etc...\n",
       " \n",
       "\n",
       "## Module 7 Definitions\n",
       "* **Commutativity of** - definition\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#@title Preview of your summary\n",
    "#@markdown You don't need to modify anything in this cell. Just press play.\n",
    "module7_sections = [\n",
    "  (\"AIMA Chapter 7.1 Knowledge-Based Agents\", chapter7_1),\n",
    "  (\"AIMA Chapter 7.2 The Wumpus World\", chapter7_2),\n",
    "  (\"AIMA Chapter 7.3 Logic\", chapter7_3),\n",
    "  (\"AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\", chapter7_4),\n",
    "  (\"AIMA 7.5 Propositional Theorem Proving\", chapter7_5),\n",
    "  (\"Module 7 Lecture Notes\", module7_lecture_notes),\n",
    "]\n",
    "\n",
    "module7_markdown = format_module(7, \"Logical Agents\", \n",
    "                         module7_sections, \n",
    "                         module7_definitions)\n",
    "display(Markdown(module7_markdown))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "vX7lbnJd4sT5"
   },
   "source": [
    "# Your Exam Notes\n",
    "\n",
    "Here are your full set of exam notes that you can use on your midterm.  Choose **Runtime > Run all**, then your notes will be displayed.\n",
    "\n",
    "If you are taking the exam in person, then you must print a copy of your notes for yourself.   Here's how to print:\n",
    "* Run the cell below. \n",
    "* Click its \"Mirror cell in tab\" button (this is located in the upper right corner of the cell, immediately to the right of the trash can).  This will open the cell.  \n",
    "* In Chrome, you can then print your notes using the **File > Print** option from the browser's menu.  \n",
    "* In the print options, change the layout from Landscape to Portrait. \n",
    "* Clicking the Save, will save a PDF that you can then print.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000
    },
    "id": "T3cm1WV542_a",
    "outputId": "926b217e-fb09-400c-fe28-cc8d5d9074c9"
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "# Module 1: Rational Agents and Task Environments\n",
       "## AIMA Chapter 1.1 What is AI?\n",
       " Chapter 1.1 summary. \n",
       "Four approaches to develpoing AI:\n",
       "- Creating systems that act human\n",
       "  - Validate with Turing test\n",
       "- Create systems that think humanly\n",
       "  - Roots in cognitive science. Study the brain\n",
       "- Create systems that think rationally:\n",
       "  - Fomral logic (Chapter 7 - Logical agents)\n",
       "- Create systems that act rationally\n",
       "  - Maximize expected utility\n",
       "  - Approach taken in this course and texbook\n",
       "  - More of an \"engineering\" approach. Does it do what it is supposed to?\n",
       "  - \"Do the right thing\" = Maximize expected utility\n",
       "\n",
       "\n",
       "## AIMA Chapter 27.1 The Limits of AI\n",
       " \n",
       "**Arguments for limits of AI**:\n",
       "- human behavior too complex to model with formal logic in computer (qualification problem)\n",
       "- Can't study functioning of brain outside of body (*embodied cognititon*)\n",
       "- Qualificatoin problem: Computer can never do X\n",
       "  - Computers have been able to do a lot that have been predicted that they can't\n",
       "  - People fall in love with Teddy Bears\n",
       "- Godels' incompleteness theorem (In any formal axiomatic framework, can construct a sentence that cannot be proven, but is still true)\n",
       "  - Claims that computers need to obey, but humans do not, so AI can never be as good as human intelligence\n",
       "  - but only applies to math, not cognitiion\n",
       "  - Not really a big deal, and human brains don't really have special properties\n",
       " \n",
       "\n",
       "## AIMA Chapter 27.1 Can Machines Really Think?\n",
       " \n",
       "- Conciusness is ill defined\n",
       "- Chinese room problem by Searle: Computers just blindly following instructions, don't really understand\n",
       "  - Counter argument: Human cells, just blindly following instructions, don't really understand.\n",
       "\n",
       "## AIMA 2.1 Agents and Environments\n",
       "\n",
       "- Percept: What an agent perceives (at current time)\n",
       "- Actuators: act upon environment\n",
       "- Percept sequence: history of everything agent has perceived\n",
       "- Agent function vs agent program:\n",
       "  - Agent function maps percepts sequences to actoins\n",
       "  - Agent program is an implementation of agent function\n",
       "  -  \n",
       "\n",
       "## AIMA 2.2 Good Behavior: The Concept of Rationality\n",
       " \n",
       "In desigining rational agents, give them performance measures. Rational agents need to maximize expcted performance measure by choosing best actions given percept sqeunce. Note that agent only needs to maximize **expected** performance meaure, not actual. ]\n",
       "Don't say that an agent isn't rational due to bad luck. Can't expect ominisinece. \n",
       "\n",
       "Can say that a thermometer is an agent.\n",
       "\n",
       "\n",
       "## AIMA 2.3 The Nature of Environments\n",
       " \n",
       "Group **P**erformance measure, **E**nvironment, **A**ctuators, and **S**ensors under the acronym **PEAS**. \n",
       "\n",
       "## Properties of task environments:\n",
       "- Fully observable vs partially observable \n",
       "  - Could also have unobservable environments...\n",
       "- Single agent vs multiagent\n",
       "  - In this context, another entity can be considered to be an agent if it is trying to maximize  a performance measure that is affected by principal's agent's actions\n",
       "- Deterministic vs non-determinstic\n",
       "  - Partially observable environments or very complex ones can be effectively non-deterministic\n",
       "  - textbook uses stochastic to refer to environments with explicit probabilities, while non-determnistic is used\n",
       "  for environments where probablities not explicitly defined, but know that outcome of actions not always the same\n",
       "- Static vs dynamic\n",
       "  - Does the environment change even when agent doesn't take an action?\n",
       "- episodic vs sequential?\n",
       "  - Is performance measure evaluated after single percept followed by single action,\n",
       "  with future percepts not depending on action? (episodic)\n",
       "    - Ex: clasification problems\n",
       "  - Or does agent make series of actions, where future percepts/state of world depends on\n",
       "  action? (sequential)\n",
       "    - Ex: chess\n",
       "- Discrete vs continous\n",
       "  - Way time is handled\n",
       "  - chess is discrete, playing starcraft is effectively continous (even if everything is discrete in computer representation)\n",
       "- Known vs unknown\n",
       "  - are rules of environment codified into agent?\n",
       "\n",
       "Hardest environment is partially observable, multiaent, non-determnistic, sequential, continours, and unknown.Autonomous cars checks most of these boxes, except most things are known (such as rules of road, physics etcc..)\n",
       "Could make more difficult by trying to drive in new country where rules of road are unknown, or install on janky car... \n",
       " \n",
       "\n",
       "## AIMA 2.4 The Structure of Agents\n",
       " \n",
       "Agent program runs on a certain architeture (physical computing device, sensors and actuators, etc..)\n",
       "\n",
       "Different kind of agents:\n",
       "- table lookups\n",
       "  - percept sequences quickly become too large for this approach\n",
       "- reflex agents\n",
       "  - just choose action on current percept, ignore history\n",
       "- Model-based reflex agents\n",
       "  - Keep track of (relevant) unobserved world. Take into account in addition to current percept.\n",
       "- Goal based agents\n",
       "  - Model how actions will affect world, so can plan better\n",
       "  - Search problems are examples of goal based agents\n",
       "- Utility based agents\n",
       "  - Model performance measure with utility function\n",
       "  - try to maximize utiltiy\n",
       "  - Helps make tradeoffs and choose between different goals\n",
       "  - Try to maximize expected utiltiy\n",
       "\n",
       "Can combine different approaches. Put reflexive actions inside of more complex utility based agents when decision is clear.\n",
       "\n",
       "Want agent programs that learn, so we don't need to code everything in advance.\n",
       "\n",
       "Can have atomic represenations of world (states with no internal, such as for simple search), factored (states have internal variables or attributes such as in CSPs or logic agents),or structured (first order logic and natural language).\n",
       "\n",
       "\n",
       "## Module 1 Lecture Notes\n",
       "\n",
       "- Things that can be viewed as agents:\n",
       "  - pet hamster\n",
       "  - thermostat\n",
       "  - touchless faucet\n",
       "  - (but not bathroom faucet turned on by handle)\n",
       "\n",
       "\n",
       "## Module 1 Definitions\n",
       "* **Agent** - anything that can perceive and act in an environment\n",
       "* **Percept** - your definitions here\n",
       "* **Other concept** - your definitions here\n",
       "* **Etc.** - your definitions here\n",
       "\n",
       "\n",
       "# Module 2: Python\n",
       "## Module 2 Lecture Notes\n",
       " \n",
       "- Can have (pointers to) None objects in list\n",
       "- Can repeat a string by multiplying by an integer: `\"a\" * 3 = \"aaa\"`\n",
       "- Python is both dynamically typed and strongly typed\n",
       "  - Dynamically means that variables can be reassigned to objects of different types\n",
       "  - Strongly means that every object has type, and that properties of type are respected\n",
       "- Python uses Duck typing: don't check if object is of certain type, just assume that it can do certain things, and catch exceptions\n",
       "- lst[:] returns a copy\n",
       "- Can't add sets `{1} + {2}` gives an error\n",
       "  - but can do subtraction `{1} - {2}` gives `{1}`\n",
       "- Last part of Python index always excluded. `a = [1,2,3]; a[:-1] = [1,2]`\n",
       "- To slice by steps or backwads, add extra colon. `a[::-1] = [3,2,1]; a[::2] = [1,3]; a[-2::-1] = a[1::-1] = [2,1]`\n",
       "- slicing creates copies (of references)\n",
       "- can make generator just by adding `yield` keyword. Generally have in a loop. Then can use `for foo in generator()`\n",
       "- WHen doing list comprehension `[(x,y) for x in foo1 for y in foo2]` gives cartesian product. SO if both foo1 and foo2 have 3 elements, then result is 9 elemtns\n",
       "- To filter in list comprhension, put conditional statment at end: `[(x,y) for x in foo1 for y in foo2 if x > 1]` \n",
       "- if have `if` statement earlier, then it is ternary statment: `[(x,y) if x > 1 else x for x in foo1 for y in foo2]` \n",
       "\n",
       "\n",
       "## Module 2 Definitions\n",
       "* **Mutability** - Attibutes/internal of object can change after creation. Therefore not hashable. Therefore can't assign as key to dictionaryy\n",
       "\n",
       "\n",
       "# Module 3: Search Problems\n",
       "## AIMA Chapter 3.1 Problem-Solving Agents\n",
       " \n",
       "A search problem takes place in an environment that is is assumed to be fully observable, deterministic and known.\n",
       "\n",
       "Informally, we are trying to get from one location to another through a series of actions with a minimum cost.\n",
       "\n",
       "Formally, a serach problem is deinfed as:\n",
       "- a space state that consists of possible states\n",
       "  - state correspond to real world, such at what city we are in or layout of a board\n",
       "- a starting space that the agents starts in\n",
       "- a *GOAL(s) function that indicates if state s is a goal state\n",
       "- a set of actions that are applicable in each state\n",
       "-  a transition model that tells use what state we end up in based on the state we are currenly in and the action we take\n",
       "- an action cost funtion that gives us the cost based on taking action *a* to get to state *s_j* from state $$s_i$$\n",
       "\n",
       "Trying to find the sequence of actions from initital state to goal state with minimum cost\n",
       "\n",
       "Can represent states as nodes in graph, with edges between nodes when we can transition between the two nodes\n",
       "\n",
       "Level of abstraction is important. If planning shortest trip, abstracting away details on driving and such. Just assume it works out.\n",
       "\n",
       "\n",
       "\n",
       "## AIMA Chapter 3.2 Example Problems\n",
       " \n",
       "- can have an infinite state spaces\n",
       "  - Knuth's conjecture that we can get to any integer starting from 4 just by applying square root, factorial and floor operations\n",
       "- touring problems: travelling salemen. \n",
       "- VLSI layout: Channel routing to find shortest path for wires throguh gaps in cells.\n",
       " \n",
       "\n",
       "## AIMA Chapter 3.3 Search Algorithms\n",
       "\n",
       "- Search algorithm takes as input a search problem and either returns path from start to goal or indicates that no solution exists\n",
       "- Algorithms create search tree, consisting of nodes with attributes of state and path cost\n",
       "  - same state can appear multiple times in tree in different nodes\n",
       "  - Edges correspond to actions\n",
       "- Important concepts:\n",
       "  - $$Expand(n)$$: take a node and generates all succesor nodes (states we can reach from input node/state, based on single action)\n",
       "  - **frontier**: set of nodes which of have been generated by *Expand()*, but not yet expanded themselves\n",
       "  - **reached**: a state has been reached when any node has been generated for it. For best first search, a data struture that maps from state to a node.     - For breadth first search, returns True or False when given a state\n",
       "\n",
       "**Best First Search**\n",
       "General algorithm that models frontier as a priority queue with evaluation function $$f(n)$$\n",
       "- start with root node/initial state in priority queue\n",
       "- while priority queue is not empty, pop a node (get node with lowest evaluation function)\n",
       "- If the node is goal, return it (success!)\n",
       "  - can get path from node, since node contains pointer to parent\n",
       "- Expand node to get children\n",
       "- for each child, add it to frontier if either child.state not in reached, or if reached[child.state].path_cost > child.path_cost\n",
       "  - if adding to frontier, update reached data structure so that child.state points to this node\n",
       "\n",
       "**Redundant Paths**\n",
       "Can be many different ways of reaching same state. Can cause slowdowns by needlesly checking paths that we know aren't efficient.Can handle by keeping track of reached states like in Best First Search. Call algorithms that check for redundant paths *graph search* algorithms. They use more memory because they keep track of reached nodes. Don't have to keep track of redundant paths if we know that there aren't many. Algorithms that don't keep track of redundant paths are called *tree search* algorithms. Ex: Depth first search. Saves memory.Can also check for cycles (using pointers stored in nodes) instead of redundant paths. Doesn't uses extra memory but requires extra computation. Can just check for cycles of certain length.\n",
       "\n",
       "\n",
       "\n",
       "In computer science, use number of nodes |V| and edges |E| to evaluate complexity. But often don't know this in AI. Instead, consider depth *d* at which optimal solution lies, *m* maximum number depth of tree and *b* the branching factor or number of successor nodes considered at each point in search tree.\n",
       "\n",
       "\n",
       "## AIMA Chapter 3.4 Uninformed Search Strategies\n",
       " \n",
       "- breadth-first search\n",
       "  - used when all actions have same cost\n",
       "  - expands nodes in order they are generated (first in first out FIFO)\n",
       "  - Could use best first search, but can make more efficient by:\n",
       "    - using FIFO queue instead of priotiy\n",
       "    - *Early goal test*: check if node is solution as soon as generated, rather than when popped off queue\n",
       "      - Since nodes generated later will always have higher cost\n",
       "  - have *reached* data stucture just contain True/False, rather than pointers to nodes.\n",
       "  - Bread first search is:\n",
       "    - complete\n",
       "    - optimal if all actions cost one\n",
       "    - has space and time complexity of $O(b^d)$\n",
       "      - time complexity is fine, space complexity is high: run out of memory\n",
       "- uniform cost search/Dijkstra's algorithm\n",
       " - for when actions have different costs\n",
       " - use best first search, with evaluation funciton being path cost\n",
       " - is complete, optimal. Space and time complexity is $O(b^{1+C^{*}/\\epsilon})$ where C* is cost of optimal solution and e is lower bound on cost of each action\n",
       "   - can be much larger than b^d, because uniform cost explores many branches with low cost before explroing higher cost branches with potentially better actions\n",
       " - Dijkstra algoithm is uniform search without a goal\n",
       "- depth first search\n",
       "  - is tree search, don't track if reached\n",
       "  - not complete if infinite depth/cycles. Not optimal\n",
       "  - more memory efficient: O(bm): *m* is maximum depth of tree. Can be even less with backtracking searching: generate only one succesor at a time\n",
       "  - time: O(b^m): if **m** is infinte, that is bad\n",
       "- iterative deepening\n",
       "  - over come limitations of DFS by restricting depth so don't run infinitely. Gradually increase depth\n",
       "  - complete and optimal\n",
       "  - time complexity is O(b^d) when there is solution, O(b^m) when no solution. *m* is max depth...\n",
       "- bidirectional\n",
       "  - start from goal and intitial state\n",
       "  - complexity: O(b^d/2)\n",
       "\n",
       "\n",
       "## Module 3 Lecture Notes\n",
       " \n",
       "\n",
       "** Measuring performance**\n",
       "Evaluate search algorithms on:\n",
       "- Completeness: Is the algorithm guranteed to return a solution if one exists?\n",
       "  - Algorithm needs to be *systematic* to be complete = able to reach any state. Since solution could be any state. If space is infinite, algorithm can't ever be certain that solution doesn't exist \n",
       "- Cost optimilaty: Is returned solution lowest cost?\n",
       "- Time complexity: Amount of time or computation needed to find solution\n",
       "- Space complexity: Amount of space (physical or abstact) needed \n",
       "\n",
       "## Module 3 Definitions\n",
       "* **Problem-solving agent** - an agent that can formulate a plan via search\n",
       "* **Open loop system** - agent ignores percepts - can do this since world is deterministic, known and single player\n",
       "\n",
       "\n",
       "# Module 4: Informed Search\n",
       "## AIMA Chapter 3.5 Informed (Heuristic) Search Strategies\n",
       "\n",
       " - A\\* is cost optimal with consistent $h(n)$\n",
       "   - \"prunes\" away nodes/paths \n",
       " - satisficing solutions = \"good enough\"\n",
       "   - if use an inadmisible heuristic (pesimistic), then reduce number of nodes expanded at risk of missing optimal solution\n",
       "   - Variants of A\\* that find solutions less than C or within $\\epsilon$ of optimal solution\n",
       "   - Weighted A\\* search puts more weight on heuristic, equivalent to a pessimistic heuristic\n",
       "     - Greedy search puts all the weight on heuristic\n",
       "  - memory issues\n",
       "    - Main issue with A\\* is use of memory. Usually *reached* much larger than *frontier*\n",
       "    - Bidirectional A\\*\n",
       "    - RBFS\n",
       "    - Beam search\n",
       "      - limit size of frontier\n",
       "    - Iterative deepening A\\* (IDA\\*)\n",
       "    - SMA\\*:\n",
       "      - Adds nodes to *reached* until it fills, then \n",
       "      - Keeps track of f-value of forgotten node in parent so knows if worth expanding parent later.\n",
       "      - Deleting and adding can lead to thrashing.\n",
       "\n",
       "\n",
       "## AIMA Chapter 3.6 Heuristic Functions\n",
       "\n",
       "- if A\\* find solution at depth $d$ and generates $N$ nodes, then its *effective branching factor* $b*$ is such that $N + 1 = 1 + b* + (b*)^2 + ... + (b*) ^d$\n",
       "  - is the branching factor that a uniform tree of depth $d$ would need to have to generate N + 1 nodes\n",
       "  - charactizes the quality of a heuristic: lower is better\n",
       "  - *effective depth* is another measure\n",
       "- A heuristic $h^1$ dominates another heuristic $h^2$ if for any n, $h^1(b) \\geq h^2(n)$\n",
       "  - dominating heuristic will have lower *effective branching factor*  and be more efficient\n",
       "    - can see this since dominating heuristic will have less \"surely expanded nodes\" (nodes with $f(n) \\leq C*$ where C* is cost of optimal path)\n",
       "- Can generate heuristics to a problem by relaxing constraints\n",
       "  - Ex: for 8-puzzle, allowing squares to be moved through other squares produces heuristic of manhattan distance\n",
       "  - Works because any solution to actual problem is also solution to relaxed problem, so any solution to relaxed problem will have cost no more than cost to actual problem\n",
       "  - can take max of a collection of heuristics\n",
       "- *pattern databases* stores exact solution costs to subproblems (eg. for 8-puzzle, getting 4/8 in right place)\n",
       "  - is admissible heuristic\n",
       "  - can take the max of several problems\n",
       "  - if subproblems are disjoint, then can add costs\n",
       "  - can be very efficient (but require memory/storage space)\n",
       "- GPS and google Maps calculate routes quickly by using *landmarks*\n",
       "  - Store costs of going from any point to land mark\n",
       "  - THen heuristic is cost of going to closest landmark, then to goal\n",
       "    - Can be inadmissible (overstimate cost)\n",
       "- learning\n",
       "  - can use machine learning to estimate heuristic from current state based on features\n",
       "  - can also treat search like a search problem? metalevel learning?\n",
       " \n",
       "\n",
       "## Module 4 Lecture Notes\n",
       "\n",
       "- heuristic function $h(n)$ estimates shortest path distance between node *n* and a goal state\n",
       "- *Greedy search* is an implementation of *Best First Search* where the evaluation function $f(n) = h(n)$\n",
       "  - Complete on finite states, not infinte  (can get stuck in cycles)\n",
       "  - With good $h(n)$, complexity of $O(bm)$\n",
       "- * A\\* search* is Best First Search implementation thartuses an evaluation function of $f(n) = g(n) + h(n)$\n",
       "  - * A\\* is complete\n",
       "  - If $h(n)$ is admissible (i.e. optimistic so is always less than or equal to actual cost to reach goal), then A\\* is optimal\n",
       "     - Sketch of proof:\n",
       "      - If A\\* returns non-optimal solution with cost $C$, then some node $n$ that is on optimal path must be on frontier and unexpanded. Thus $f(n) > C$.\n",
       "      - $f(n) \\leq C* \\leq C$ since $h(n)$ is admissible. But this is contradiction\n",
       "  - consistency\n",
       "    - *Consistency* is stronger than admissibility: $h(n) \\leq c(n,a,n1) + h(n')$\n",
       "      - Basically requirement for heuristic to obey triangle inequality\n",
       "      - if $h(n)$ is consistent, then can be like BFS - ignore later nodes for same state since pathcost for first node will be optimal\n",
       "        - if consistent, can use tree search (don't need to keep track of reached)\n",
       "        - quiz is wrong, says is False that the graph search of A\\* is optimal as long as the heuristic is admissible. This is in fact true.\n",
       "- search contours\n",
       " - A\\* search spreads out in contours that \"stretch\" towards goal, compared to uniform-cost search, where contours are circular\n",
       "\n",
       "\n",
       "\n",
       "## Module 4 Definitions\n",
       "* **Reference counts** - track number of times a state has been reached and remove from reached datastructure when no more ways to reach\n",
       "* **Beam search** - limit size of frontier by keeping *k* nodes with best *f*scores\n",
       "* **Ida\\*** - Each round, increase 'depth' to smallest f-score that exceeded last iteration's depth. Works well for integer valued f-scores\n",
       "* **Recursive best-first search (rbfs)** - No *reached* datastructure. Each node remembers f-score of best alternative path. Backsup when f-value of current path exceeds best alternaitve.\n",
       "* **Bidirectional heurisitc search** - Full page in text book.\n",
       "\n",
       "\n",
       "# Module 5: Adversarial Search and Games\n",
       "## AIMA Chapter 5.1 Game Theory\n",
       " ==\n",
       "- A game has:\n",
       "  - Two players: MAX and MIN\n",
       "    - Alternate turns\n",
       "    - MAX goes first: calcuulations done from perspective of Max\n",
       "  - An initial state, $$S_0$$\n",
       "  - terminal states\n",
       "  - A utility function that returns utility for finishing in a certain state\n",
       "- \n",
       "\n",
       "\n",
       "## AIMA Chapter 5.2 Optimal Decisions in Games\n",
       "\n",
       "- *minimax search*\n",
       "  - recurisve - max picks from results of minimax from MINS perspecitve with highest ulitiy. MIN picks from results of minimax from MAX's perpective with lowest utiltiy. If leaf, then just reutnr uitliy.\n",
       "- if muitl;p[layer, then replace single uiltiy, with vector at each node\n",
       "- alpha bata rpunig: alpha is Max best utlity in this branch so far. Starts off at negative infinty at root. If min finds better result than alpha (lower), then know that max will nvber go down this branch, so stop serarhcing this brnabn\n",
       "  - update alpha wwith best value. First time get reuslt from branch updater, Then if find betterm update gain. Provide al;phah to mininmax form MIN's perepctive so MIN knoiw to sto searhc\n",
       "  - beta is iquiovalnt for MIN. Start off at iniftity. If find lower (better) update.\n",
       "- can try move ordering to improve alpgha beta- : stop searching faster\n",
       "\n",
       "\n",
       "\n",
       "## AIMA Chapter 5.3 Heuristic Alpha–Beta Tree Search\n",
       "\n",
       "- sually cn't search too deep, so have heistic ebaultion funciton that can be evaulted at any baord state. Shoudl appocate ulity funciton\n",
       "- can stop searching early. Searhc to certia depth. (cutooff)\n",
       "- foerard pruning is method of narrpwing moves consider oto look at best. Fawster, but risk of not being optmal Beam search keep top n.\n",
       "- Can uise lookeup for board states where bst m ove know. Start omces and end mocves in chess.\n",
       " \n",
       "\n",
       "## AIMA Chapter 5.5 Stochastic Games\n",
       " \n",
       "- in socahistc games, have chance nodes. Priblairyes for whioch acitons will be takne. Rahter than reutnrin min or max, retuned average/expectd values of eultiy..\n",
       "\n",
       " \n",
       "\n",
       "## AIMA Chapter 16.1 Combining Beliefs and Desires under Uncertainty\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 16.2 The Basis of Utility Theory\n",
       "\n",
       "6 constrinats on prferences:\n",
       "- orceability (can always choose between 2 loteries\n",
       "- trnaisviity\n",
       "- subitiylaiblity (weight loteries so can be indeffernet))\n",
       "- montocity: if prfer otciumoe A o B, then must prefer lottery that gives higher prob to outcome A\n",
       "- Domcpaislity: can reduce compound lotereis into simpler ones using laws of problality\n",
       "\n",
       "- based on raitonal prfernces, can always have a wel bahbed utiltyi funtion\n",
       "  - well baheved, because utiliy of lotters is sum of problaity o foutocme times utiltiy of outome\n",
       " \n",
       "\n",
       "## AIMA Chapter 16.3 Utility Functions\n",
       " \n",
       "- utilfuncitons can be normalier between 1 and 0 \n",
       "- standard lotteirs: best and worse otucomes - probialtiy are asjuted until indernt to another ocuome\n",
       "- montic prefernce for money\n",
       "  - dopnes'y mean that it is linear\n",
       "- people risk adverse\n",
       "- insurnce premium \n",
       "- even if esimtates are ubniaes, always have diapalintment, since chosing loteir with highest epxectd utiltiy. Erros means lays going to have lower.\n",
       "  -optimaixzer curse.\n",
       "  - betterto choose lower vialbil;y, even if expected otuomce is lwoer...\n",
       "- achoring effcet\n",
       "- frmaing effct...\n",
       "- poeple don't liek abiguity.\n",
       " \n",
       "\n",
       "## Module 5 Lecture Notes\n",
       "\n",
       "- minimax: Don't play hope chess\n",
       "\n",
       "\n",
       "## Module 5 Definitions\n",
       "* **Ply** - one move per player - layerlevel in search tree\n",
       "\n",
       "\n",
       "# Module 6: Constraint Satisfaction Problems\n",
       "## AIMA Chapter 6.1 Defining Constraint Satisfaction Problems\n",
       "\n",
       "- set of vairables, domains for variabvles and ocntaints (allwoable cominbtions of vlaues\n",
       "- contriats can be modled as rlaitons between varibles\n",
       "- all contriants can be modelled as binary byb introiducing aucilary vairbles\n",
       "- global contsint = more than two bvaile,s not a all variables\n",
       " \n",
       "\n",
       "## AIMA Chapter 6.2 Constraint Propagation: Inference in CSPs\n",
       " \n",
       "- node consitency is just unary contrints beingh siatifed\n",
       "- arc consitncy is satisicaiont of bianry contrintys \n",
       "  - rmember, can concrrt contrints to binary...\n",
       "- path consitcy: assignment to set of two vairbles still allows for assiignemnt to a thrid (3-consinmcy)\n",
       "- k-consitncy: gnerlaiziton: for any consintnetto a  set of k-1 vaitrbles, consinten vlaue can be asisgned to a kth vailes\n",
       "- stonhly k-consint: if k consintent, also k-1 conmsint, k-2 consint... ec. down to uanry...\n",
       "- all difff is impolrtant globe constitrn\n",
       "- AC_3 by sitlef only solves easit suko....\n",
       "- AC_3 is rmeoves vairles form domain that don't siafie acr consitny\n",
       "- start with queu of all arcs (contrina has tail on left, arrow pint right to head)\n",
       "  - check that for all values in tail, there is value in head that allows siaifiaciton of contint\n",
       "  - if not, rmeove vlaue from tail\n",
       "  - if removce any valeus form tial (X), add arc to que that have X as head 9since less values in domain of X, might need to udpate variabvles that have contrinst swith X)\n",
       "\n",
       " \n",
       "\n",
       "## AIMA Chapter 6.3 Backtracking Search for CSPs\n",
       " \n",
       "- can do bakcrtaking searh also: depth first sarch\n",
       "- to make more ficitn, try mopst contrint variables first. Fial fast\n",
       "  - fi tied: choose vairable invl.ed in most contrints... (dggre heuisitcs)\n",
       "- then, choose least continaing values.\n",
       "- van interlave inference 9rmeoveal of contrints =forad checking.\n",
       "  - foeward checknig only does one pass on vaiable that is asisnged\n",
       "  - better to do aAC-3\n",
       "-= can do smar bakctacking\n",
       "  - backjiumpiomnhg: not needed with foward cehcking/einfernce\n",
       "\n",
       "e \n",
       "\n",
       "## AIMA Chapter 6.4 Local Search for CSPs\n",
       "\n",
       "- for n-queuens: can randomize, then adjust one queen to rduce conflict\n",
       "  - chosoe whic quweento ajust frnaomly\n",
       "  - works very for alrge problem, becuae soltuion space is dense.... (so rnaomied start not to far from solutonm..)\n",
       "\n",
       "\n",
       "## AIMA Chapter 6.5 The Structure of Problems\n",
       "\n",
       "- can model CPS as gpahs\n",
       "- toplogfical sort\n",
       "- custset: rmoce viarbles; make into a tree. Asisng to thes e virables., then easy to find vbalieus in tre ..\n",
       "- tre doemcpisno:: make into a tre where each nos is a set o f vbiarbles. Vairbvle sin oringal poroblem msut apa in a t one node tobert.\n",
       "  0 apply tre-cps soler\n",
       "- vlaue smmyert\n",
       " \n",
       "\n",
       "## Module 6 Lecture Notes\n",
       "\n",
       "- Wlltz-mackor contirnt propagiton not a goo as AC-3: donsne't add to que aerficntly.\n",
       "- - make bracktracking searhc more siiecintg since viable aisngment is conutv e(ordr dones' tmatter)\n",
       "\n",
       "\n",
       "## Module 6 Definitions\n",
       "* **Concept** - definition\n",
       "\n",
       "\n",
       "# Module 7: Logical Agents\n",
       "## AIMA Chapter 7.1 Knowledge-Based Agents\n",
       " \n",
       "- axiom: given, no need to inger - simialr to bakground knowldge\n",
       "- knowlege bse: set of sentence\n",
       "infernece: deive new snences\n",
       " \n",
       "\n",
       "## AIMA Chapter 7.2 The Wumpus World\n",
       " Your summary here \n",
       "\n",
       "## AIMA Chapter 7.3 Logic\n",
       " \n",
       "- enitalment: sentnce tneitgals another if first sentce is ture in all worls/wmodels that esocnd snentece is true (models in which firest snentce is true is sunbet of scenod)\n",
       "- knlwodsge bnase i false in models that contricts what agne tknows\n",
       "- inernce algoirthms should be sound (only infer true tings) andncmplete: can derie any senence that is enitals\n",
       "= also wahnt to b eforunded: have logical sybtax translte to real world...\n",
       "\n",
       "\n",
       "## AIMA Chapter 7.4 Propositional Logic: A Very Simple Logic\n",
       "\n",
       "- model checking: check all possible models, see if query holds in model in which knowldge base holds\n",
       "\n",
       " \n",
       "\n",
       "## AIMA 7.5 Propositional Theorem Proving\n",
       "\n",
       "- A entails B if and only if there is no model in which both A and not B are True\n",
       "- modnes mones: if pemrise is ture, than can infer conlusino\n",
       "- and-lmiaiton: if AND sentnce, and knwo it is true, then know that cmponts are tur.\n",
       "- logical quilcance\n",
       "- proofg by  roelsiton: cancel out negative and positve, gives a solbnet:\n",
       "- can use in conjecitve n4eagice form\n",
       "- rolsiuotn algrioth - progof by contadicitnog. resolve clauses, get smalelr. keep on doing until get cmepty clause (contatidiont, so teruen ture), or can resolve any more (reutn false - can't prove by contadicont)\n",
       "- horn clause is dijcnin of listers (OR), where  at emost one is true\n",
       " - osninent unde rhreusltiojnL: roslving two horn clauses gives a  hron clasiue\n",
       " - dinigt is tpye of honr clause. Exactly one is ture\n",
       "   - quicanlt to an nmplkciaioptn..\n",
       "-  with fienite clasue, can use fowar chaing:\n",
       "  - keep track of number of litera in prmeis. If know that al ae tue, then get conlucsion. ... add to symbvols/litersl..\n",
       "\n",
       " \n",
       "\n",
       "## Module 7 Lecture Notes\n",
       "\n",
       "Inference rules:\n",
       "- Modus Ponens: if given implication and premise is True, then know that conlcusion is also True:\n",
       "- And Elmination: If and statement is True, then know that both sides are also True:\n",
       "- Logical Equivalence:\n",
       "  - Can infer other forms based on logical equivalnce. Ex: biconditional elmination, implication elimination, De Morgan's rules, etc...\n",
       " \n",
       "\n",
       "## Module 7 Definitions\n",
       "* **Commutativity of** - definition\n"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# This will generate the full set of notes that you can use for your exam.\n",
    "full_markdown = \"\\n\\n\".join([module1_markdown, \n",
    "                             module2_markdown, \n",
    "                             module3_markdown, \n",
    "                             module4_markdown, \n",
    "                             module5_markdown,\n",
    "                             module6_markdown,\n",
    "                             module7_markdown,]\n",
    "                       )\n",
    "display(Markdown(full_markdown))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "id": "MPKMO2JBxln7"
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "name": "Copy of FINAL Template_for CIS521_midterm notes.ipynb",
   "provenance": []
  },
  "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.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
