Algorithm Search⌘K

Techniqueresearch

Positive equality

Also called Bryant-German-Velev positive equality.

Bryant, German and Velev's reduction of EUF formulas that gives distinct constants to terms used only in positive equations, which makes processor verification fast.

Positive equality is a way to decide validity of formulas in the logic of equality with uninterpreted functions (EUF) much faster when most equations occur only positively. Bryant, German and Velev (2001) noticed that in the formulas of Burch-Dill flushing, the data values of a processor are compared for equality only in the final, positive check, while register identifiers and control values also appear in negated equations and in the conditions of if-then-else terms. They split the function symbols in two classes. A p-function symbol is used only in positive equations, and a g-function symbol is used in general. Their central theorem says that a formula in which the p-symbols occur only positively is valid exactly when it is true in the maximally diverse interpretations, where terms of p-symbols are equal only when functional consistency forces it. After the function applications are removed, each p-variable can therefore take a fixed constant, distinct from every other value, and it needs no Boolean variables at all. Only the g-variables are encoded, so the propositional formula that a SAT or BDD tool gets is much smaller.

In plain words

To prove an equation about a processor, you must check every way the values in it can be equal or different. With many values this is a huge number of cases.

Look at how each value is used. Some values are only ever compared at the end, in a check that says "these two must be equal". Making two such values equal by chance can only help that check succeed. So the hardest case for the check is the one where all those values are different, unless the circuit itself forces them to be equal. You can give each of them its own fixed constant and stop treating it as an unknown.

Other values are compared inside the logic, for example a register number that selects a bypass. Those stay unknown and are encoded with Boolean variables. In processor formulas most values are data, so most unknowns disappear.

When it applies

  • The input is a formula FtopF_{\mathrm{top}} of EUF: domain variables, function and predicate applications, if-then-else terms ITE(G,T1,T2)\mathrm{ITE}(G, T_1, T_2), equations, propositional variables, ¬\neg, ∧\wedge and ∨\vee. The question is whether FtopF_{\mathrm{top}} is universally valid: true for every nonempty domain and every interpretation of the symbols. A domain variable is a function symbol of arity 0.
  • FtopF_{\mathrm{top}} is in negation normal form, so ¬\neg is applied only to equations and predicate applications. Any formula can be put in this form with De Morgan's laws.
  • Let Φ\Phi and Θ\Theta be the sets of syntactically distinct formulas and terms of FtopF_{\mathrm{top}}. The negative formulas Φ−⊆Φ\Phi^- \subseteq \Phi form the smallest set that contains FF for every ¬F\neg F in Φ\Phi, contains the condition FF of every ITE(F,T1,T2)\mathrm{ITE}(F, T_1, T_2) in Θ\Theta, and contains F1F_1 and F2F_2 whenever it contains F1∧F2F_1 \wedge F_2 or F1∨F2F_1 \vee F_2. The negative terms Θ−⊆Θ\Theta^- \subseteq \Theta form the smallest set that contains T1T_1 and T2T_2 for every equation T1=T2T_1 = T_2 in Φ−\Phi^-, and T1T_1 and T2T_2 for every ITE(F,T1,T2)\mathrm{ITE}(F, T_1, T_2) in Θ−\Theta^-.
  • A function symbol ff is in Fg\mathcal{F}_g if some term f(T1,…,Tk)f(T_1, \ldots, T_k) is in Θ−\Theta^-, and in Fp\mathcal{F}_p otherwise. A symbol does not become a g-symbol because its applications appear as arguments of other applications: arguments may be p-terms. Theorem 1 of Bryant, German and Velev says that FtopF_{\mathrm{top}} can then be parsed as a p-formula of their logic PEUF, with the symbols of Fg\mathcal{F}_g as g-symbols and those of Fp\mathcal{F}_p as p-symbols.
  • The technique pays off when Fp\mathcal{F}_p is large. In Burch-Dill formulas, the data values, the ALU and the results are usually p-symbols, while register identifiers, which are compared in bypass and stall logic, are g-symbols.

