From 0f04cc5136822c9554befff23d2b05cad1ae0d3b Mon Sep 17 00:00:00 2001 From: SEK1RO Date: Sun, 11 Jan 2026 16:11:40 +0300 Subject: [PATCH] movs: basis --- circuit/25-1/basis/index.html | 22 ++++++ circuit/25-1/basis/index.js | 138 ++++++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 circuit/25-1/basis/index.html create mode 100644 circuit/25-1/basis/index.js diff --git a/circuit/25-1/basis/index.html b/circuit/25-1/basis/index.html new file mode 100644 index 0000000..73a48a0 --- /dev/null +++ b/circuit/25-1/basis/index.html @@ -0,0 +1,22 @@ + + + + + Document + + + +
+ + + + diff --git a/circuit/25-1/basis/index.js b/circuit/25-1/basis/index.js new file mode 100644 index 0000000..6eaabcd --- /dev/null +++ b/circuit/25-1/basis/index.js @@ -0,0 +1,138 @@ +const app = document.getElementById('app') +const func_names = ['константа 0', 'и', 'левая коимпликация', 'X', 'правая коимпликация', 'Y', 'исключающее или', 'или', 'стрелка пирса', 'эквивалентность', 'не Y', 'правая импликация', 'не X', 'левая импликация', 'штрих шеффера', 'константа 1'] + +function getTerm(num) { + return [num >> 3, num >> 2 & 1, num >> 1 & 1, num & 1] +} + +function getName(num) { + return 'F' + num + ' - ' + func_names[num] +} + +function isT0(num) { + const term = getTerm(num) + return term[0] == 0 +} + +function isT1(num) { + const term = getTerm(num) + return term[3] == 1 +} + +function isL(num) { + const term = getTerm(num) + return (term[0] ^ term[1] ^ term[2] ^ term[3]) == 0 +} + +function isM(num) { + const term = getTerm(num) + return term[0] <= term[1] && term[1] <= term[2] && term[2] <= term[3] +} + +function isS(num) { + const term = getTerm(num) + return term[0] == !term[3] && term[1] == !term[2] +} + +const row_func = [isT0, isT1, isL, isM, isS] +const table = document.createElement('table') +table.innerHTML = 'ФункцияT0T1LMS' + +const bitclasses = [] + +for (let i = 0; i < 16; i++) { + bitclasses.push(0) + const tr = document.createElement('tr') + const td = document.createElement('td') + td.innerHTML = getName(i) + td.style.textAlign = 'left' + tr.appendChild(td) + + for (let j = 0; j < 5; j++) { + bitclasses[i] |= row_func[j](i) << j + const td = document.createElement('td') + td.innerText = row_func[j](i) ? '+' : '' + tr.appendChild(td) + } + + table.appendChild(tr) +} + +app.appendChild(table) + +function forEachSubset(arr, callback) { + for (let i = 0n; i < 2n ** BigInt(arr.length); i++) { + const subset = [] + let bitset = i + let pos = 0n + + while (bitset > 0n) { + if (bitset & 1n) { + subset.push(arr[pos]) + } + bitset >>= 1n + pos++ + } + + callback(subset) + } +} + +const indexes = new Array(16).fill(0) +indexes.forEach((v, i, a) => { a[i] = i }) + +const basis = [] +forEachSubset(indexes, (subset) => { + for (let skipped_i = 0; skipped_i < subset.length; skipped_i++) { + let bitclass = 2 ** 5 - 1 + + for (let i = 0; i < subset.length; i++) { + if (i == skipped_i) { + continue + } + + bitclass &= bitclasses[subset[i]] + } + if (bitclass == 0) { + return + } + } + + let bitclass = 2 ** 5 - 1 + + for (const index of subset) { + bitclass &= bitclasses[index] + } + if (bitclass != 0) { + return + } + + basis.push(subset) +}) + +basis.sort((a, b) => { return a.length - b.length }) +let len +let ul +basis.forEach((basis) => { + if (basis.length != len || ul === undefined) { + len = basis.length + + const h = document.createElement('h3') + h.innerText = 'Базисы размера ' + len + app.appendChild(h) + + ul = document.createElement('ul') + app.appendChild(ul) + } + + const li = document.createElement('li') + const inner_ul = document.createElement('ul') + + for (const index of basis) { + const inner_li = document.createElement('li') + inner_li.innerText = getName(index) + inner_ul.appendChild(inner_li) + } + li.appendChild(inner_ul) + ul.appendChild(li) +})