import math # Import math library
def R(t, alpha, lmbda ): # Survivor function in the Weibull distribution
   return math.exp(-((lmbda * t)**alpha))

MTTF	= 81 # Norwegian men
alpha	= 5  # Assumption, higher alpha gives lower standard deviation
t	= 64 # Current age of the man considered
x	= 100-t	# x is the number of years from now (t) to reach 100 years
lmbda	= math.gamma(1+1/alpha)/MTTF # Since the Weibull was specified in terms of alpha and MTTF, we need to calculate lambda
V       =(math.gamma(2/alpha+1)-(math.gamma(1/alpha+1))**2)/(lmbda**2) # Variance
SD	= math.sqrt(V) # Standard deviation
R_100	= R(100,alpha,lmbda) # Probability that a new born boy survives 100 years
R_t	= R(t,alpha,lmbda) # Probability that a new born boy survives t years 
R_x_t	= R(x+t,alpha,lmbda)/R(t,alpha,lmbda) # Probability that a man of age t will be more than 100 years
R_1_t	= R(1+t,alpha,lmbda)/R(t,alpha,lmbda) # Probability that a man of age t will survive another year
z_Dt	= alpha*lmbda**alpha*t**(alpha-1) # Probability that a man of age t will die next year (Dt=1)

print("Var(T) =",V)
print("SD(T) =",SD)
print("x = ",x)
print("R(100) =",R_100)
print("R(x|t) =",R_x_t)
print("R(1|t) =",R_1_t)
print("z(t)*Dt =",z_Dt)
