{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter1 - Set Theory"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex1.7 Pg 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "To find : number of mathematics students taking atleast one of the languages French(F),German(G) and Russian(R)\n",
      "the number of students studying atleast one of the languages : 100\n"
     ]
    }
   ],
   "source": [
    "print 'To find : number of mathematics students taking atleast one of the languages French(F),German(G) and Russian(R)'\n",
    "F=65# #number of students studying French\n",
    "G=45#  # number of students studying German\n",
    "R=42#  #number of students studying Russian\n",
    "FandG=20#  #number of students studying French and German\n",
    "FandR=25#  #number of students studying French and Russian\n",
    "GandR=15#   #number of students studying German and Russian\n",
    "FandGandR=8# #number of students studying French,German and Russian\n",
    "#By inclusion-exclusion principle\n",
    "ForGorR=F+G+R-FandG-FandR-GandR+FandGandR#\n",
    "print 'the number of students studying atleast one of the languages :',ForGorR\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex1.8 Pg 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In a college, 120 mathematics students can opt for either French(F),German(G) or Russian(R)\n",
      "using inclusion-exclusion principle:\n",
      "number of students studying French or German or Russian 100\n",
      "number of students studying French and German but not Russian 12\n",
      "number of students studying French and Russian but not German 17\n",
      "number of students studying German and Russian but not French 7\n",
      "number of students studying  Only French 28\n",
      "number of students studying  Only German 18\n",
      "number of students studying  Only Russian 10\n",
      "number of students not studying any of the languages 20\n"
     ]
    }
   ],
   "source": [
    "print 'In a college, 120 mathematics students can opt for either French(F),German(G) or Russian(R)'\n",
    "n=120#  #total number of students\n",
    "F=65#  #number of students studying French\n",
    "G=45#  #number of students studying German\n",
    "R=42#  #number of students studying Russian\n",
    "FandG=20#  #number of students studying French and German\n",
    "FandR=25#  #number of students studying French and Russian\n",
    "GandR=15#  #number of students studying German and Russian\n",
    "FandGandR=8#  #number of students studying French,German and Russian\n",
    "print 'using inclusion-exclusion principle:'\n",
    "ForGorR=F+G+R-FandG-FandR-GandR+FandGandR# \n",
    "print 'number of students studying French or German or Russian',ForGorR\n",
    "FGnR=FandG-FandGandR#  \n",
    "print 'number of students studying French and German but not Russian',FGnR\n",
    "FRnG=FandR-FandGandR #\n",
    "print 'number of students studying French and Russian but not German',FRnG\n",
    "GRnF=GandR-FandGandR # \n",
    "print 'number of students studying German and Russian but not French',GRnF\n",
    "OF=F-FGnR-FandGandR-FRnG # \n",
    "print 'number of students studying  Only French',OF\n",
    "OG=G-FGnR-FandGandR-GRnF#  \n",
    "print 'number of students studying  Only German',OG\n",
    "OR=R-FRnG-FandGandR-GRnF#  \n",
    "print 'number of students studying  Only Russian',OR\n",
    "k=n-ForGorR# \n",
    "print 'number of students not studying any of the languages',k\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex1.13 Pg 12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of members of powerset P which are proper subsets of x are: 1023\n"
     ]
    }
   ],
   "source": [
    "x=10# #number of members of set X\n",
    "P=2**x #number of members of the power set of X\n",
    "q=P-1##x itself is not the proper subset.Hence it isn't counted\n",
    "print 'number of members of powerset P which are proper subsets of x are:',q"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex1.14 Pg 12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of different salads that can be prepared using the given eatables 31\n"
     ]
    }
   ],
   "source": [
    "A=[1,2,3,4,5]#  #eatables for salad preparation 1=onion,2=tomato,3=carrot,4=cabbage,5=cucumber\n",
    "p=len(A)#   #total number of eatables available  \n",
    "n=2**p-1#  #no salad can be made without atleast one of the eatables.Hence null set isn't counted\n",
    "print 'number of different salads that can be prepared using the given eatables',n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex1.18 Pg 13"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "P(1) 1\n",
      "P(2) 5\n",
      "P(1)=U(1) and P(2)=U(2)\n",
      "hence Un=3**n-2**n for all n belonging to N\n"
     ]
    }
   ],
   "source": [
    "U1=1#  #given\n",
    "U2=5#  #given\n",
    "P=[]#\n",
    "for I in range(0,2):\n",
    "    i=I+1\n",
    "    P.append(3**i-2**i)\n",
    "    print \"P(%s)\"%(i),P[I]\n",
    "print 'P(1)=U(1) and P(2)=U(2)'#\n",
    "print 'hence Un=3**n-2**n for all n belonging to N'"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
