#๐ Algebra algorithm
12 messages ยท Page 1 of 1 (latest)
@trim carbon
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
import numpy
from itertools import combinations
from itertools import permutations
n = int(input())
p = 1
# formula for calculating number of bases of vector space Z2^2 over Z2
# for the first vector we have 2^n - 1 options (it can't be null)
# for the second vector we have 2^n - 2 options (it can't be null or the same as the first)
# for the third vector we have 2^n - 2^2 options (it can't be null or a linear combination of the first two)
# and so on
for i in range(n):
p = p * (2 ** n - 2 ** i)
print("1)", p)
if n == 1:
print("2) (1)")
elif n <= 4:
print("2)")
vector_list = []
bases = []
# generating the initial vectors using bit operations
for i in range(2 ** n):
vector = [(i >> j) & 1 for j in range(n)]
vector_list.append(tuple(vector))
count = 1
for combination in combinations(vector_list, n): # we get every combination of the initial vectors
matrix = numpy.array(combination)
if numpy.linalg.matrix_rank(
matrix) == n: # we check it's linear independency by calculating the rank of the matrix formed by those vectors
for permutation in permutations(combination): # we print every permutation of a valid basis
print(f"{count}:", permutation)
count += 1
if n == 4:
print("1)", p) # it may not show at the start because of the huge number of vectors
here is the code
and
for n = 3
it should give me 168 vectors but it gives me 174
Pastebin
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
here is the list
should i verify something else?
@trim carbon
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.