#! /usr/bin/env python """ Module MyStuff is a collection of useful functions which are user defined, stored locally at $HOME/python/mymodules/mystuff.py where the mymodules directory has been added to the $PYTHONPATH environment. Symbols: 'm' is positive integer 'n' is a positive integet such that n >= m >= 0 Paul Eugenio Florida State University Department of Physics Jan 2019 """ from __future__ import division, print_function import sys from math import factorial def binomial(n, k): """ Binomial coefficient (n k) = n!/(k!(n-k)! """ return ( factorial(n) // (factorial(k)*factorial(n-k)) ) def lobb_number(m, n): """ Lobb numbers form a natural generalization of the Catalan numbers, Catalan recursive function defined via integer arithmetic Lobb numbers L_n,n = 1 & Lobb_),n = 1/(1+n) Bionomial(2n, n) """ return binomial(2*n, m+n )* (2*m+1) // (m+n+1) def test_functions(): """ Routines to test module functions. To execute test of function run module as python program along with commandline argument "test" example: "mypython test" """ # test catalan function if( lobb_number(1, 3) == 9 ): print("Module is Good") else: print("WARNING!!!\n catalan() function failed test\n DO NOT USE!!!") # # main # if __name__ == '__main__': # the test block if len(sys.argv) == 2 and sys.argv[1] == 'test': test_functions()