# Chapter 01: The Foundations: Logic and Proofs¶

## Example 01:Page 02¶

In [1]:
print "The following sentences are Propositions" #Proposition should be a declarative sentence or should result in either a YES or a NO.

print "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.

The following sentences are Propositions
1.  Washington D.C is the capital of the United States of America
2.  Toronto is the capital of Canada
3.  1+1=2.
4.  2+2=3.


## Example 02:Page 02¶

In [2]:
print "1.  What time is it? \n2.  Read this carefully. \n3.  x+1=2.\n4.  x+y=Z."
print"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."

1.  What time is it?
3.  x+1=2.
4.  x+y=Z.
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.


## Example 03:Page 03¶

In [9]:
print "Propositon p=Michael's PC runs Linux."
print "\n Negation of p is ~p : It is not the case that Michael's PC runs Linux."
print "\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".

Propositon p=Michael's PC runs Linux.

Negation of p is ~p : It is not the case that Michael's PC runs Linux.

Negation of p is ~p : Michae's PC does not run.


## Example 04:Page 03¶

In [10]:
print "Let p=Vandana's smartphone has at least 32GB of memory."
print "The negation of p is ( ~p ) :It is not the case that Vandana's smartphone has at least 32GB of memory."
print "Or in simple English ( ~p ): Vandana's smartphone does not have at least 32GB of memory."
print "Or even more simple as ( ~p ): Vandana's smartphone has less than 32GB of memory."

Let p=Vandana's smartphone has at least 32GB of memory.
The negation of p is ( ~p ) :It is not the case that Vandana's smartphone has at least 32GB of memory.
Or in simple English ( ~p ): Vandana's smartphone does not have at least 32GB of memory.
Or even more simple as ( ~p ): Vandana's smartphone has less than 32GB of memory.


## Example 05:Page 04¶

In [11]:
p="Rebecca's PC has more than 16GB free hard disk space"
q="The processor in Rebecca's PC runs faster than 1GHz"
print "Let p,q be two propositions"
print "Let p=",p,"\n","Let q=",q
print "Conjunction of p^q is : "+p+" and "+q #conjunction combines two propositons with "and"

Let p,q be two propositions
Let p= Rebecca's PC has more than 16GB free hard disk space
Let q= The processor in Rebecca's PC runs faster than 1GHz
Conjunction 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


## Example 06:Page 05¶

In [12]:
p="Rebecca's PC has more than 16GB free hard disk space"
q="The processor in Rebecca's PC runs faster than 1GHz"
print "Let p,q be two propositions"
print "Let p=",p,"\n","Let q=",q
print "Disjunction of p\/q is : "+p+" or "+q #unavailability of cup symbol.  So \/
#Disjunction combines two propositons using OR

Let p,q be two propositions
Let p= Rebecca's PC has more than 16GB free hard disk space
Let q= The processor in Rebecca's PC runs faster than 1GHz
Disjunction 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


## Example 07:Page 07¶

In [14]:
p="Maria learns discrete mathematics"
q="Maria will find a good job"
print"Let p=",p,"\n","Let q=",q
print"p->q is : "+"If "+p+" then "+q #p->q p implies q means If P then Q.
print"p->q is also expressed as :",q," when ",p

Let p= Maria learns discrete mathematics
Let q= Maria will find a good job
p->q is : If Maria learns discrete mathematics then Maria will find a good job
p->q is also expressed as : Maria will find a good job  when  Maria learns discrete mathematics


## Example 01:Page 37¶

In [15]:
def p(x): #Function defined to check whether the given statements are true.
if(x>3):
print "p(",x,") which is the statement",x,">3, is true"
else:
print "p(",x,") which is the statement",x,">3, is false"
p(4)#Fuction call
p(2)

p( 4 ) which is the statement 4 >3, is true
p( 2 ) which is the statement 2 >3, is false


## Example 02:Page 38¶

In [17]:
x1="CS1" #Defining systems to check whether they are under attack through a function.
x2="CS2"
x3="MATH1"
def A(x):
if(x=="CS1"):                #Since cs1 and Math1 are the two computers under attack
print "A(",x,") is true."
else:
if(x=="MATH1"):         #Since CS1 and MATH1 are the two computers under attack
print "A(",x,") is true."
else:
print"A(",x,") is false."
print "Systems under attack are CS1 and MATH1.  The truth values for the same are calculated using functions."
A(x1)#Function call
A(x2)
A(x3)

Systems under attack are CS1 and MATH1.  The truth values for the same are calculated using functions.
A( CS1 ) is true.
A( CS2 ) is false.
A( MATH1 ) is true.