This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import matplotlib.pyplot as plt | |
import sys | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument("--nqubit", required=False, help="number of qubits", type=int) | |
parser.add_argument("--precision", required=False, default=32, type=int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/questions/10244180/python-generating-integer-partitions (checked) | |
def accelAsc(n): | |
a = [0 for i in range(n + 1)] | |
k = 1 | |
a[0] = 0 | |
y = n - 1 | |
while k != 0: | |
x = a[k - 1] + 1 | |
k -= 1 | |
while 2*x <= y: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def stirling_second(x,n): | |
if n <= 1 or x == n: return 1 | |
if n > x or x <= 0: return 0 | |
return stirling_second(x-1, n-1) + n * stirling_second(x-1, n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
def comp_enum ( x, n ): | |
#******************************************************************************/ | |
# | |
## COMP_ENUM returns the number of compositions of the integer x into n parts. | |
# | |
# Discussion: | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
def i4_choose ( x, n ): | |
#***************************************************************************** | |
# | |
## I4_CHOOSE computes the binomial coefficient C(x,n) as an I4. | |
# | |
# Discussion: | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import factorial | |
x=10 | |
n=3 | |
res = math.factorial(x+n-1) / ( math.factorial(n) * math.factorial(x+n-1-n)) | |
>>> len([i for i in itertools.combinations_with_replacement(range(0,x), n)]) == res | |
True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@memo # can be memoized, otherwise comment this line | |
def stirling1(n,k): | |
"""Returns the stirling number of the first kind using recursion..""" | |
if n == 0 and k == 0: | |
return 1 | |
if k == 0 and n >= 1: | |
return 0 | |
if k > n: | |
return 0 | |
return stirling1(n-1, k-1) - (n - 1) * stirling1(n-1, k) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
s="ABCD" | |
rep=3 | |
a = [i for i in itertools.combinations(s, rep)] | |
len(a) == math.factorial(len(s)) / (math.factorial(rep) * math.factorial(len(s)-rep)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> s="ABCD" | |
>>> repetition=3 | |
>>> a = [i for i in itertools.permutations(s, repetition)] | |
>>> len(a) == math.factorial(len(s)) / math.factorial(len(s)-repetition) | |
True | |
def sample_function(n=0, s=set() ): | |
f = {} | |
for i in range(0, n): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> x = len("ABCDEF") # x= 6, | |
>>> n=3 | |
>>> for i in product("ABCDEF", repeat=n): | |
... print(i) | |
('A', 'A', 'A') | |
... | |
('F', 'F', 'F') | |
>>> len( [i for i in product("ABCDEF", repeat=n)] ) == x**n |
NewerOlder