Maximally diverse interpretations. For an interpretation II, write T1≈IT2T_1 \approx_I T_2 when I[T1]=I[T2]I[T_1] = I[T_2]. Let Σ\Sigma be a set of function symbols of FF. The interpretation II is diverse for FF with respect to Σ\Sigma if, for every function application term T1=f(T1,1,…,T1,k)T_1 = f(T_{1,1}, \ldots, T_{1,k}) of FF with f∈Σf \in \Sigma, T1≈IT2T_1 \approx_I T_2 holds for a function application term T2T_2 of FF only when T2=f(T2,1,…,T2,k)T_2 = f(T_{2,1}, \ldots, T_{2,k}) has the same symbol and T1,i≈IT2,iT_{1,i} \approx_I T_{2,i} for all ii. It is maximally diverse if it is diverse with respect to the set Σp(F)\Sigma_p(F) of all p-function symbols of FF. So a p-application equals another term only when functional consistency forces it.

Theorem 2 (Bryant, German and Velev). A p-formula FF is universally valid if and only if it is true in all maximally diverse interpretations.

The template

  1. POSITIVE-EQUALITY(F_top)
  2. 1F ← the negation normal form of F_top
  3. 2compute the negative formulas Φ⁻ and the negative terms Θ⁻ of F
  4. 3F_g ← symbols with an application in Θ⁻; F_p ← all other function symbols
  5. 4F* ← F with every function application replaced by nested ITE terms over fresh domain variables, innermost applications first
  6. 5P ← the fresh variables of the symbols in F_p, and the domain variables in F_p
  7. 6give each variable in P its own fixed constant, distinct from all other values
  8. 7encode equations between the other domain variables with Boolean variables
  9. 8return whether the propositional formula from F* is a tautology, by SAT or BDDs

Line L4 is the function elimination of Bryant, German and Velev. Let f(T1),…,f(Tn)f(T_1), \ldots, f(T_n) be the applications of a symbol ff, in an order where each argument has already been rewritten. Each application gets a fresh variable vf,iv_{f,i}, and the ii-th application becomes

ITE(Ti=T1, vf,1, ITE(Ti=T2, vf,2, ⋯ ITE(Ti=Ti−1, vf,i−1, vf,i))),\mathrm{ITE}\bigl(T_i = T_1,\ v_{f,1},\ \mathrm{ITE}\bigl(T_i = T_2,\ v_{f,2},\ \cdots\ \mathrm{ITE}(T_i = T_{i-1},\ v_{f,i-1},\ v_{f,i})\bigr)\bigr),

where Ti=TjT_i = T_j means equality of all arguments. The result F∗F^* has only domain variables, and it is valid exactly when FF is (their Theorem 3). It keeps functional consistency by construction: equal arguments select the same variable. The new equations between arguments sit in ITE conditions, which are negative positions of F∗F^*. Even so, Theorem 4 of the paper says that FF is valid exactly when F∗F^* is true in every interpretation that is diverse with respect to the fresh variables of the p-symbols, so line L5 takes the polarity from FF, not from F∗F^*. Corollary 1 then allows the fixed constants of line L6, taken from a set disjoint from the values of the g-variables. Lines L7 and L8 are any propositional encoding of the remaining equations; Theorem 5 of the paper treats two of them.

Proof of a small case. The direction from validity to truth in the maximally diverse interpretations is immediate. For the other direction, here is a complete proof for p-formulas in which every function symbol is a domain variable. ITE terms, propositional variables and predicate symbols may occur. The general proof is Lemmas 1 and 2 of the paper. Lemma 1 splits one equivalence class of a not maximally diverse interpretation without making the formula true, and Lemma 2 repeats this, which ends because a partition of the finite term set can be properly refined only finitely often.

Let FF be such a p-formula, true in all maximally diverse interpretations, and let JJ be any interpretation over a domain DD. Take a fresh value zv∉Dz_v \notin D for each p-variable vv, and let D′=D∪{zv}D' = D \cup \{z_v\}. Let τ:D′→D\tau: D' \to D map zvz_v to J(v)J(v) and fix DD. Define J′J' over D′D': J′(v)=zvJ'(v) = z_v for each p-variable, J′(u)=J(u)J'(u) = J(u) for each g-variable and each propositional variable, and J′(p)(d1,…,dk)=J(p)(τ(d1),…,τ(dk))J'(p)(d_1, \ldots, d_k) = J(p)(\tau(d_1), \ldots, \tau(d_k)) for each predicate symbol. We show, by induction on the PEUF syntax:

  1. τ(J′[T])=J[T]\tau(J'[T]) = J[T] for every term TT, and J′[T]=J[T]J'[T] = J[T] for every g-term.
  2. J′[G]=J[G]J'[G] = J[G] for every g-formula GG.
  3. J′[P]J'[P] implies J[P]J[P] for every p-formula PP.

For a variable, (1) holds by the definition of J′J', and a g-term variable is a g-variable. For ITE(G,T1,T2)\mathrm{ITE}(G, T_1, T_2), the condition GG is a g-formula, so by (2) both interpretations pick the same branch, and (1) passes up from that branch. A g-formula is an equation of g-terms, a predicate application, a propositional variable, or a Boolean combination of g-formulas with ¬\neg, ∧\wedge, ∨\vee. Equations of g-terms keep their value by (1). For a predicate, J′(p)(J′[T1],…)=J(p)(τ(J′[T1]),…)=J(p)(J[T1],…)J'(p)(J'[T_1], \ldots) = J(p)(\tau(J'[T_1]), \ldots) = J(p)(J[T_1], \ldots) by (1). The rest is a Boolean combination of equal values, so (2) holds. A p-formula is a g-formula, an equation of p-terms, or a combination of p-formulas with ∧\wedge and ∨\vee only. For an equation, J′[T1]=J′[T2]J'[T_1] = J'[T_2] gives τ(J′[T1])=τ(J′[T2])\tau(J'[T_1]) = \tau(J'[T_2]), which is J[T1]=J[T2]J[T_1] = J[T_2] by (1). ∧\wedge and ∨\vee are monotone, so (3) passes up. This proves the three claims.

J′J' is maximally diverse. The value of a term under J′J' is the value of the variable that its ITE conditions select, so J′[T]=zvJ'[T] = z_v only when TT is vv itself, and a p-variable is equal to no other variable term. So J′[F]J'[F] is true, and by (3) J[F]J[F] is true. As JJ was arbitrary, FF is valid. □\square

The proof also shows why polarity matters. Claim (3) is only an implication, so it survives ∧\wedge and ∨\vee but not ¬\neg and not ITE conditions. That is why p-terms may appear only in positive equations.

Example. The running example of the paper is

Feg=¬(x=y)∨h(g(x),g(g(x)))=h(g(y),g(g(x))).F_{\mathrm{eg}} = \neg(x = y) \vee h\bigl(g(x), g(g(x))\bigr) = h\bigl(g(y), g(g(x))\bigr).

The equation x=yx = y is negated, so xx and yy are g-symbols. The symbols gg and hh occur only in the positive equation and in arguments, so they are p-symbols. The formula has seven function application terms: xx, yy, g1=g(x)g_1 = g(x), g2=g(y)g_2 = g(y), g3=g(g(x))g_3 = g(g(x)), h1=h(g1,g3)h_1 = h(g_1, g_3), h2=h(g2,g3)h_2 = h(g_2, g_3). There are 877 ways to partition seven terms, the Bell number B7B_7, and 384 of them are functionally consistent. Only two come from maximally diverse interpretations: D1, where all seven terms are different, and D2, with classes {x,y},{g1,g2},{g3},{h1,h2}\{x, y\}, \{g_1, g_2\}, \{g_3\}, \{h_1, h_2\}. In D2, x=yx = y forces g1=g2g_1 = g_2, which forces h1=h2h_1 = h_2. FegF_{\mathrm{eg}} is true in D1 because x≠yx \ne y, and true in D2 because h1=h2h_1 = h_2. By Theorem 2 it is valid. (These counts were checked by enumeration of all 877 partitions while writing this page.)

The same check through lines L4 to L8: eliminate gg in the order g(x),g(y),g(g(x))g(x), g(y), g(g(x)) and hh in the order h1,h2h_1, h_2:

term after elimination with vg,1,vg,2,vg,3v_{g,1}, v_{g,2}, v_{g,3} distinct constants
g(x)g(x) vg,1v_{g,1} vg,1v_{g,1}
g(y)g(y) ITE(y=x,vg,1,vg,2)\mathrm{ITE}(y = x, v_{g,1}, v_{g,2}) ITE(e,vg,1,vg,2)\mathrm{ITE}(e, v_{g,1}, v_{g,2})
g(g(x))g(g(x)) ITE(vg,1=x,vg,1,ITE(vg,1=y,vg,2,vg,3))\mathrm{ITE}(v_{g,1} = x, v_{g,1}, \mathrm{ITE}(v_{g,1} = y, v_{g,2}, v_{g,3})) vg,3v_{g,3}, as constants differ from g-values
h1h_1 vh,1v_{h,1} vh,1v_{h,1}
h2h_2 ITE(g^2=vg,1∧g^3=g^3,vh,1,vh,2)\mathrm{ITE}(\hat g_2 = v_{g,1} \wedge \hat g_3 = \hat g_3, v_{h,1}, v_{h,2}) ITE(e,vh,1,vh,2)\mathrm{ITE}(e, v_{h,1}, v_{h,2})

Here g^2\hat g_2 and g^3\hat g_3 are the rewritten forms of g(y)g(y) and g(g(x))g(g(x)), and ee is the one Boolean variable for x=yx = y. With the constants, g^2=vg,1\hat g_2 = v_{g,1} is ITE(e,vg,1,vg,2)=vg,1\mathrm{ITE}(e, v_{g,1}, v_{g,2}) = v_{g,1}, which is ee. The formula becomes ¬e∨vh,1=ITE(e,vh,1,vh,2)\neg e \vee v_{h,1} = \mathrm{ITE}(e, v_{h,1}, v_{h,2}), which is ¬e∨e\neg e \vee e, a tautology. Without positive equality, the five fresh variables and x,yx, y would all be encoded, with equations among them.

Cost. Line L4 adds, for a symbol with nfn_f applications of arity kk, at most nf(nf−1)/2n_f (n_f - 1) / 2 argument comparisons of kk equations each, so F∗F^* has size O(∣F∣+∑fk nf2)O(|F| + \sum_f k \, n_f^2) with shared subterms. A formula with mm domain variables only is valid exactly when it is valid over a domain of mm values, because a falsifying interpretation uses at most mm values and can be cut down to them. So without positive equality the mm variables need m⌈log⁡2m⌉m \lceil \log_2 m \rceil Boolean variables in a binary encoding, or m(m−1)/2m(m-1)/2 variables eije_{ij} for the equations, plus constraints for transitivity. With positive equality the p-variables need none, and only the mgm_g g-variables are encoded. Validity of EUF stays coNP-complete, so the worst case does not change. The gain is measured, not proved. Bryant, German and Velev report experiments on pipelined processor models in which the reduction makes the propositional problem much smaller and faster to solve than encodings that treat every variable as general.

Classic examples

  • Burch-Dill formulas. The commuting diagram of Burch-Dill flushing compares the register files of the two routes in one positive equation. The data terms and the uninterpreted ALU are p-symbols. Positive equality made these checks scale to larger pipelines than direct EUF procedures could handle.
  • Ackermann's reduction. Ackermannization removes function applications with functional consistency constraints Ti=Tj⇒vf,i=vf,jT_i = T_j \Rightarrow v_{f,i} = v_{f,j}. These constraints put the fresh variables on both sides of an implication, that is in negative equations, so every variable becomes general. The nested ITE scheme of line L4 keeps the p-variables positive. This is why Bryant, German and Velev use it.
  • Eager SMT encodings. Eager encodings of equality logic to propositional logic, with small domains or eije_{ij} variables and transitivity constraints, are the back end of lines L7 and L8. Positive equality shrinks their input before they start.
  • Lazy procedures. Congruence closure inside a lazy SMT solver decides the same formulas without any encoding, and does not need the polarity split.

Variations

  • Only part of the polarity. A symbol with some applications in negative positions is a g-symbol for all its applications in the basic method. A finer split classifies application terms, not symbols. Theorem 2 is stated for symbols.
  • Fixed constants versus diverse interpretations. Theorem 2 quantifies over all maximally diverse interpretations. Corollary 1 of the paper fixes the values of the p-variables to distinct constants outside the domain of the g-variables, which is what a propositional encoding needs.
  • Memories. Memories modeled with uninterpreted read and write functions put address comparisons in ITE conditions, so addresses are g-terms while the stored data can stay p-terms.
  • BDDs or SAT. The propositional formula of line L8 can be checked with BDDs or with a CDCL SAT solver on its negation.

Pitfalls

  • A g-term treated as a p-term is unsound. ¬(x=y)\neg(x = y) is not valid, but with xx and yy given distinct constants it becomes true. The classification of line L3 must use every negative position, including ITE conditions and equations under ¬\neg after the formula is in negation normal form.
  • A p-term treated as a g-term is only slow. Every interpretation with fixed p-constants is an interpretation, so encoding more variables as general never gives a wrong answer.
  • Shared subterms. Θ\Theta holds syntactically distinct terms. A term that occurs once positively and once in a negative equation is in Θ−\Theta^-, and its symbol is a g-symbol everywhere.
  • The order of elimination. Line L4 needs the arguments of an application rewritten before the application itself, so nested applications such as g(g(x))g(g(x)) refer to the fresh variable of the inner one.
  • Algebraic facts. Like all EUF methods, positive equality proves only what holds for every interpretation. A design that relies on ADD(a,b)=ADD(b,a)\mathrm{ADD}(a, b) = \mathrm{ADD}(b, a) fails unless the fact is added as an axiom, and an axiom with equations in its premise changes the polarity of the terms in it.

Exercises

  1. Classify the symbols of ¬(a=b)∨f(a)=f(b)\neg(a = b) \vee f(a) = f(b), and show that the formula is valid by checking its maximally diverse interpretations.
  2. Give a formula in which a symbol has one application in a negative equation and one only in positive ones. What does the basic method do, and why is it sound?
  3. Extend the small-case proof to function symbols of arity 1 when every application has a domain variable as its argument. Which step of Lemma 1 of the paper do you need?

References

  1. R. E. Bryant, S. German and M. N. Velev, Processor verification using efficient reductions of the logic of uninterpreted functions to propositional logic, ACM Transactions on Computational Logic 2(1), 93 to 134, 2001, Section 3 (the PEUF syntax of Figure 2, the sets of negative formulas and terms, Theorem 1 on parsing, diverse and maximally diverse interpretations, Theorem 2 with Lemmas 1 and 2), Section 4 (function elimination by nested ITE terms, Theorems 3 and 4, Corollary 1) and Section 5 (propositional encodings, Theorem 5)
  2. R. E. Bryant, S. German and M. N. Velev, Processor verification using efficient reductions of the logic of uninterpreted functions to propositional logic, technical report CMU-CS-99-115, 1999, the preprint of the journal paper, with the running example F_eg, Table 2 and the counts 877 and 384 in Section 3.3
  3. J. R. Burch and D. L. Dill, Automatic verification of pipelined microprocessor control, Computer Aided Verification (CAV 1994), LNCS 818, 68 to 80, 1994, the EUF formulas of pipelined processors that positive equality was made to decide

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.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW3 standard
  • five exercises