suppose we have a list like [x,y,z] and a number like 2. i need an algorithm to find all monomials with this 3 variable and degree=2
my algorithm:
def mul(x:list, y:list) -> list:
return ["".join(elm) for elm in product(x, y)]
def f(x:list, n:int) -> list:
r = x;
for i in range(n-1):
r = mul(r, x)
return r
>>> f(['x','y','z'],2)
['xx', 'xy', 'xz', 'yx', 'yy', 'yz', 'zx', 'zy', 'zz']
is there any better algorithm to do this?
EDIT:
1) suppose 'xz' != 'zx' 2) suppose 'xx' = 'x^2'