Algorithmadvanced
NOVA state encoding
Also called NOVA, Villa-Sangiovanni-Vincentelli encoding.
Villa and Sangiovanni-Vincentelli's state encoder that satisfies as many face embedding constraints from symbolic minimization as possible to give a small two-level controller.
- Solves
- State assignment
- Time
- O(T + G^2 n 2^(k n)) worst
- Space
- O(n G + 2^k) extra
- Where
- G = the number of face constraints; T = the time of the symbolic two-level minimization; k = the code length (the least that holds n codes); n = the number of states
- Model
- Word RAM
- Properties
- deterministicnot exactofflineiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Tiziano Villa, Alberto L. Sangiovanni Vincentelli, 1990
NOVA is a method of state assignment for two-level logic that keeps the number of state bits fixed. Like KISS, it starts from a symbolic minimization of the state table, whose product terms give face constraints: groups of states whose codes should span a face of the code cube that holds no other code. KISS lengthens the code until every constraint is met. NOVA instead fixes the code at the least length, usually bits for states, and meets as many constraints as it can, giving more weight to the groups that more product terms use. Villa and Sangiovanni-Vincentelli published it in 1990. This page proves the bound that makes the idea work, a count of product terms that charges each unmet group the number of cubes it needs. It also shows by exhaustive search that NOVA is not optimal for the final logic: the codes that meet the most weight can differ from each other by several product terms.
In plain words
KISS asks for codes in which every merged group of states can be named by one pattern with some bits left free, and it adds bits until that works. Extra bits mean extra flip-flops. NOVA keeps the fewest bits and accepts that some groups will need two or more patterns. It ranks the groups by how many rows of the merged table use them, and walks down the list, keeping a group whenever the groups kept so far and the new one can still all be given single patterns. Then it picks codes that give every kept group one pattern.
The problem
The input is a reduced finite state machine with states, as on the KISS page, and the output is an injective code of bits, with fixed in advance. The aim is a small minimum two-level cover of the encoded next-state and output functions, with unused codes as don't cares.
Weights. Let be a minimum symbolic cover. For a group of present states with , its weight is the number of cubes of whose group is .
Cube count of a group. For a code and a group , let be the least number of subcubes of whose union holds every code of and no code of a state outside ; unused codes may lie in them or not. If meets the face constraint of , then ; otherwise .
The algorithm
NOVA(M)- 1
S_cover ← a minimum symbolic cover of M, as in KISS - 2
for each group G of S_cover with 1 < |G| < n do w(G) ← the number of cubes of S_cover whose group is G - 3
order the groups by decreasing w(G), then by increasing size, then by first appearance in S_cover - 4
k ← ⌈log2 n⌉; kept ← empty; dropped ← empty - 5
for each group G in that order do - 6
if some injective code of k bits meets every face constraint in kept and G then add G to kept - 7
else add G to dropped - 8
return an injective code of k bits that meets every face constraint in kept
The test of line L6 is the face embedding problem at a fixed length. The reference code answers it by backtracking over all codes, which fits only small machines. Villa and Sangiovanni-Vincentelli's program offers several algorithms for this step, exact ones and heuristics, and options that this sketch leaves out; the version here keeps only the greedy rule of lines L5 to L7, with the weights of line L2. It is a simplified form of NOVA, not a transcription of the paper.
The bound behind the weights. For any injective code, the encoded function has a two-level cover with at most
cubes, where is the group of cube (proved in the full proof). A met group adds to this sum and an unmet group adds , so the sum is at least plus the weight of the unmet groups. Keeping heavy groups lowers this lower part of the bound. It does not control of the dropped groups, and it says nothing about the minimum cover itself, which can be much smaller than the bound.
Example
Take the machine with one input , one output and four states:
| present | ||
|---|---|---|
| / 1 | / 1 | |
| / 1 | / 1 | |
| / 0 | / 1 | |
| / 1 | / 0 |
A minimum symbolic cover has 7 cubes:
| cube | group | next | ||
|---|---|---|---|---|
| 1 | - | 1 | ||
| 2 | 1 | 1 | ||
| 3 | - | |||
| 4 | 0 | 1 | ||
| 5 | 0 | 1 | ||
| 6 | 1 | |||
| 7 | 1 | 1 |
The groups , and each have weight 1, and line L3 orders them by size. With , the first two can be met together, but not with the third: three codes span a face of two bits only if that face is the whole square, which holds the fourth code. So NOVA keeps and , drops , and returns , , , . The dropped group needs two cubes, and , so the bound is cubes. An exact minimization of the encoded function under these codes gives 5 cubes and 10 literals.
An exhaustive search over the 12 classes of two-bit codes (24 codes up to swapping the bits) gives a best cover of 4 cubes and 9 literals, with , , , . These codes meet the same two constraints as NOVA's codes. In fact 8 of the 12 classes meet both of them, so all 8 have the same total weight in NOVA's sense, and their exact covers range from 4 to 6 cubes. NOVA has no way to tell them apart, and its choice gives 5.
KISS meets all three groups by going to three bits, with codes , , , ; its encoded cover has 7 cubes, which an exact minimization reduces to 5 cubes and 9 literals. So on this machine KISS spends one more flip-flop for no fewer product terms than NOVA, and both miss the best two-bit code.
Correctness
The full proof shows:
- Valid codes. The returned code is injective and meets every face constraint in kept, since line L6 adds a group only when such a code exists, and line L8 returns one.
- The bound. For any injective code, the encoded function has a cover with at most cubes. With every constraint met, this is the KISS bound.
- A maximal set. Every dropped group cannot be met together with the groups kept before it. So no group can be added to kept without dropping another.
What is not proved: that the kept set has the largest weight that any code can meet. A greedy choice gives no such guarantee in general, since a kept group can block later groups. What is false: that the codes minimize the final logic. As the example shows, codes of equal weight can differ by two cubes. As a measurement, on 100 random machines with 4 states, one input bit, one output bit and every entry specified (seed 1990), the kept weight equalled the largest weight that any two-bit code can meet on all 100, which says more about how few constraints such small machines have than about the greedy rule. The final logic matched the best two-bit code on 41 of the 100, with 71 extra cubes in total and at most 3 on one machine.
Proof: Correctness of the NOVA encoder and the cube count boundfull
We use the notation of the page and of the KISS proof. The machine has states, (at least 1), and is a correct minimum symbolic cover. Each cube of has an input part , a group of present states and a set of asserted outputs (next states and primary outputs ). A code is injective from the states to . It meets the face constraint of when the least subcube that holds the codes of holds no code of a state outside .
For a group , is the least number of subcubes of whose union holds every code of and no code of a state outside . It exists, since the single points , , form such a family, so .
Lemma 1 (met means one cube)
if and only if meets the face constraint of , or .
Proof. If the constraint is met, is one such cube. If , the point is one; if , the whole cube is one. Conversely, let one cube hold every code of and no code outside . Every cube that holds the codes of contains the least one, so , and holds no code outside either.
Theorem 1 (the cube count bound)
For every injective code, the encoded function has a correct two-level cover with at most cubes.
Proof. For each cube of , choose subcubes as in the definition of . Form the encoded cubes , each with the output part that the KISS construction gives : the next-state bits with for each state that asserts, and the primary outputs that asserts. Drop those whose output part is empty.
Take a specified pair , and let be the set of cubes of that contain it. An encoded cube from contains only if and for some . The second holds for some exactly when : if some holds , and if none does. So the cubes of that have an encoded cube at are exactly the cubes of , and every output part at that point is the union of the output parts of the cubes from . This is the situation of Lemma 1 of the KISS proof, and the argument of its theorem applies word for word: the next-state bits set at are the 1 bits of , and each primary output has the value it has in at . Points at unspecified pairs or at unused codes are don't cares. So the cover is correct, and it has at most cubes.
By Lemma 1, each met group contributes to the sum and each unmet group with contributes . When every group is met, the bound is , the KISS bound.
Theorem 2 (what the encoder returns)
Line L8 returns an injective code of bits that meets every group in kept. Every dropped group has the property that no injective code of bits meets every group in kept together with .
Proof. We show by induction over the loop that some injective code of bits meets every group in kept. At the start kept is empty, and an injective code exists because . Line L6 adds a group only when the test succeeds, so the property is kept. At line L8 the property holds, so a code exists, and the reference code finds one, since its backtracking tries every injective code and prunes only partial codes in which the face of the placed members of a group already holds the code of a placed state outside it; faces only grow as more members are placed, so a pruned partial code has no valid completion.
For the second claim, let be dropped, and let be the set kept before was tested. No code meets together with . The final kept set contains , and a code that meets a set of constraints meets every subset of it, so no code meets the final kept set together with .
So the kept set is maximal: every group of is either kept or dropped, and no dropped group can join it.
What is not proved
Nothing here bounds the weight of the kept set against the largest weight that any code of bits can meet; a greedy order gives no such guarantee in general, and the tests only measure it. Nothing here says that the returned code makes the final logic small. Theorem 1 is an upper bound for every code, and the codes that meet the same groups can differ in cost; the page shows a machine on which 8 classes of codes meet the same two groups and their minimum covers range from 4 to 6 cubes, found by exhaustive search over all two-bit codes.
Complexity
The symbolic minimization of line L1 is a two-level minimization, hard in general. Lines L2 and L3 take time. Line L6 runs times, and each run of the reference backtracking tries at most placements with checks each, which gives the term. The heuristics of the NOVA program replace this exponential step by polynomial ones.
Properties
- Fixed code length. The number of flip-flops is always , unless the user asks for more.
- Maximal. The kept set cannot be extended. Nothing proves that its weight is the largest possible.
- Not optimal. The final logic need not be the smallest over codes of the same length. None of KISS, NOVA and MUSTANG is optimal for the final logic: on the example machines of the three pages, an exhaustive search over all codes finds cheaper logic than each of them gives.
- Same bound as KISS when all constraints fit. If every group can be met at length , NOVA keeps them all and the KISS bound holds.
- Deterministic. The order of line L3 and the search order fix the result.
Variants and improvements
- Exact embedding at fixed length. For small machines, the largest-weight set of constraints that some code meets can be found by searching all codes, as the tests do. This gives the best answer to NOVA's own objective, which is still not the final logic.
- Weights from the cubes saved. A weight would measure what failing costs under the bound, but depends on the code, so it is known only after the embedding.
- Output constraints. Constraints from the next-state field, described in De Micheli's book (Chapter 9), let cubes share next-state bits, which input constraints alone cannot see.
- Multilevel logic. For multilevel implementations, MUSTANG uses attraction weights between pairs of states instead of face constraints.
- Longer codes. Raising by one or two bits often lets every constraint fit, which turns NOVA into KISS with a heuristic embedding.
When to use it
Use NOVA when the controller is a PLA or another two-level form and the number of flip-flops is fixed, so KISS's longer codes are not allowed. For small machines, compare its result with an exhaustive search over codes, since equal-weight codes can differ in cost. For multilevel logic, a method aimed at multilevel cost, such as MUSTANG, is the usual choice.
Pitfalls
- Taking the weight as the cost. The met weight is a proxy. Two codes that meet the same groups can give different logic, as in the example.
- Unreduced machines. Equivalent states give extra groups and waste code space. Reduce the machine first with DFA minimization or incompletely specified FSM minimization.
- Ties in the order. All groups often have weight 1, so the tie rule of line L3 decides what is kept. A different tie rule can give a different result.
- Unused codes. When , the unused codes are don't cares in the final minimization, and they also make more groups fit.
- Skipping the final minimization. The bound counts cubes before minimization. The real cost is the size of a two-level cover after minimization with Espresso or an exact minimizer.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Shared helper of the hs3 eda pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Small exact two-level logic for finite state machines.
This module holds no state encoder. It gives the encoders and their tests:
- an exact multiple-valued, multiple-output two-level minimizer for tiny
functions (all cubes, then an exact set cover by branch and bound);
- the symbolic function of a machine (present state as one multiple-valued
input, next state as one output per state) and the encoded function of a
machine under given codes;
- a check that a cover implements the machine;
- an exhaustive search for the best codes of a given length.
A machine is (ni, no, states, rows). A row is (inp, ps, ns, out): inp is a
string over 0, 1 and - of length ni, ps and ns are state names, and out is
a string over 0, 1 and - of length no. Rows of one present state must not
overlap in the input. Input and state pairs that no row covers are don't
cares.
"""
import itertools
# ---------------------------------------------------------------- minimizer
def _minterms(domains):
return list(itertools.product(*[range(d) for d in domains]))
def _literals(cube, domains):
return sum(1 for m, d in zip(cube, domains) if m != (1 << d) - 1)
def minimize(domains, on, dc):
"""Exact minimum cover; return a list of (cube, outputs).
domains[i] is the number of values of variable i (2 for a binary one).
on[j] and dc[j] are sets of points (tuples) for output j. The cover has
the least number of cubes, and among those the least number of input
literals. A cube is a tuple of nonempty value masks.
"""
nout = len(on)
points = _minterms(domains)
npts = len(points)
index = {p: i for i, p in enumerate(points)}
# value masks: the points where variable i takes value v, as bit sets
vmask = [[0] * d for d in domains]
for p, i in index.items():
for var, v in enumerate(p):
vmask[var][v] |= 1 << i
on_m = [sum(1 << index[p] for p in on[j]) for j in range(nout)]
ok_m = [on_m[j] | sum(1 << index[p] for p in dc[j]) for j in range(nout)]
sub = [[sum(vmask[var][v] for v in range(d) if m >> v & 1) for m in range(1 << d)] for var, d in enumerate(domains)]
full = (1 << npts) - 1
cands = []
for cube in itertools.product(*[range(1, 1 << d) for d in domains]):
pm = full
for var, m in enumerate(cube):
pm &= sub[var][m]
outs = [j for j in range(nout) if pm & ~ok_m[j] == 0]
cover = 0
for j in outs:
cover |= (pm & on_m[j]) << (j * npts)
if cover:
cands.append((cube, frozenset(outs), cover, _literals(cube, domains)))
# Keep only terms that no other term dominates. A cube is dropped at
# once if adding one value to one variable covers at least as much,
# since that never adds a literal; the rest are compared in pairs.
by_cube = {c[0]: c[2] for c in cands}
pruned = []
for c in cands:
cube, cov = c[0], c[2]
grown = False
for var, m in enumerate(cube):
for v in range(domains[var]):
if not m >> v & 1:
bigger = cube[:var] + (m | 1 << v,) + cube[var + 1:]
if cov & ~by_cube.get(bigger, 0) == 0:
grown = True
break
if grown:
break
if not grown:
pruned.append(c)
cands = pruned
cands.sort(key=lambda c: (-bin(c[2]).count("1"), c[3]))
terms = []
for c in cands:
if not any(c[2] & ~t[2] == 0 and t[3] <= c[3] for t in terms):
terms.append(c)
need = 0
for j in range(nout):
need |= on_m[j] << (j * npts)
by_elem = {}
for i, t in enumerate(terms):
m = t[2]
while m:
low = m & -m
by_elem.setdefault(low, []).append(i)
m ^= low
order = sorted(by_elem, key=lambda e: len(by_elem[e]))
tmask = {e: sum(1 << i for i in by_elem[e]) for e in by_elem}
best = [None, (len(terms) + 1, 0)]
def lower_bound(left):
lb = 0
used = 0
for e in order:
if left & e and not used & tmask[e]:
lb += 1
used |= tmask[e]
return lb
def search(left, chosen, nlit):
if not left:
if (len(chosen), nlit) < best[1]:
best[0], best[1] = list(chosen), (len(chosen), nlit)
return
if (len(chosen) + lower_bound(left), nlit) >= best[1]:
return
e = next(e for e in order if left & e)
for i in sorted(by_elem[e], key=lambda i: (-bin(terms[i][2] & left).count("1"), terms[i][3])):
chosen.append(i)
search(left & ~terms[i][2], chosen, nlit + terms[i][3])
chosen.pop()
search(need, [], 0)
return [(terms[i][0], terms[i][1]) for i in best[0]]
def cost(cover, domains):
"""(number of cubes, number of input literals) of a cover."""
return len(cover), sum(_literals(c, domains) for c, _ in cover)
# ---------------------------------------------------------------- machines
def _bits_match(cube, bits):
return all(c == "-" or int(c) == b for c, b in zip(cube, bits))
def _lookup(fsm, bits, s):
ni, no, states, rows = fsm
for inp, ps, ns, out in rows:
if ps == s and _bits_match(inp, bits):
return ns, out
return None
def symbolic_function(fsm):
"""Domains, on and dc of the symbolic function.
Variables: the ni inputs, then the present state with len(states)
values. Outputs: one per next state (one-hot), then the no outputs.
"""
ni, no, states, rows = fsm
n = len(states)
domains = [2] * ni + [n]
on = [set() for _ in range(n + no)]
dc = [set() for _ in range(n + no)]
for p in _minterms(domains):
hit = _lookup(fsm, p[:ni], states[p[ni]])
for j in range(n + no):
if hit is None:
dc[j].add(p)
elif j < n:
if states[j] == hit[0]:
on[j].add(p)
else:
c = hit[1][j - n]
if c == "1":
on[j].add(p)
elif c == "-":
dc[j].add(p)
return domains, on, dc
def encoded_function(fsm, codes, k):
"""Domains, on and dc of the machine under codes (state -> int of k bits).
Variables: the ni inputs, then the k state bits, most significant
first. Outputs: the k next state bits, then the no outputs. Codes that
no state uses are don't cares.
"""
ni, no, states, rows = fsm
by_code = {codes[s]: s for s in states}
domains = [2] * (ni + k)
on = [set() for _ in range(k + no)]
dc = [set() for _ in range(k + no)]
for p in _minterms(domains):
code = int("".join(map(str, p[ni:])), 2) if k else 0
s = by_code.get(code)
hit = None if s is None else _lookup(fsm, p[:ni], s)
for j in range(k + no):
if hit is None:
dc[j].add(p)
elif j < k:
if codes[hit[0]] >> (k - 1 - j) & 1:
on[j].add(p)
else:
c = hit[1][j - k]
if c == "1":
on[j].add(p)
elif c == "-":
dc[j].add(p)
return domains, on, dc
def encoded_cost(fsm, codes, k):
domains, on, dc = encoded_function(fsm, codes, k)
return cost(minimize(domains, on, dc), domains)
def implements(fsm, codes, k, cover):
"""Does the two-level cover give the right next state and outputs?
It checks every input and state pair that some row specifies.
"""
ni, no, states, rows = fsm
for s in states:
for bits in itertools.product((0, 1), repeat=ni):
hit = _lookup(fsm, bits, s)
if hit is None:
continue
p = tuple(bits) + tuple(codes[s] >> (k - 1 - b) & 1 for b in range(k))
val = [0] * (k + no)
for cube, outs in cover:
if all(m >> v & 1 for m, v in zip(cube, p)):
for j in outs:
val[j] = 1
if val[:k] != [codes[hit[0]] >> (k - 1 - b) & 1 for b in range(k)]:
return False
for j, c in enumerate(hit[1]):
if c != "-" and val[k + j] != int(c):
return False
return True
_CODES = {}
def all_codes(n, k):
"""Every injective code of n states in k bits, one per class of bit permutations.
Permuting the bits of all codes permutes the state variables and the
next state outputs, so the cost does not change. Complementing a bit
can change it, so those classes stay apart.
"""
if (n, k) not in _CODES:
seen = set()
keep = []
perms = list(itertools.permutations(range(k)))
for codes in itertools.permutations(range(1 << k), n):
key = min(tuple(sum((c >> perm[b] & 1) << b for b in range(k)) for c in codes) for perm in perms)
if key not in seen:
seen.add(key)
keep.append(codes)
_CODES[(n, k)] = keep
return list(_CODES[(n, k)])
def exhaustive_best(fsm, k):
"""Return (best cost, list of cost of every class) over all codes of length k."""
ni, no, states, rows = fsm
costs = []
for codes in all_codes(len(states), k):
costs.append(encoded_cost(fsm, dict(zip(states, codes)), k))
return min(costs), costs
nova_state_encoding.py 85 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/nova-state-encoding/. The authors are listed in prov/EG491A.jsonl.
"""A NOVA-style encoder: weighted face constraints at the least code length.
Symbolic minimization gives groups of present states. The weight of a
group is the number of symbolic cubes that use it. With k fixed to the
least length ceil(log2 n), the encoder takes the groups in order of
decreasing weight and keeps a group if the kept groups can still all be
met. This follows the greedy idea of Villa and Sangiovanni-Vincentelli's
heuristic; their program has several other options that are not here.
The satisfiability test is an exact search, so it fits only small machines.
"""
from fsmlogic import minimize, symbolic_function
def weighted_constraints(fsm):
"""Groups of present states with their weights, heaviest first."""
ni, no, states, rows = fsm
n = len(states)
domains, on, dc = symbolic_function(fsm)
weight = {}
first = {}
for pos, (cube, outs) in enumerate(minimize(domains, on, dc)): # @line L1
group = frozenset(states[v] for v in range(n) if cube[ni] >> v & 1)
if 1 < len(group) < n:
weight[group] = weight.get(group, 0) + 1 # @line L2
first.setdefault(group, pos)
return sorted(weight.items(), key=lambda gw: (-gw[1], len(gw[0]), first[gw[0]])) # @line L3
def face(codes, group, k):
vals = [codes[s] for s in group]
full = (1 << k) - 1
agree = full
for v in vals[1:]:
agree &= ~(v ^ vals[0]) & full
return agree, vals[0] & agree
def embed(states, constraints, k):
"""Injective codes of k bits meeting every constraint, or None (backtracking)."""
n = len(states)
codes = {}
used = set()
def ok():
for g in constraints:
placed = [s for s in g if s in codes]
if len(placed) < 2:
continue
mask, val = face(codes, placed, k)
if any(codes[t] & mask == val for t in codes if t not in g):
return False
return True
def place(i):
if i == n:
return True
for c in range(1 << k):
if c in used:
continue
codes[states[i]] = c
used.add(c)
if ok() and place(i + 1):
return True
used.discard(c)
del codes[states[i]]
return False
return dict(codes) if place(0) else None
def nova_encode(fsm):
"""Return (k, codes, kept groups, dropped groups)."""
ni, no, states, rows = fsm
k = max(1, (len(states) - 1).bit_length()) # @line L4
kept, dropped = [], []
for group, w in weighted_constraints(fsm): # @line L5
if embed(states, kept + [group], k) is not None: # @line L6
kept.append(group)
else:
dropped.append(group) # @line L7
return k, embed(states, kept, k), kept, dropped # @line L8
test_nova_state_encoding.py 113 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/nova-state-encoding/. The authors are listed in prov/EG491A.jsonl.
import itertools
import random
from fsmlogic import all_codes, encoded_cost, encoded_function, exhaustive_best, implements, minimize, symbolic_function
from nova_state_encoding import face, nova_encode, weighted_constraints
# The machine of the page: one input, one output, four states.
M2 = (1, 1, ["s0", "s1", "s2", "s3"], [
("0", "s0", "s1", "1"), ("1", "s0", "s0", "1"),
("0", "s1", "s0", "1"), ("1", "s1", "s0", "1"),
("0", "s2", "s2", "0"), ("1", "s2", "s2", "1"),
("0", "s3", "s3", "1"), ("1", "s3", "s2", "0"),
])
def random_fsm(rng: random.Random, n, ni, no):
states = [f"s{i}" for i in range(n)]
rows = []
for s in states:
for x in range(1 << ni):
rows.append((format(x, f"0{ni}b"), s, rng.choice(states), "".join(rng.choice("01") for _ in range(no))))
return (ni, no, states, rows)
def meets(codes, group, k, states):
mask, val = face(codes, group, k)
return all(codes[t] & mask != val for t in states if t not in group)
def satisfiable(states, groups, k):
"""Brute force over all codes of k bits."""
return any(all(meets(dict(zip(states, cs)), g, k, states) for g in groups)
for cs in itertools.permutations(range(1 << k), len(states)))
def kappa(codes, group, k, states):
"""Least number of cubes over the k state bits that hold the codes of
group and no code of another state; unused codes are free."""
pts = list(itertools.product((0, 1), repeat=k))
as_pt = lambda c: tuple(c >> (k - 1 - b) & 1 for b in range(k))
on = {as_pt(codes[s]) for s in group}
off = {as_pt(codes[s]) for s in states if s not in group}
dc = set(pts) - on - off
return len(minimize([2] * k, [on], [dc]))
def symbolic_groups(fsm):
ni, no, states, rows = fsm
domains, on, dc = symbolic_function(fsm)
return [frozenset(states[v] for v in range(len(states)) if cube[ni] >> v & 1)
for cube, _ in minimize(domains, on, dc)]
def test_page_example():
states = M2[2]
assert symbolic_groups(M2).__len__() == 7
assert weighted_constraints(M2) == [
(frozenset({"s0", "s1"}), 1), (frozenset({"s2", "s3"}), 1), (frozenset({"s0", "s1", "s2"}), 1)]
k, codes, kept, dropped = nova_encode(M2)
assert (k, codes) == (2, {"s0": 0, "s1": 1, "s2": 2, "s3": 3})
assert kept == [frozenset({"s0", "s1"}), frozenset({"s2", "s3"})]
assert dropped == [frozenset({"s0", "s1", "s2"})]
assert not satisfiable(states, kept + dropped, 2)
assert encoded_cost(M2, codes, 2) == (5, 10)
assert sum(kappa(codes, g, 2, states) for g in symbolic_groups(M2)) == 8
assert exhaustive_best(M2, 2)[0] == (4, 9)
def test_random_machines():
rng = random.Random(1990)
hits = excess = worst = most = 0
for _ in range(100):
fsm = random_fsm(rng, 4, 1, 1)
states = fsm[2]
k, codes, kept, dropped = nova_encode(fsm)
assert k == 2 and sorted(codes.values()) == sorted(set(codes.values()))
# the kept groups are met, and each dropped group fails with the
# groups kept before it
assert all(meets(codes, g, k, states) for g in kept)
before = []
for g, w in weighted_constraints(fsm):
if g in kept:
before.append(g)
else:
assert g in dropped and not satisfiable(states, before + [g], k)
# the proved bound: cubes <= sum over symbolic cubes of kappa
domains, on, dc = encoded_function(fsm, codes, k)
exact = minimize(domains, on, dc)
assert implements(fsm, codes, k, exact)
assert len(exact) <= sum(kappa(codes, g, k, states) for g in symbolic_groups(fsm))
# does the greedy keep the largest weight that any code can meet?
weights = weighted_constraints(fsm)
got_w = sum(w for g, w in weights if g in kept)
best_w = max(sum(w for g, w in weights if meets(dict(zip(states, cs)), g, k, states))
for cs in all_codes(4, k))
assert got_w <= best_w
most += got_w == best_w
# measured gap of the final logic to the best 2-bit code
best = exhaustive_best(fsm, k)[0][0]
got = len(exact)
hits += got == best
excess += got - best
worst = max(worst, got - best)
assert (most, hits, excess, worst) == MEASURED
# 100 machines: the greedy keeps the largest weight that any 2-bit code can
# meet on all 100; the final logic meets the best 2-bit code on 41, with 71
# extra cubes in total and at most 3 extra cubes on one machine.
MEASURED = (100, 41, 71, 3)
History
De Micheli, Brayton and Sangiovanni-Vincentelli (1985) introduced face constraints with KISS, which satisfies all of them with codes as long as needed. Villa and Sangiovanni-Vincentelli (1990) gave NOVA, which keeps the code length fixed, weights the constraints, and offers exact and heuristic embeddings; they reported PLA areas on a set of benchmark machines, a measurement on that set rather than a bound. De Micheli's 1994 textbook places both in a common framework of input and output encoding constraints.
References
- Tiziano Villa and Alberto L. Sangiovanni-Vincentelli, NOVA, state assignment of finite state machines for optimal two-level logic implementation, IEEE Transactions on Computer-Aided Design 9(9), 905 to 924, 1990, the weighted face constraints, the exact and heuristic embedding algorithms at a fixed code length, and the PLA areas measured on benchmark machines
- Giovanni De Micheli, Robert K. Brayton and Alberto L. Sangiovanni-Vincentelli, Optimal state assignment for finite state machines, IEEE Transactions on Computer-Aided Design CAD-4(3), 269 to 285, 1985, symbolic minimization and face constraints, on which NOVA builds
- Giovanni De Micheli, Synthesis and Optimization of Digital Circuits, McGraw-Hill, 1994, Chapter 9 (state encoding for two-level circuits and the embedding of face constraints)
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag EG491A Edit this page History Report an error Markdown