From e9319f8888b375dc0007d4825ced306fa14a8f89 Mon Sep 17 00:00:00 2001 From: Andrew Guschin Date: Sun, 1 May 2022 00:07:32 +0400 Subject: =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=87=D0=B5=D1=80=D0=B2=D1=91=D1=80=D1=82=D0=BE?= =?UTF-8?q?=D0=B9=20=D0=BB=D0=B0=D0=B1=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab4/lab4.py | 89 +++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 55 insertions(+), 34 deletions(-) (limited to 'lab4/lab4.py') 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(): -- cgit v1.2.3