diff options
Diffstat (limited to 'lab4/lab4.py')
| -rw-r--r-- | lab4/lab4.py | 89 |
1 files changed, 55 insertions, 34 deletions
diff --git a/lab4/lab4.py b/lab4/lab4.py index b4c2e73..0f28157 100644 --- a/lab4/lab4.py +++ b/lab4/lab4.py @@ -70,22 +70,29 @@ def make_semigroup_binrel(): for _ in range(n): matrix.append(list(map(int, input().split()))) matrices[str(i + 1)] = np.array(matrix) - - combinations = [] - for i in range(1, q + 1): - combination = list(it.product(map(str, range(1, q + 1)), repeat=i)) - combinations.extend(combination) - - for combination in combinations: - matrix = matrices[combination[0]].copy() - word = combination[0] - for comb_i in range(1, len(combination)): - matrix *= matrices[combination[comb_i]] - word += combination[comb_i] - matrices[word] = matrix - find_correlation(matrices) + while True: + new_matrices = {} + for key_i, value_i in matrices.items(): + for key_j, value_j in matrices.items(): + new_matrices[key_i + key_j] = value_i * value_j + + already_exists = [] + for mat in new_matrices.values(): + flags = [] + for mat_old in matrices.values(): + flags.append(np.array_equal(mat, mat_old)) + already_exists.append(any(flags)) + if not any(flags): + break + + if all(already_exists): + break + matrices.update(new_matrices) + + find_correlation(matrices) + def make_semigroup(): print("Введите элементы полугруппы:") @@ -101,28 +108,42 @@ def make_semigroup(): print(f"Введите значения преобразования '{generators_list[i]}' " "элементов полугруппы:") print(*elements) - translations.append(input().split()) + translations.append((generators_list[i], input().split())) - combinations = [] - for i in range(1, gn + 1): - combinations.extend(it.product(''.join(generators_list), repeat=i)) + copresentation = translations.copy() + correlations = {} + while True: + is_inserted = False + for key_i, value_i in translations: + for key_j, value_j in copresentation: + new_word = key_i + key_j + + new_value = [] + for elem in value_i: + if elem == "*": + sec_sem = "*" + else: + sec_sem = value_j[int(elem) - 1] + new_value.append(sec_sem) + + find_corr = False + for k, v in copresentation: + if np.array_equal(new_value, v): + correlations[new_word] = k + find_corr = True + if not find_corr: + copresentation.append((new_word, new_value)) + is_inserted = True + if not is_inserted: + break - result = {} - for combination in combinations: - correlation = [] - for i in elements: - element = i - for generator in combination: - if element not in elements: - element = '*' - else: - gi = generators_list.index(generator) - si = elements.index(element) - element = translations[gi][si] - correlation.append(element) - result[combination] = correlation - - find_correlation(result) + print("Копредставление: ") + for key, value in copresentation: + print(key + ":", value) + + print("Полученные соотношения: ") + for key, value in correlations.items(): + print(key, "->", value) def main(): |