Files
lab/5/схемотехника/basis.html
2026-02-17 23:13:20 +03:00

169 lines
4.3 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
th,
td {
padding: 0;
margin: 0;
border: 1px solid black;
min-width: 20px;
text-align: center;
}
table {
border-collapse: collapse;
}
</style>
</head>
<body>
<div id="app"></div>
<script>
const app = document.getElementById('app')
const func_names = ['константа 0', 'и', 'левая коимпликация', 'экв. x', 'правая коимпликация', 'экв. y', 'исключающее или', 'или', 'стрелка пирса', 'эквивалентность', 'не y', 'правая импликация', 'не x', 'левая импликация', 'штрих шеффера', 'константа 1']
const func_syms = ['0', 'x∧y', 'x↛y', 'x', 'x↚y', 'y', 'x⊕y', 'xy', 'x↓y', 'x=y', '¬y', 'x←y', '¬x', 'x→y', 'x|y', '1']
function getTerm(num) {
return [num >> 3, num >> 2 & 1, num >> 1 & 1, num & 1]
}
function getName(num) {
return func_syms[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[0] <= term[2] && term[1] <= term[3] && 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 = '<tr><th>Функция</th><th>T0</th><th>T1</th><th>L</th><th>M</th><th>S</th></tr>'
const bitclasses = []
for (let i = 0; i < 16; i++) {
bitclasses.push(0)
const tr = document.createElement('tr')
const td = document.createElement('td')
td.innerHTML = 'F' + i + ' : ' + 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)
})
</script>
</body>
</html>