{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# CS 4100 Homework 01 \n",
"\n",
"#### Due Thursday 1/19 at midnight (1 minute after 11:59 pm) in Gradescope (with a grace period of 6 hours)\n",
"#### You may submit the homework up to 24 hours late (with the same grace period) for a penalty of 10%. \n",
"\n",
"You must submit the homework as an .ipynb
file in Gradescope by the due date and time. \n",
"All homeworks will be scored with a maximum of 100 points; if point values are not given for individual\n",
"problems, then all problems will be counted equally. \n",
"\n",
"Please select Kernel -> Restart and Run All
before you submit; we will not run your code\n",
"while grading, and anything you do not demonstrate as correct will be assumed to be incorrect. \n",
"\n",
"The goals of this first homework are that you\n",
"\n",
"1. Get up to speed on Python and Jupyter Notebooks (by going through the various tutorials or other resources as needed);\n",
"2. Practice the submission process through Gradescope (and allow us to practice the grading process); and\n",
"3. Get started on the material in Chapter 2 of the textbook.\n",
"\n",
"Whenever possible, you will have all the material you need for homeworks the week before they are due (so\n",
"that you have the weekend before the due date to complete it). However this will not always be possible, and in this\n",
"homework, I am giving you some exercises on material we will cover on Monday 1/16; these should be\n",
"very familiar from your Discrete Mathematics course in any case. "
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Problem 1 (2 points)\n",
"\n",
"Sign up for an account for `chatGPT`:\n",
"\n",
"https://openai.com/blog/chatgpt/\n",
"\n",
"and ask it for advice on how to prepare for your Introduction to AI class. If the system is busy, you may have to try it late at night or early in the morning. \n",
"\n",
"Take a screen shot of your interaction. In the solution cell following, drag and drop your screen shot file;\n",
"when you run the cell, the image will display. \n",
"\n",
"**Note:** Sometimes when I do the drag and drop, nothing happens; I think this is when you try to drop an image file into a cell more than once, but I'm not precisely sure of the problem. If you simply create a new cell and try again, it should work. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Solution 1\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem 2 (8 points)\n",
"\n",
"For this problem, we will explore chatGPT's coding ability. \n",
"\n",
"**Note:** To input multi-line prompts, at the end of the line use Shift-Return instead of Return and it will\n",
"not submit the prompt. \n",
"\n",
"### Part 2.1\n",
"\n",
"Ask `chatGPT` whether the following code will correctly find the larger of the two integers x and y:\n",
"\n",
" if(x > y):\n",
" print(x)\n",
" \n",
"and observe the result. Then ask if the following code will correctly print the largest element in a list L:\n",
"\n",
" m = -1\n",
" for x in L:\n",
" if(x > m):\n",
" m = x\n",
" print(m)\n",
"\n",
"and observe the result. \n",
"\n",
"Ok, your turn! Play around with various examples and find a relatively complex program that `chatGPT` appears to\n",
"understand correctly. You may want to ask something more than just \"is this correct?\"\n",
"\n",
"As with Problem 1, paste your screenshot in the solution cell. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Solution 2.1\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Part 2.2\n",
"\n",
"Now play around with various examples and find a relatively simple program that `chatGPT` does NOT understand\n",
"correctly. Paste your screenshot in the solution cell. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Solution 2.2\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Part 2.3\n",
"\n",
"Ask `chatGPT` to write a Python program to determine if an integer n is a prime. Observe the result. \n",
"\n",
"Play around with various examples where `chatGPT` writes Python code and give an interesting example\n",
"where it creates a reasonably complex program. Try to add details or constraints so that it is\n",
"clearly not just spitting out something from StackOverflow. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Solution 2.3\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Part 2.4 (Not exactly about coding, but similar)\n",
"\n",
"Ask `chatGPT` to solve exercise 2.1 from the textbook and display the result as usual in the solution cell. Also evaluate whether it did the problem correctly.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Solution 2.4\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Part 2.5\n",
"\n",
"How well do you think `chatGPT` would work as a coding assistant? Give a brief assessment with pros and cons about\n",
"the practical use of the current system based on your own coding experiences. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Solution 2.5\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem 3 (20 points)\n",
"\n",
"\n",
"Do problem 2.2 c & d and provide the solutions using Markdown and Latex, or by writing it on paper, scanning it, and dragging and dropping it into the solution cell. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Solution 3\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem 4 (20 points)\n",
"\n",
"Do problem 2.3 b & c and provide the solutions using Latex in the solution cell. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Solution 4\n",
"\n",
"$$\\begin{aligned}\n",
" A\\vee (B\\wedge C) &\\iff (A\\wedge B) \\vee (A\\wedge C) \\\\ \n",
" &\\iff (A\\wedge B) \\vee (A\\wedge C) \\\\\n",
" &\\iff (A\\wedge B) \\vee (A\\wedge C) \\\\ \n",
" \\end{aligned}$$"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Problem 5 (50 points)\n",
"\n",
"Do problem 2.5 in Python and demonstrate your program on the three formulae in problem 2.4. As part of this\n",
"process, you will need to convert these three formulae to conjunctive normal form by hand. You do NOT need to\n",
"write code to do this, but simply create the CNFs to input to your code to determine if they\n",
"are unsatisfiable, satisfiable, or true/valid. \n",
"\n",
"Hint: It is a little messy to represent literals as strings, so a simple encoding\n",
"could be to consider $\\Sigma=\\{A_1, A_2, A_3, \\ldots \\}$ and represent literals\n",
"using just the subscript, with a negative literal being -1 * subscript.\n",
"Thus, if your propositions are `gas_in_tank` and `car_starts` you could\n",
"use the encodings:\n",
"\n",
"1 = gas_in_tank \n",
"2 = car_starts \n",
"-1 = $\\neg$ gas_in_tank \n",
"-2 = $\\neg$ car_starts\n",
"\n",
"The simplest representation of an interpretation/model in Python is simply a list of\n",
"Boolean values, e.g., \n",
"\n",
"$$[True,False,False,True] \\quad = \\quad \\{A_1\\mapsto t, A_2\\mapsto f,A_3\\mapsto f,A_4\\mapsto t\\}.$$\n",
"\n",
"Feel free to use another encoding if you have a better one!"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Solution 5\n",
"\n",
"def evalLiteral(I,L):\n",
" pass\n",
"\n",
"def evalClause(I,C):\n",
" pass\n",
"\n",
"def evalCNF(I,A):\n",
" pass\n",
"\n",
"all( [True,True,True] )"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[(1, 1, 1),\n",
" (1, 1, 0),\n",
" (1, 0, 1),\n",
" (1, 0, 0),\n",
" (0, 1, 1),\n",
" (0, 1, 0),\n",
" (0, 0, 1),\n",
" (0, 0, 0)]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from itertools import product\n",
"\n",
"\n",
"list(product([1,0],repeat=3))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}