-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtenpprm.py
54 lines (45 loc) · 1.69 KB
/
tenpprm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def tensor_product(v1, v2):
"""
Compute the tensor product of two binary vectors.
Parameters:
v1 (list): The first binary vector.
v2 (list): The second binary vector.
Returns:
list: The tensor product of the two binary vectors.
"""
def simplify_product(term1, term2):
"""Simplify the product of two terms by removing duplicates."""
combined = set(term1) | set(term2) # Combine terms and remove duplicates
return ''.join(sorted(combined)) # Return the sorted string representation
result = []
for elem1 in v1:
for elem2 in v2:
if elem1 == '0' or elem2 == '0':
result.append('0')
elif elem1 == '1':
result.append(elem2)
elif elem2 == '1':
result.append(elem1)
else:
result.append(simplify_product(elem1, elem2))
return result
def generate_pprm_expansions(n):
"""
Generate PPRM expansions for n binary variables.
Parameters:
n (int): Number of binary variables.
Returns:
list: The PPRM expansions in lexicographical order.
"""
# Initialize with the first variable
expansions = ['1', chr(65 + n - 1)] # Start with ['1', 'C'] for n=3
# Iterate through remaining variables
for i in range(n - 2, -1, -1): # Start from 'B' (65 + n - 2) down to 'A'
current_var = chr(65 + i)
expansions = tensor_product(['1', current_var], expansions)
return expansions
if __name__ == "__main__":
# Example usage:
n = 3 # Number of binary variables
pprm_expansions = generate_pprm_expansions(n)
print(pprm_expansions)