import sys,math

def surprisemultiple(myargs):
   assert len(myargs)==6
   newargs = {}
   newargs['w1'] = int(myargs[1])
   newargs['w2'] = int(myargs[2])
   newargs['joint'] = int(myargs[3])
   newargs['total'] = int(myargs[4])
   newargs['canned'] = int(myargs[5])
   prefix = "Pages that contain both words are"
   suffix = "we would expect if the two words were independent."
   if newargs['canned'] not in [1,2,3]:
      w1 = newargs['w1']
      w2 = newargs['w2']
      joint = newargs['joint']
      total = newargs['total']
   if newargs['canned']==1:
      w1 = 1000
      w2 = 1000
      joint = 1
      total = 1000000
   if newargs['canned']==2:
      w1 = 1000
      w2 = 1000
      joint = 0
      total = 1000000
   if newargs['canned']==3:
      w1 = 1000
      w2 = 1000
      joint = 1000
      total = 1000000
   smoother = 0.0001
   w1 += smoother
   w2 += smoother
   joint += smoother
   total += smoother
   print 'P(w1) = ',(w1/total)
   print 'P(w2) = ',(w2/total)
   print 'P(w1w2) = ',(joint/total)
   print 'P(w1)*P(w2) = ',(w1/total)*(w2/total)
   surprise = (joint/total)/((w1/total)*(w2/total))
   print
   print prefix
   if surprise>1.5:
      print 'MORE FREQUENT THAN'
   elif surprise<0.6:
      print 'LESS FREQUENT THAN'
   else:
      print 'ROUGHLY AS FREQUENT AS'
   print suffix
   print
   print 'surprise',surprise
   print 'log 10 surprise',math.log10(surprise)
   print

surprisemultiple(sys.argv)
