Skip to content

Instantly share code, notes, and snippets.

@texadactyl
Last active December 24, 2019 00:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save texadactyl/4d48ff60a6e7bb42a19f to your computer and use it in GitHub Desktop.
Save texadactyl/4d48ff60a6e7bb42a19f to your computer and use it in GitHub Desktop.
import sys
import decimal
from math import factorial
usage = "\nUsage: python ntaxa.py {# of taxa}\n"
if __name__ == '__main__':
ntaxa = 0
if len(sys.argv) == 2:
ntaxa = int( sys.argv[1] )
if ntaxa < 2:
print("%s" % usage)
sys.exit(86)
else:
print("%s" % usage)
sys.exit(86)
d2 = decimal.Decimal( 2.0 )
d3 = decimal.Decimal( 3.0 )
d5 = decimal.Decimal( 5.0 )
dn = decimal.Decimal( ntaxa )
ctx = decimal.getcontext()
ctx.prec = 8
print("Parameters: ntaxa=%s" % (dn))
A = factorial( ( d2 * dn ) - d3 )
B = ctx.power( d2, ( dn - d2 ) )
C = factorial( dn - d2 )
result = A / ( B * C )
print("# of rooted trees = %s" % result)
A = factorial( ( d2 * dn ) - d5 )
B = ctx.power( d2, ( dn - d3 ) )
C = factorial( dn - d3 )
result = A / ( B * C )
print("# of unrooted trees = %s" % result)
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment