Algorithmcore
Transition density
Also called Najm transition density.
Najm's measure of average transitions per second and its propagation through gates by Boolean difference probabilities, giving power without simulation vectors.
- Time
- O(G + P K) worst
- Space
- O(G + n) extra
- Where
- G = the number of gates; K = the largest fanin of a gate; P = the number of gate input pins; n = the number of primary inputs
- Model
- Word RAM
- Properties
- deterministicnot exactofflineiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Farid N. Najm, 1991
The transition density of a logic signal is its average number of transitions per unit time. Najm (1991, 1993) showed that for a gate or block with independent inputs,
where is the Boolean difference of with respect to . The algorithm applies this rule gate by gate in topological order, with the signal probabilities of the gate inputs, and so turns input statistics into a density at every node in one pass, without input vectors or simulation. The dynamic power of a node is then . The result is exact on circuits without reconvergent fanout when no two inputs switch at the same instant. With reconvergent fanout it is an approximation, and with inputs that switch together at a clock edge it counts glitches that a zero-delay view does not see.
In plain words
Each input wire turns on and off at random, a known number of times per second, and the inputs act independently. The question is how often each wire inside the circuit switches.
When one input of a gate switches, the output switches only if the other inputs let the change through. An AND gate passes a change on one input only when its other inputs are on. So the output switches as often as each input switches, times the chance that the gate passes that input, summed over the inputs.
Going through the gates from the inputs to the outputs gives a switching rate for every wire. Multiply each rate by the energy of one switch and you have the power, with no simulation at all.
The problem
The input is a combinational circuit with primary inputs and gates in topological order, and for each input two numbers: its equilibrium probability , the fraction of time it is 1, and its transition density , its mean number of transitions per unit time. The model treats each input as a random 0-1 signal in continuous time. The signals are mutually independent and stationary, with a finite number of transitions in each finite interval. For a node with transitions in ,
The output is and for every node .
For a Boolean function of , the Boolean difference of with respect to is
the XOR of the two cofactors of . It does not depend on , and it is 1 at exactly those values of the other variables for which a change of changes . In test it is the condition for the effect of a fault on to reach the output. For a single gate it is simple: is the AND of the other inputs, the derivative of OR is the AND of the complements of the other inputs, and the derivative of XOR, BUF or NOT is 1. Complementing does not change , so NAND, NOR and XNOR have the same derivatives as AND, OR and XOR.
The algorithm
TRANSITION-DENSITY(C, p, d)- 1
for each primary input x_i do P[x_i] ← p_i; D[x_i] ← d_i - 2
for each gate y = kind(z_1, …, z_k) in topological order do - 3
P[y] ← the signal probability of kind with input probabilities P[z_1], …, P[z_k] - 4
D[y] ← 0 - 5
for j ← 1 to k do - 6
b ← P(∂y/∂z_j): ∏_{l≠j} P[z_l] for AND and NAND, ∏_{l≠j} (1 − P[z_l]) for OR and NOR, 1 for XOR, XNOR, BUF and NOT - 7
D[y] ← D[y] + b · D[z_j] - 8
return P, D
Line L3 is the numeric mode of signal probability propagation. Line L6 computes the probability of the Boolean difference of the gate under the assumption that its inputs are independent, from the probabilities found at line L3 for the earlier gates.
Example
A fanout-free circuit. Take and , with densities in transitions per nanosecond.
| node | ||
|---|---|---|
Each node drives one pin, so these values are exact under the model. A change on passes the OR gate whenever , which is 7/8 of the time, so inherits most of the activity of . If drives 10 fF at 1 V, its power is µW.
A reconvergent circuit. Take , and , all inputs with and . The algorithm gives and . The rule applied to the whole function gives the true value: , and , so
The gate-by-gate value is 20 percent too high, because and both depend on and the gate rule at treats them as independent.
Correctness
The proof has two parts, both in the full proof.
The rule for one block. Suppose the inputs of are independent stationary signals, no two of them switch at the same instant, and follows with zero delay or with a fixed delay. Then changes only at a transition of some , and at such an instant it changes exactly when at the values of the other inputs. The other inputs are independent of the transition times of and stationary, so the expected count of the transitions of that pass is times the expected count of the transitions of . Summing over gives the formula. A fixed delay moves the transitions in time but does not change their number.
The pass over the gates. When the input pins of every gate have disjoint supports, as in a fanout-free circuit, the inputs of each gate are functions of disjoint groups of independent primary input signals. So they are independent stationary signals, with no common transition instants, and the rule for one block holds at each gate. The probabilities of line L3 are exact under the same condition. By induction in topological order every and is exact. Under reconvergent fanout the independence of the gate inputs fails, and the example above shows that the result can then be wrong.
Proof: The transition density formula for independent inputs, and exactness of the gate-by-gate pass without reconvergencefull
Model. A logic signal is a random function that is right-continuous and has finitely many transitions in every bounded interval. Write for the random set of its transition times and for the number of them in a set . The signal is stationary when the law of does not depend on ; then for every and for a constant , the transition density, which we assume finite. Signals are independent when they are independent as random functions.
Lemma 1 (no common transitions). If and are independent stationary signals with finite densities, then with probability 1 they have no transition time in common.
Proof. For a fixed instant , , so . Condition on . Its transition times in form a finite set that is independent of , so the expected number of them that are also transitions of is a finite sum of zeros. Taking expectations and letting over the integers gives the claim.
Lemma 2 (sampling at independent instants). Let be a random set of instants with , and let be a stationary 0-1 signal independent of . Then
Proof. Condition on . The sum then has finitely many terms at fixed instants, and since is independent of and stationary, for each . So the conditional expectation is , and its expectation is .
Theorem 1 (one block). Let be independent stationary signals with finite densities, , and for a fixed delay . Then is stationary and
where has independent coordinates with .
Proof. The vector signal is stationary because its coordinates are independent and stationary, so is stationary, and a shift by changes neither the law nor the density. So take . By Lemma 1, with probability 1 no two inputs switch at the same instant. Then is constant between the transitions of the inputs, and at a transition time of only changes. So changes at exactly when takes different values at the two vectors that differ only in coordinate , which is . The Boolean difference does not depend on , so its value is , a function of the other inputs only. Hence
is a stationary signal that depends only on , so it is independent of . Lemma 2 gives , and because the values of at one instant are independent with . Divide by .
Lemma 3 (gate rules). For a gate with independent 0-1 inputs, , the probability of is for AND and NAND, for OR and NOR, and 1 for XOR, XNOR, BUF and NOT, which is line L6.
Proof. and , so the difference is . For OR the cofactors are 1 and , whose XOR is . For XOR the cofactors are complements of each other, so the difference is 1, and the same holds for BUF and NOT. Since , the complemented gates have the same differences. The probabilities follow from the independence of the .
Theorem 2 (the pass is exact without reconvergence). Suppose the primary inputs are independent stationary signals with finite densities, every gate output follows its function with a fixed delay, and for every gate the supports of its input pins are pairwise disjoint (this holds in every fanout-free circuit). Then TRANSITION-DENSITY returns and for every node .
Proof. By induction in topological order we show that each node is a stationary signal that is a function of the primary input signals in its support (with time shifts), and that and are exact. For a primary input this is line L1. For a gate , the signals are functions of the disjoint groups of independent signals, so they are independent, and each is stationary with a finite density by the induction hypothesis. The node is with a fixed delay, so it is a function of the inputs in , and Theorem 1 applies with as the inputs. With the values at one instant independent, line L3 gives (the numeric mode of signal probability propagation is exact for independent gate inputs), Lemma 3 shows that line L6 gives , and lines L4 to L7 then compute the sum of Theorem 1 with the exact .
Reconvergence. For , , with all and , Theorem 1 applied to as one block gives , which is the true density. The pass gives . The step that fails is the independence of and in Theorem 1 at the gate : both depend on , and they switch together at every transition of that both pass, so Lemma 1 fails for them as well.
What is not proved. For synchronous inputs that all switch at a clock edge, Lemma 1 fails, and the formula is not the zero-delay activity per cycle. For an AND gate with fresh uniform inputs every cycle the formula gives per cycle and the zero-delay output changes in of the cycles. The gap is the expected number of glitches that the formula assumes when the two input transitions are separated in time.
Complexity
A gate with inputs costs at line L3 and for each of its pins at line L6, so the pass costs arithmetic operations. With prefix and suffix products of and , line L6 costs per pin and the pass costs . The space is one probability and one density per node, . This is the same cost as one zero-delay logic simulation of one vector, while a simulation-based estimate needs many vectors.
Applying the rule to whole functions in place of gates is exact on every circuit with independent inputs, but it needs for every node and input. That is a signal probability, which is #P-hard in general. With BDDs it costs time linear in the size of the BDD of , which can be exponential in .
Properties
- What it measures. counts all transitions, rising and falling, including glitches. The dynamic power of a node with load is , because a full charge and discharge, two transitions, costs .
- Continuous time. The density is a rate per unit time, not per clock cycle. For a synchronous circuit with clock frequency , the switching activity per cycle is if the assumptions hold.
- Linear in the input densities. For fixed probabilities, every is a linear function of the input densities with nonnegative coefficients. So the share of each input in the activity of a node is explicit, and doubling all input densities doubles all node densities.
- Delay does not enter. The algorithm uses no gate delays. In the model a delay shifts the transitions of a signal but does not change their number.
- Glitches through a gate. When the inputs of a gate switch at different times, each passing input transition is counted, so the density includes the glitches that come from skew between independent inputs.
Variants and improvements
- Blocks in place of gates. Najm's program, DENSIM, applies the rule to groups of gates, computing the Boolean difference probabilities of each block with BDDs. Larger blocks absorb local reconvergence, at a cost that grows with the block size.
- Low-pass filtering. A real gate with inertial delay does not pass a pulse shorter than its delay (see inertial and transport delay). Najm (1994) modified the rule to filter such pulses, which lowers the overestimate on deep logic.
- Correlation coefficients. Add pairwise correlation terms between gate inputs to correct part of the error from reconvergent fanout. This is a heuristic without a general bound.
- Exact zero-delay activity. If the question is the activity per clock cycle with zero delay, compute symbolically, as in BDD-based switching activity estimation.
- Statistical estimates. Monte Carlo power estimation simulates the circuit with a real delay model and stops at a stated accuracy, at a much higher cost per node.
When to use it
Use transition density for fast, vectorless activity estimates on large gate-level netlists, for example to find the most active nets early, to compare design options, or to give an activity number to every net when no simulation testbench exists. It suits circuits with mostly independent inputs and limited reconvergence. When a number must be accurate within a known error, use simulation with a stopping rule, and use the density result as a starting point or a sanity check.
Pitfalls
- Simultaneous switching. The rule assumes that two inputs never switch at the same instant. In a synchronous circuit all register outputs switch near the clock edge. For an AND gate with fresh random inputs each cycle (, per cycle), the rule gives transition per cycle, while the zero-delay output changes only in of the cycles. If one input arrives a little later, the true count with that delay is again : the difference is the glitch that the skew creates.
- Reconvergent fanout. The gate inputs then depend on each other and the result can be too high or too low. For the rule gives , while the output is 0 with zero delay. With a delay on the inverter, each rising edge of makes a pulse of two transitions, so is right for that delay model and wrong for a fast inverter that filters the pulse.
- Correlated inputs. Inputs from a counter, a shift register or the same bus are not independent, and the result can be far off.
- Densities are not probabilities. is a rate with a unit, not a number between 0 and 1. Mixing per-cycle and per-second values is a common unit error.
- Glitches that do not exist. In deep logic the rule passes every short pulse, while real gates filter many of them, so the estimate tends to be too high there.
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 pr1 eda pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Gate-level combinational netlists for the power estimation pages.
A circuit has named primary inputs and gates in topological order. Each gate
has a kind (BUF, NOT, AND, OR, NAND, NOR, XOR, XNOR), a list of fanin names
and an integer delay (1 by default). A node is a primary input or a gate.
This module holds the circuit model, plain evaluation of one input vector,
structural queries (fanout, support, reconvergence) and a step simulation of
the transport delay model. It holds no estimation algorithm.
"""
from __future__ import annotations
import random
from typing import Iterable, Optional, Sequence
KINDS = ("BUF", "NOT", "AND", "OR", "NAND", "NOR", "XOR", "XNOR")
def gate_value(kind: str, bits: Sequence[int]) -> int:
"""Value of one gate on 0-1 inputs."""
if kind == "BUF":
return bits[0]
if kind == "NOT":
return 1 - bits[0]
if kind in ("AND", "NAND"):
v = int(all(bits))
elif kind in ("OR", "NOR"):
v = int(any(bits))
elif kind in ("XOR", "XNOR"):
v = sum(bits) % 2
else:
raise ValueError(f"unknown gate kind {kind}")
return 1 - v if kind in ("NAND", "NOR", "XNOR") else v
class Circuit:
"""Inputs, then gates (name, kind, fanins) in topological order."""
def __init__(
self,
inputs: Sequence[str],
gates: Sequence[tuple[str, str, Sequence[str]]],
delay: Optional[dict[str, int]] = None,
) -> None:
self.inputs = list(inputs)
self.gates = [(g, k, list(f)) for g, k, f in gates]
seen = set(self.inputs)
if len(seen) != len(self.inputs):
raise ValueError("repeated input name")
for g, k, fins in self.gates:
if k not in KINDS:
raise ValueError(f"unknown gate kind {k}")
if g in seen:
raise ValueError(f"repeated node name {g}")
if not fins or (k in ("BUF", "NOT") and len(fins) != 1):
raise ValueError(f"bad fanin count at {g}")
for f in fins:
if f not in seen:
raise ValueError(f"{g} reads {f} before it is defined")
seen.add(g)
self.nodes = self.inputs + [g for g, _, _ in self.gates]
self.delay = {g: 1 for g, _, _ in self.gates}
if delay:
self.delay.update(delay)
def evaluate(self, x: Sequence[int]) -> dict[str, int]:
"""Values of all nodes for the input vector x (in the order of self.inputs)."""
val = dict(zip(self.inputs, x))
for g, k, fins in self.gates:
val[g] = gate_value(k, [val[f] for f in fins])
return val
def fanout(self) -> dict[str, int]:
"""Number of gate input pins that each node drives."""
cnt = {v: 0 for v in self.nodes}
for _, _, fins in self.gates:
for f in fins:
cnt[f] += 1
return cnt
def is_fanout_free(self) -> bool:
return all(c <= 1 for c in self.fanout().values())
def support(self) -> dict[str, frozenset[str]]:
"""The primary inputs in the transitive fanin of each node."""
sup: dict[str, frozenset[str]] = {x: frozenset([x]) for x in self.inputs}
for g, _, fins in self.gates:
sup[g] = frozenset().union(*(sup[f] for f in fins))
return sup
def has_reconvergence(self) -> bool:
"""True when some gate has two fanin pins whose supports meet."""
sup = self.support()
for _, _, fins in self.gates:
for i in range(len(fins)):
for j in range(i + 1, len(fins)):
if sup[fins[i]] & sup[fins[j]]:
return True
return False
def arrival(self) -> dict[str, int]:
"""Latest time at which each node can change after the inputs change at time 0."""
t = {x: 0 for x in self.inputs}
for g, _, fins in self.gates:
t[g] = self.delay[g] + max(t[f] for f in fins)
return t
def waveforms(c: Circuit, x: Sequence[int], y: Sequence[int]) -> dict[str, list[int]]:
"""Transport delay simulation: the inputs change from x to y at time 0.
Returns, for each node, its values at times -1, 0, 1, ..., T, where T is the
largest arrival time. A gate with delay d has at time t the value of its
function on the values of its fanins at time t - d. Before time 0 every
node holds its value under x.
"""
old = c.evaluate(x)
horizon = max(c.arrival().values())
wave = {v: [old[v]] for v in c.nodes} # index 0 is time -1
for xi, a, b in zip(c.inputs, x, y):
wave[xi] = [a] + [b] * (horizon + 1)
for g, k, fins in c.gates:
d = c.delay[g]
w = [old[g]]
for t in range(horizon + 1):
s = t - d
w.append(gate_value(k, [wave[f][s + 1] if s >= -1 else old[f] for f in fins]))
wave[g] = w
return wave
def transitions(c: Circuit, x: Sequence[int], y: Sequence[int], delay_model: str = "zero") -> dict[str, int]:
"""Number of value changes of each node when the inputs change from x to y.
delay_model "zero": a node changes at most once, when its value under x and y differ.
delay_model "transport": the step simulation of waveforms(), which counts glitches.
"""
if delay_model == "zero":
a, b = c.evaluate(x), c.evaluate(y)
return {v: int(a[v] != b[v]) for v in c.nodes}
if delay_model == "transport":
w = waveforms(c, x, y)
return {v: sum(1 for t in range(1, len(s)) if s[t] != s[t - 1]) for v, s in w.items()}
raise ValueError(delay_model)
def random_circuit(
rng: random.Random,
n_inputs: int,
n_gates: int,
kinds: Iterable[str] = KINDS,
max_fanin: int = 3,
fanout_free: bool = False,
max_delay: int = 1,
) -> Circuit:
"""A random circuit. With fanout_free, every node drives at most one gate pin."""
kinds = list(kinds)
inputs = [f"x{i}" for i in range(n_inputs)]
free = list(inputs)
names = list(inputs)
gates = []
delay = {}
for j in range(n_gates):
pool = free if fanout_free else names
if not pool:
break
k = rng.choice(kinds)
if k in ("BUF", "NOT"):
m = 1
else:
m = min(len(pool), rng.randint(2, max_fanin))
if m < 2:
k = rng.choice(["BUF", "NOT"])
m = 1
fins = rng.sample(pool, m)
g = f"g{j}"
gates.append((g, k, fins))
delay[g] = rng.randint(1, max_delay)
if fanout_free:
for f in fins:
free.remove(f)
free.append(g)
names.append(g)
return Circuit(inputs, gates, delay)
transition_density.py 80 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/transition-density/. The authors are listed in prov/G6GC4V.jsonl.
"""Transition density propagation (Najm 1993).
Each primary input x is a 0-1 signal in time with equilibrium probability
p[x] = P(x = 1) and transition density d[x] (mean number of transitions per
unit time). The inputs are independent. transition_densities(c, p, d) walks the
gates of a netlist.Circuit in topological order and sets, for y = f(z_1..z_k),
P(y) by the signal probability formula for independent fanins,
D(y) = sum_j P(df/dz_j) D(z_j),
where df/dz_j = f(z_j = 0) XOR f(z_j = 1) is the Boolean difference. The
result is exact when the fanins of every gate depend on disjoint sets of
inputs (for example in a fanout-free circuit) and no two inputs switch at
the same instant. Values are Fractions when the inputs are.
"""
from __future__ import annotations
from fractions import Fraction
from typing import Mapping, Sequence
def gate_probability(kind: str, q: Sequence[Fraction]) -> Fraction:
"""P(output = 1) for independent fanins with P(fanin j = 1) = q[j]."""
if kind in ("AND", "NAND"):
r = Fraction(1)
for v in q:
r *= v
elif kind in ("OR", "NOR"):
r = Fraction(1)
for v in q:
r *= 1 - v
r = 1 - r
elif kind in ("XOR", "XNOR"):
r = Fraction(0)
for v in q:
r = r + v - 2 * r * v
elif kind in ("BUF", "NOT"):
r = Fraction(q[0])
else:
raise ValueError(kind)
return 1 - r if kind in ("NAND", "NOR", "XNOR", "NOT") else r
def boolean_difference_probability(kind: str, q: Sequence[Fraction], j: int) -> Fraction:
"""P(df/dz_j = 1) for one gate, with independent fanins.
AND and NAND are sensitive to pin j when every other pin is 1, OR and NOR
when every other pin is 0, and XOR, XNOR, BUF and NOT always.
"""
r = Fraction(1)
if kind in ("AND", "NAND"):
for k, v in enumerate(q):
if k != j:
r *= v
elif kind in ("OR", "NOR"):
for k, v in enumerate(q):
if k != j:
r *= 1 - v
elif kind not in ("XOR", "XNOR", "BUF", "NOT"):
raise ValueError(kind)
return r
def transition_densities(c, p: Mapping[str, Fraction], d: Mapping[str, Fraction]):
"""Return (P, D): the probability and the transition density of every node."""
P: dict[str, Fraction] = {}
D: dict[str, Fraction] = {}
for x in c.inputs:
P[x], D[x] = Fraction(p[x]), Fraction(d[x]) # @line L1
for y, kind, fins in c.gates: # @line L2
q = [P[z] for z in fins]
P[y] = gate_probability(kind, q) # @line L3
D[y] = Fraction(0) # @line L4
for j, z in enumerate(fins): # @line L5
b = boolean_difference_probability(kind, q, j) # @line L6
D[y] += b * D[z] # @line L7
return P, D # @line L8
test_transition_density.py 212 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/transition-density/. The authors are listed in prov/G6GC4V.jsonl.
import itertools
import random
from fractions import Fraction
from netlist import KINDS, Circuit, random_circuit, transitions
from transition_density import boolean_difference_probability, gate_probability, transition_densities
HALF = Fraction(1, 2)
# y = ab + ac, the reconvergent example of the page.
RECONV = Circuit(["a", "b", "c"], [("u", "AND", ["a", "b"]), ("v", "AND", ["a", "c"]), ("y", "OR", ["u", "v"])])
def weight(c, p, x):
w = Fraction(1)
for name, b in zip(c.inputs, x):
w *= p[name] if b else 1 - p[name]
return w
def flip(x, i):
y = list(x)
y[i] = 1 - y[i]
return tuple(y)
def global_densities(c, p, d):
"""D(y) = sum_i P(dy/dx_i) D(x_i) with the Boolean differences of whole node functions, by enumeration."""
out = {v: Fraction(0) for v in c.nodes}
for x in itertools.product((0, 1), repeat=len(c.inputs)):
w = weight(c, p, x)
if w == 0:
continue
a = c.evaluate(x)
for i, name in enumerate(c.inputs):
b = c.evaluate(flip(x, i))
for v in c.nodes:
if a[v] != b[v]:
out[v] += w * d[name]
return out
class Chain:
"""Inputs as one Markov chain: each step picks input i with probability w[i]
and flips it with probability up[i] if it is 0 and down[i] if it is 1."""
def __init__(self, rng, n):
self.w = [Fraction(1, n + 1)] * n
self.up = [Fraction(rng.randint(1, 6), 6) for _ in range(n)]
self.down = [Fraction(rng.randint(1, 6), 6) for _ in range(n)]
def marginal(self, i):
return self.up[i] / (self.up[i] + self.down[i])
def rate(self, i):
return self.w[i] * 2 * self.up[i] * self.down[i] / (self.up[i] + self.down[i])
def flip_prob(self, i, bit):
return self.w[i] * (self.down[i] if bit else self.up[i])
def markov_toggles(c, ch):
"""Expected node transitions per step of the chain, from the product distribution, by enumeration."""
p = {name: ch.marginal(i) for i, name in enumerate(c.inputs)}
out = {v: Fraction(0) for v in c.nodes}
for x in itertools.product((0, 1), repeat=len(c.inputs)):
w = weight(c, p, x)
a = c.evaluate(x)
for i in range(len(c.inputs)):
b = c.evaluate(flip(x, i))
t = w * ch.flip_prob(i, x[i])
for v in c.nodes:
if a[v] != b[v]:
out[v] += t
return out
def chain_inputs(c, ch):
p = {name: ch.marginal(i) for i, name in enumerate(c.inputs)}
d = {name: ch.rate(i) for i, name in enumerate(c.inputs)}
return p, d
def test_gate_rules_against_truth_tables():
rng = random.Random(1)
for kind in KINDS:
for k in ([1] if kind in ("BUF", "NOT") else [2, 3, 4]):
c = Circuit([f"i{j}" for j in range(k)], [("o", kind, [f"i{j}" for j in range(k)])])
for _ in range(5):
p = {x: Fraction(rng.randint(0, 6), 6) for x in c.inputs}
d = {x: Fraction(rng.randint(0, 9), 3) for x in c.inputs}
q = [p[x] for x in c.inputs]
for j in range(k):
one = {x: Fraction(int(x == c.inputs[j])) for x in c.inputs}
assert boolean_difference_probability(kind, q, j) == global_densities(c, p, one)["o"]
P, D = transition_densities(c, p, d)
assert D["o"] == global_densities(c, p, d)["o"]
assert P["o"] == gate_probability(kind, q)
def test_product_distribution_is_stationary():
rng = random.Random(2)
for n in range(1, 5):
ch = Chain(rng, n)
names = [f"x{i}" for i in range(n)]
c = Circuit(names, [])
p = {name: ch.marginal(i) for i, name in enumerate(names)}
states = list(itertools.product((0, 1), repeat=n))
pi = {x: weight(c, p, x) for x in states}
nxt = {x: Fraction(0) for x in states}
for x in states:
stay = Fraction(1)
for i in range(n):
t = ch.flip_prob(i, x[i])
nxt[flip(x, i)] += pi[x] * t
stay -= t
nxt[x] += pi[x] * stay
assert nxt == pi
# The input rates of the chain are the transition densities D(x_i).
for i, name in enumerate(names):
assert markov_toggles(c, ch)[name] == ch.rate(i)
def test_page_fanout_free_example():
c = Circuit(["a", "b", "c"], [("u", "AND", ["a", "b"]), ("y", "OR", ["u", "c"])])
p = {"a": HALF, "b": Fraction(1, 4), "c": HALF}
d = {"a": Fraction(2), "b": Fraction(1), "c": Fraction(4)}
P, D = transition_densities(c, p, d)
assert (P["u"], D["u"]) == (Fraction(1, 8), 1)
assert (P["y"], D["y"]) == (Fraction(9, 16), 4)
assert D == global_densities(c, p, d)
def test_page_reconvergent_example():
p = {"a": HALF, "b": HALF, "c": HALF}
d = {"a": Fraction(1), "b": Fraction(1), "c": Fraction(1)}
P, D = transition_densities(RECONV, p, d)
assert D["u"] == D["v"] == 1
assert D["y"] == Fraction(3, 2)
assert P["y"] == Fraction(7, 16)
assert global_densities(RECONV, p, d)["y"] == Fraction(5, 4)
def test_exact_without_reconvergence_against_markov_chain():
rng = random.Random(3)
count = 0
for _ in range(250):
c = random_circuit(rng, rng.randint(1, 6), rng.randint(1, 8), fanout_free=rng.random() < 0.5)
if c.has_reconvergence():
continue
count += 1
ch = Chain(rng, len(c.inputs))
p, d = chain_inputs(c, ch)
_, D = transition_densities(c, p, d)
assert D == markov_toggles(c, ch)
assert count > 80
def test_global_formula_matches_markov_chain_on_every_circuit():
rng = random.Random(4)
for _ in range(100):
c = random_circuit(rng, rng.randint(1, 5), rng.randint(1, 8))
ch = Chain(rng, len(c.inputs))
p, d = chain_inputs(c, ch)
assert global_densities(c, p, d) == markov_toggles(c, ch)
def test_propagation_is_wrong_under_reconvergence():
rng = random.Random(5)
wrong = 0
for _ in range(300):
c = random_circuit(rng, rng.randint(2, 5), rng.randint(3, 8))
if not c.has_reconvergence():
continue
ch = Chain(rng, len(c.inputs))
p, d = chain_inputs(c, ch)
if transition_densities(c, p, d)[1] != markov_toggles(c, ch):
wrong += 1
assert wrong > 50
def per_cycle(c, delay_model):
"""Expected transitions per cycle for fresh uniform vectors each cycle, over all pairs."""
n = len(c.inputs)
tot = {v: Fraction(0) for v in c.nodes}
for x in itertools.product((0, 1), repeat=n):
for y in itertools.product((0, 1), repeat=n):
for v, k in transitions(c, x, y, delay_model).items():
tot[v] += Fraction(k, 4**n)
return tot
def test_simultaneous_switching():
# Fresh uniform vectors every cycle: P = 1/2 and D = 1/2 per cycle for each input.
same_time = Circuit(["a", "b"], [("y", "AND", ["a", "b"])])
skewed = Circuit(["a", "b"], [("bd", "BUF", ["b"]), ("y", "AND", ["a", "bd"])])
p = {"a": HALF, "b": HALF}
_, D = transition_densities(same_time, p, p)
assert D["y"] == HALF
assert per_cycle(same_time, "zero")["y"] == Fraction(3, 8)
assert per_cycle(skewed, "transport")["y"] == HALF
def test_glitch_of_a_and_not_a():
c = Circuit(["a"], [("n", "NOT", ["a"]), ("y", "AND", ["a", "n"])])
_, D = transition_densities(c, {"a": HALF}, {"a": HALF})
assert D["y"] == HALF
assert per_cycle(c, "zero")["y"] == 0
assert per_cycle(c, "transport")["y"] == HALF
History
Najm introduced the transition density at the Design Automation Conference in 1991 and gave the full treatment in IEEE Transactions on CAD in 1993. He modeled logic signals as stationary random processes, proved the Boolean difference formula for a module with independent inputs, and propagated densities through a circuit by blocks whose Boolean differences were computed with BDDs. In 1994 he added a low-pass filter for gates with inertial delay, and his survey of power estimation in the same year placed the method next to simulation, signal probability and BDD-based methods.
References
- Farid N. Najm, Transition density, a new measure of activity in digital circuits, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 12(2), 310 to 323, February 1993, the definition of the transition density and equilibrium probability, the theorem that gives the density at the output of a Boolean module with independent inputs, and the propagation algorithm
- Farid N. Najm, Transition density, a stochastic measure of activity in digital circuits, Proceedings of the 28th ACM/IEEE Design Automation Conference, 644 to 649, June 1991, the first presentation of the measure and of its propagation
- Farid N. Najm, A survey of power estimation techniques in VLSI circuits, IEEE Transactions on VLSI Systems 2(4), 446 to 455, December 1994, the section on probabilistic techniques, which compares transition density with signal probability and BDD methods
- Farid N. Najm, Low-pass filter for computing the transition density in digital circuits, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 13(9), 1123 to 1131, September 1994, the filtering of short pulses by gates with inertial delay
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 G6GC4V Edit this page History Report an error Markdown