summaryrefslogtreecommitdiff
path: root/Discrete_Mathematics_and_its_Applications_by_Kenneth_H.Rosen/chapter1.ipynb
blob: fe652a17c66667e1a3cd5ff0f8702825fc62dc84 (plain)
1
{"nbformat_minor": 0, "cells": [{"source": "#Chapter 01: The Foundations: Logic and Proofs\n", "cell_type": "markdown", "metadata": {}}, {"source": "##Example 01:Page 02", "cell_type": "markdown", "metadata": {}}, {"execution_count": 1, "cell_type": "code", "source": "print \"The following sentences are Propositions\" #Proposition should be a declarative sentence or should result in either a YES or a NO.\n\nprint \"1.  Washington D.C is the capital of the United States of America\\n2.  Toronto is the capital of Canada\\n3.  1+1=2.\\n4.  2+2=3.\" #Since these statements are declarative and they answer the question YES or NO they are called propositions.\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "The following sentences are Propositions\n1.  Washington D.C is the capital of the United States of America\n2.  Toronto is the capital of Canada\n3.  1+1=2.\n4.  2+2=3.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "#Chapter 01: The Foundations: Logic and Proofs", "cell_type": "markdown", "metadata": {}}, {"source": "##Example 02:Page 02", "cell_type": "markdown", "metadata": {}}, {"execution_count": 2, "cell_type": "code", "source": "print \"1.  What time is it? \\n2.  Read this carefully. \\n3.  x+1=2.\\n4.  x+y=Z.\"\nprint\"Sentences 1 and 2 are not propositions since they are not declarative.  Sentences 3 and 4 are neither true nor false and so they are not propositions.\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "1.  What time is it? \n2.  Read this carefully. \n3.  x+1=2.\n4.  x+y=Z.\nSentences 1 and 2 are not propositions since they are not declarative.  Sentences 3 and 4 are neither true nor false and so they are not propositions.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "#Chapter 01: The Foundations: Logic and Proofs", "cell_type": "markdown", "metadata": {}}, {"source": "##Example 03:Page 03", "cell_type": "markdown", "metadata": {}}, {"execution_count": 9, "cell_type": "code", "source": "print \"Propositon p=Michael's PC runs Linux.\"\nprint \"\\n Negation of p is ~p : It is not the case that Michael's PC runs Linux.\"\nprint \"\\n Negation of p is ~p : Michae's PC does not run.\"#Negation is opposite of the truth value of the proposition expressed with \"it is not the case that\" or with \"not\".\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Propositon p=Michael's PC runs Linux.\n\n Negation of p is ~p : It is not the case that Michael's PC runs Linux.\n\n Negation of p is ~p : Michae's PC does not run.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "#Chapter 01: The Foundations: Logic and Proofs", "cell_type": "markdown", "metadata": {}}, {"source": "##Example 04:Page 03", "cell_type": "markdown", "metadata": {}}, {"execution_count": 10, "cell_type": "code", "source": "print \"Let p=Vandana's smartphone has at least 32GB of memory.\"\nprint \"The negation of p is ( ~p ) :It is not the case that Vandana's smartphone has at least 32GB of memory.\"\nprint \"Or in simple English ( ~p ): Vandana's smartphone does not have at least 32GB of memory.\"\nprint \"Or even more simple as ( ~p ): Vandana's smartphone has less than 32GB of memory.\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Let p=Vandana's smartphone has at least 32GB of memory.\nThe negation of p is ( ~p ) :It is not the case that Vandana's smartphone has at least 32GB of memory.\nOr in simple English ( ~p ): Vandana's smartphone does not have at least 32GB of memory.\nOr even more simple as ( ~p ): Vandana's smartphone has less than 32GB of memory.\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "#Chapter 01: The Foundations: Logic and Proofs", "cell_type": "markdown", "metadata": {}}, {"source": "##Example 05:Page 04", "cell_type": "markdown", "metadata": {}}, {"execution_count": 11, "cell_type": "code", "source": "p=\"Rebecca's PC has more than 16GB free hard disk space\"\nq=\"The processor in Rebecca's PC runs faster than 1GHz\"\nprint \"Let p,q be two propositions\"\nprint \"Let p=\",p,\"\\n\",\"Let q=\",q\nprint \"Conjunction of p^q is : \"+p+\" and \"+q #conjunction combines two propositons with \"and\"\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Let p,q be two propositions\nLet p= Rebecca's PC has more than 16GB free hard disk space \nLet q= The processor in Rebecca's PC runs faster than 1GHz\nConjunction of p^q is : Rebecca's PC has more than 16GB free hard disk space and The processor in Rebecca's PC runs faster than 1GHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "#Chapter 01: The Foundations: Logic and Proofs", "cell_type": "markdown", "metadata": {}}, {"source": "##Example 06:Page 05", "cell_type": "markdown", "metadata": {}}, {"execution_count": 12, "cell_type": "code", "source": "p=\"Rebecca's PC has more than 16GB free hard disk space\"\nq=\"The processor in Rebecca's PC runs faster than 1GHz\"\nprint \"Let p,q be two propositions\"\nprint \"Let p=\",p,\"\\n\",\"Let q=\",q\nprint \"Disjunction of p\\/q is : \"+p+\" or \"+q #unavailability of cup symbol.  So \\/\n#Disjunction combines two propositons using OR \n\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Let p,q be two propositions\nLet p= Rebecca's PC has more than 16GB free hard disk space \nLet q= The processor in Rebecca's PC runs faster than 1GHz\nDisjunction of p\\/q is : Rebecca's PC has more than 16GB free hard disk space or The processor in Rebecca's PC runs faster than 1GHz\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "#Chapter 01: The Foundations: Logic and Proofs", "cell_type": "markdown", "metadata": {}}, {"source": "##Example 07:Page 07", "cell_type": "markdown", "metadata": {}}, {"execution_count": 14, "cell_type": "code", "source": "p=\"Maria learns discrete mathematics\"\nq=\"Maria will find a good job\"\nprint\"Let p=\",p,\"\\n\",\"Let q=\",q\nprint\"p->q is : \"+\"If \"+p+\" then \"+q #p->q p implies q means If P then Q.\nprint\"p->q is also expressed as :\",q,\" when \",p\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Let p= Maria learns discrete mathematics \nLet q= Maria will find a good job\np->q is : If Maria learns discrete mathematics then Maria will find a good job\np->q is also expressed as : Maria will find a good job  when  Maria learns discrete mathematics\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "#Chapter 01: The Foundations: Logic and Proofs", "cell_type": "markdown", "metadata": {"collapsed": true}}, {"source": "## Example 01:Page 37", "cell_type": "markdown", "metadata": {}}, {"execution_count": 15, "cell_type": "code", "source": "def p(x): #Function defined to check whether the given statements are true.\n    if(x>3):\n        print \"p(\",x,\") which is the statement\",x,\">3, is true\"\n    else:\n        print \"p(\",x,\") which is the statement\",x,\">3, is false\"\np(4)#Fuction call \np(2)\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "p( 4 ) which is the statement 4 >3, is true\np( 2 ) which is the statement 2 >3, is false\n"}], "metadata": {"collapsed": false, "trusted": true}}, {"source": "#Chapter 01: The Foundations: Logic and Proofs", "cell_type": "markdown", "metadata": {}}, {"source": "## Example 02:Page 38", "cell_type": "markdown", "metadata": {}}, {"execution_count": 17, "cell_type": "code", "source": "x1=\"CS1\" #Defining systems to check whether they are under attack through a function.\nx2=\"CS2\"\nx3=\"MATH1\"\ndef A(x):\n    if(x==\"CS1\"):                #Since cs1 and Math1 are the two computers under attack\n        print \"A(\",x,\") is true.\"\n    else:\n        if(x==\"MATH1\"):         #Since CS1 and MATH1 are the two computers under attack\n            print \"A(\",x,\") is true.\"\n        else:\n           print\"A(\",x,\") is false.\"\nprint \"Systems under attack are CS1 and MATH1.  The truth values for the same are calculated using functions.\"\nA(x1)#Function call \nA(x2)\nA(x3)\n", "outputs": [{"output_type": "stream", "name": "stdout", "text": "Systems under attack are CS1 and MATH1.  The truth values for the same are calculated using functions.\nA( CS1 ) is true.\nA( CS2 ) is false.\nA( MATH1 ) is true.\n"}], "metadata": {"collapsed": false, "trusted": true}}], "nbformat": 4, "metadata": {"kernelspec": {"display_name": "Python 2", "name": "python2", "language": "python"}, "language_info": {"mimetype": "text/x-python", "nbconvert_exporter": "python", "version": "2.7.9", "name": "python", "file_extension": ".py", "pygments_lexer": "ipython2", "codemirror_mode": {"version": 2, "name": "ipython"}}}}