def check():
   """performs some checks according to problem 3/1d and 3/1e
   """
   import numpy as np

# uniformly distributed sample  
   n=10001
   rand_orig=np.random.uniform(size=n)

# exponentially distributed sample
   rand=-np.log(rand_orig)
   randexp=rand

# problem 1d
   frand=1.+np.sin(rand)
   print('mean(f) = ',np.mean(frand))

# problem 1e 
# transformation property of median
   print() 
   print('complete sample')
   xmed=np.median(rand)
   xmedexp=xmed
   print('x_0.5 = ',xmed)
   print('f_0.5 = ',np.median(frand))
   print('f(x_0.5)',1.+np.sin(xmed))

   
   b=np.where(rand < 1.)
   rand=rand[b]
   frand=frand[b]

   print()
   print('sample with x < 1')
   xmed=np.median(rand)
   print('x_0.5 = ',xmed)
   print('f_0.5 = ',np.median(frand))
   print('f(x_0.5)',1.+np.sin(xmed))
   
# exponentially distributed sample within [0,1), normalized   
   rand=-np.log(1.-rand_orig*(1.-np.exp(-1.)))
   frand=1.+np.sin(rand)
   print()
   print('sample with x < 1 (normalized)')
   print('median will be different, since now larger sample than above')
   print('(all values are now lower than 1)')

   xmed=np.median(rand)
   print('x_0.5 = ',xmed)
   print('f_0.5 = ',np.median(frand))
   print('f(x_0.5)',1.+np.sin(xmed))   

# mean abs deviation
   print()
   print('complete sample')
   meanabsdev=sum(abs(randexp-xmedexp))/float(n)
   print('meanabsdev = ',meanabsdev)

   randexp=np.sort(randexp)
   print('complete sample (sorted)')
   print('      i      variate         median          meanabsdev1      meanabsdev(median)   difference')

   
   for i in range(4995,5005):
     meanabsdev1=sum(abs(randexp-randexp[i]))/float(n)
     print(i,randexp[i],xmedexp,meanabsdev1,meanabsdev,meanabsdev1-meanabsdev)
     
     
   av=np.mean(randexp)
   print(av)
   stdev=sum((randexp-av)**2)/float(n)
   print()
   print('median =      ',xmedexp,'   mean =  ',av,' (exact value = 1)')
   print('meanabsdev = ',meanabsdev,' stdev = ',stdev,' (exact value = 1)')
     
     
