Skip to content

Commit

Permalink
Edited basis() method for augmented Chow Ring (atom-free presentation)
Browse files Browse the repository at this point in the history
  • Loading branch information
25shriya committed Sep 18, 2024
1 parent 8b8ab5d commit 91a757a
Showing 1 changed file with 53 additions and 54 deletions.
107 changes: 53 additions & 54 deletions src/sage/matroids/chow_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,74 +178,76 @@ def basis(self):
"""
flats = [X for i in range(1, self._matroid.rank())
for X in self._matroid.flats(i)]
flats.append(frozenset())
flats_gen = self._ideal.flats_generator()
R = self._ideal.ring()
flats = sorted(flats, key=lambda X: (len(X), sorted(X)))
ranks = {F:self._matroid.rank(F) for F in flats}
monomial_basis = []
if self._augmented is True:
if self._presentation == 'fy':
flats.remove(frozenset())
flats.remove(frozenset()) #Non empty proper flats
max_powers = []
max_powers[0] = ranks[flats[0]]
for i in range(1, len(flats)):
max_powers = ranks[flats[i]] - ranks[flats[i-1]]
for combination in product(*(range(p) for p in max_powers)):
for combination in product(*(range(p) for p in max_powers)): #Generating combinations for all powers up to max_powers
expression = R.one()
for i in range(k):
expression *= flats_gen[subset[i]]**combination[i]
monomial_basis.append(expression)
max_powers.remove(ranks[flats[0]])
for combination in product(*(range(p) for p in max_powers)):
expression = flats_gen[flats[0]]**ranks[flats[0]]
for i in range(k):
for i in range(len(flats)):
expression *= flats_gen[subset[i]]**combination[i]
monomial_basis.append(expression)
if combination[0] == 0: #Generating combinations for all powers including first max_powers
expression *= flats_gen[subset[0]]**max_powers[0]
monomial_basis.append(expression)

elif self._presentation == 'atom-free': #all double equals need spacing
first_rank = self._matroid.rank(flats[len(flats) - 1])
reln = lambda p,q : p < q
P = Poset((flats, reln))
chains = P.chains()
def generate_combinations(current_combination, index, max_powers, x_dict):
# Base case: If index equals the length of max_powers, print the current combination
if index == len(max_powers):
expression_terms = [x_dict[i+1] if current_combination[i] == 1
else x_dict[i+1]**{current_combination[i]}
for i in range(len(current_combination)) if current_combination[i] != 0]
if expression_terms:
term = R.one()
for t in expression_terms:
term *= t
monomial_basis.append(term)
else:
monomial_basis.append(R.one())
return

# Recursive case: Iterate over the range for the current index
for power in range(max_powers[index]):
current_combination[index] = power
generate_combinations(current_combination, index + 1, max_powers, x_dict)

for chain in chains:
elif self._presentation == 'atom-free':
subsets = []
# Generate all subsets of the frozenset using combinations
for r in range(len(flats) + 1): # r is the size of the subset
subsets.extend(list(subset) for subset in combinations(flats, r))
for subset in subsets:
flag = True
sorted_list = sorted(subset, key=len)
for i in range (len(sorted_list)): #Taking only chains
if (i != 0) & (len(sorted_list[i]) == len(sorted_list[i-1])):
flag = False
break
if flag is True: #For every chain
max_powers = []
x_dict = dict()
for i, F in enumerate(chain):
if F == frozenset():
x_dict[i] = R.one()
k = len(subset)
for i in range(k-1):
if i == 0:
max_powers.append(ranks[subset[i]])
x_dict[subset[i]] = flats_gen[subset[i]]
else:
x_dict[i] = flats_gen[F]
ranks = [self._matroid.rank(F) for F in chain]
max_powers = [ranks[i-1] - ranks[i] for i in range(1, len(chain))]
k = len(chain)
current_combination = [0] * k
print(max_powers, k, x_dict, chain)
if sum(max_powers) == (first_rank + 1) and max_powers[len(chain) - 1] <= self._matroid.rank(chain[len(chain) - 1]):
generate_combinations(current_combination, 0, max_powers, x_dict)

max_powers.append(ranks[subset[i]] - ranks[subset[i-1]])
x_dict[subset[i]] = flats_gen[subset[i]]
x_dict[subset[k-1]] = flats_gen[subset[k-1]]
max_powers[k-1] = ranks[subset[k-1]]
first_rank = ranks[subset[0]] + 1
last_rank = ranks[subset[k-1]]
for combination in product(*(range(1, p) for p in max_powers)): #Generating combinations for all powers from 1 to max_powers
expression = R.one()
if sum(combination) == first_rank:
for i in range(k):
expression *= x_dict[subset[i]]**combination[i]
monomial_basis.append(expression)
max_powers.remove(last_rank)
for combination in product(*(range(1, p) for p in max_powers)): #Generating all combinations including 0 power and max_power for first flat
expression = R.one()
if sum(combination) == first_rank:
for i in range(len(combination)):
expression *= x_dict[subset[i]]**combination[i]
monomial_basis.append(expression)
else:
expression *= x_dict[subset[k-1]]**last_rank
if sum(combination) + last_rank == first_rank:
for i in range(k):
expression *= x_dict[subset[i]]**combination[i]
monomial_basis.append(expression)

else:
R = self._ideal.ring()
else:
flats.remove(frozenset()) #Non empty proper flats
subsets = []
# Generate all subsets of the frozenset using combinations
for r in range(len(flats) + 1): # r is the size of the subset
Expand All @@ -262,10 +264,7 @@ def generate_combinations(current_combination, index, max_powers, x_dict):
max_powers = []
x_dict = dict()
for i in range(len(subset)):
if subset[i] == frozenset():
max_powers.append(0)
x_dict[subset[i]] = 1
elif i == 0:
if i == 0:
max_powers.append(ranks[subset[i]])
x_dict[subset[i]] = flats_gen[subset[i]]
else:
Expand Down

0 comments on commit 91a757a

Please sign in to comment.