13.07.2015 Views

paper pdf - Lab for Automated Reasoning and Analysis - LARA

paper pdf - Lab for Automated Reasoning and Analysis - LARA

paper pdf - Lab for Automated Reasoning and Analysis - LARA

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Structural Subtyping of Non-Recursive Types is DecidableViktor Kuncak <strong>and</strong> Martin Rinard<strong>Lab</strong>oratory <strong>for</strong> Computer ScienceMassachusetts Institute of TechnologyCambridge, MA 02139, USA{vkuncak, rinard}@lcs.mit.eduAbstractWe show that the first-order theory of structural subtypingof non-recursive types is decidable, as a consequence ofa more general result on the decidability of term powers ofdecidable theories.Let Σ be a language consisting of function symbols <strong>and</strong>let C (with a finite or infinite domain C) be an L-structurewhere L is a language consisting of relation symbols. Weintroduce the notion of Σ-term-power of the structure C,denoted P Σ (C). The domain of P Σ (C) is the set of Σ-termsover the set C. P Σ (C) has one term algebra operation <strong>for</strong>each f ∈ Σ, <strong>and</strong> one relation <strong>for</strong> each r ∈ L defined bylifting operations of C to terms over C.We extend quantifier elimination <strong>for</strong> term algebras <strong>and</strong>apply the Feferman-Vaught technique <strong>for</strong> quantifier eliminationin products to obtain the following result. Let K bea family of L-structures <strong>and</strong> K P the family of their Σ-termpowers.Then the validity of any closed <strong>for</strong>mula F on K Pcan be effectively reduced to the validity of some closed <strong>for</strong>mulaq(F) on K.Our result implies the decidability of the first-order theoryof structural subtyping of non-recursive types with covariantconstructors, <strong>and</strong> the construction generalizes tocontravariant constructors as well.1. IntroductionIn this <strong>paper</strong> we show that the first-order theory of structuralsubtyping constraints <strong>for</strong> non-recursive types is decidable.We show this result as a consequence of a more generalresult on the decidability of term powers of decidabletheories, which we show using quantifier elimination.Subtyping Constraints. Subtyping constraints are an importanttechnique <strong>for</strong> checking <strong>and</strong> inferring program prop-∗ Appears in the Proceedings of the Eighteenth Annual IEEE Symposiumon Logic in Computer Science, Ottawa, Canada, June 2003. Formore in<strong>for</strong>mation, seewww.mit.edu/∼vkuncak/<strong>paper</strong>s/SubtypingDecidableLICSerties, used both in type systems <strong>and</strong> program analyses. Thestudy of subtyping constraints is there<strong>for</strong>e important <strong>for</strong>developing techniques that increase the reliability of programs.Subtyping was introduced through the subsumption rulein [29]. [4, 24, 21] treat subtyping in the presence of recursivetypes. [49] shows that terms typable in a system withstructural subtyping denote terminating computations. [12]treats intersection types in ML in the presence of computationaleffects. [15] presents an extension of ML that allowsa more precise typing of programs than the st<strong>and</strong>ard MLtype system. [34] shows the equivalence of non-structuralsubtyping <strong>and</strong> flow-analysis. Set constraints are related tothe subtyping constraints <strong>and</strong> <strong>for</strong>m the basis of several programanalyses [2, 1, 7, 8, 5, 17].The applications of type systems with subtyping havemotivated the study of the complexity <strong>and</strong> the decidabilityof the subtyping constraints. [19] shows that typabilityis equivalent to the satisfiability of a conjunction of atomic<strong>for</strong>mulas in the language of structural subtyping constraints.[16] shows that the satisfiability <strong>for</strong> structural subtypingover an arbitrary structure of base types is in PSPACE. [45]shows that if the ordering on primitive types has the <strong>for</strong>m of“crowns”, then the satisfiability is PSPACE hard. The need<strong>for</strong> efficient h<strong>and</strong>ling of constraints arising from type inference,<strong>and</strong> the need <strong>for</strong> presenting results of type inference inhuman-readable <strong>for</strong>m led the researchers to ask more generalproblems about subtyping constraints [35, 39]. [18]studies the entailment problem <strong>for</strong> structural subtyping <strong>and</strong>shows that if the ordering on the primitive types is a lattice,then the entailment is coNP complete. Because themore complicated notions of subtyping involve quantifiers[47, 42], it is natural to consider the decidability <strong>and</strong> thecomplexity of the full first-order theory of subtyping constraints.[32] studies the complexity <strong>and</strong> decidability propertiesof feature tree constraints with subsumption, which correspondclosely to subtyping constraints <strong>and</strong> have applicationsin constraint logic programming [3] <strong>and</strong> computa-


tional linguistics [37]. [32] shows that the first-order theoryof subtyping constraints of feature trees is undecidable<strong>and</strong> that the existential entailment problem is PSPACEcomplete.The first-order theory of non-structural subtypingconstraints has been shown to be undecidable [42]. Inthis <strong>paper</strong> we show that the first-order theory of structuralsubtyping of non-recursive types is decidable.This problem was left open in [42]. [42] shows thedecidability of the first-order theory of non-structural subtyping<strong>for</strong> the special cases of one unary constructor symbol(where the problem is solved using tree automata techniques),as well as <strong>for</strong> the special case of one constant symbol(where the problem reduces to the decidability of termalgebras).Contribution. The main contribution of this <strong>paper</strong> is aproof that a term power of a structure with a decidable firstordertheory is a structure with a decidable first-order theory.This result directly implies that the first-order theory ofstructural subtyping of non-recursive types is decidable. Inaddition, we believe that the decidability of term powers isof general interest <strong>and</strong> may be useful <strong>for</strong> constructing decisionprocedures in automated theorem proving. The complexityof the decidability problem <strong>for</strong> term powers is nonelementarybecause term powers extend term algebras. Thenon-elementary bound applies to term algebras as a consequenceof the lower bound on the theory of pairing functions[14], see also [11].Previous Quantifier Elimination Results. We show ourdecidability result using quantifier elimination. Quantifierelimination [20, Section 2.7] is a fruitful technique that hasbeen used to show decidability <strong>and</strong> classification of booleanalgebras [40, 44], Presburger arithmetic [36], decidability ofproducts [30, 13], [28, Chapter 12], <strong>and</strong> algebraically closedfields [43]. Directly relevant to our work are quantifiereliminationtechniques <strong>for</strong> term algebras [28, Chapter 23],[27, 41]. Several extensions of term algebras have beenshown decidable using quantifier elimination. [9] gives aterminating term rewriting system <strong>for</strong> quantifier eliminationin term algebras with membership constraints, [38] givesquantifier elimination <strong>for</strong> term algebras with queues, [6]presents quantifier elimination <strong>for</strong> the first-order theory offeature trees with arity predicates. [46] shows the decidabilityof any feature tree structure whose edge labels areelements of a decidable structure, <strong>and</strong> [48] shows the decidabilityof the monadic second-order theory of an infinitebinary tree whose edges come from a structure with a decidablemonadic second-order theory. Compared to structuresin [46], term powers allow the additional lifted relationsbetween trees, which per<strong>for</strong>m a global comparison ofall leaves in a tree. It may be possible to combine our techniquewith [46] to obtain a family of decidable structuresparameterized by both the edge label theory <strong>and</strong> the leaf theory.The main difficulty in applying the result of [48] to thedecidability of the full first-order theory of structural subtypingstems from the need to simultaneously represent 1)selector operations on trees (which require operations thatmanipulate the initial segments of paths in a tree) <strong>and</strong> 2) theprefix-closure property of the tree domain (which requiresoperations that manipulate the terminal segment of paths ina tree), see [31], [25, Section 7].Preliminaries. If A is a set, write |A| to denote the cardinalityof A. An L-structure (model) is a set together withfunctions <strong>and</strong> relations interpreting the language L. If Sis an L-structure <strong>and</strong> r ∈ L a function or relation symbol,write ar(r) to denote the arity of r. (Arity is a nonnegativeinteger.) Write r S to denote the interpretation ofr in structure S. An L-<strong>for</strong>mula is a first-order <strong>for</strong>mula in thelanguage L. A sentence is a closed <strong>for</strong>mula. If K is a familyof L-structures, the theory of K is the set of all L-sentencesthat are true in all structures S ∈ K. If F is a sentence, thenF K = true if F is in the theory of K <strong>and</strong> F K = falseotherwise. The notation 〈E i 〉 k i denotes the list E 1, . . . , E k(if k is omitted, it is understood from the context).1.1. Structural Subtyping <strong>and</strong> Σ-Term-PowerWe introduce the notion of the Σ-term-power of somestructure C as a generalization of the structure that arises instructural subtyping.We represent primitive types in structural subtyping asan L C -structure C with the carrier C. We call C the basestructure. We assume that L C contains only relation symbolsbecause functions <strong>and</strong> constants can be represented asrelations.We represent type constructors as free operations in theterm algebra with a finite signature Σ. Because we representthe primitive types as elements of C, we do not needconstants in Σ, so we assume ar(f) ≥ 1 <strong>for</strong> each f ∈ Σ.Be<strong>for</strong>e defining term powers, we review the notion of afinite power of a C structure, which is a special case of directproducts of structures [20, Section 9.1, Page 413].Definition 1 (Finite Power) Let m > 0 be a positive integer<strong>and</strong> I m = {0, . . .,m − 1}. The structure C m is definedas follows. The domain of C m is the set C Im of all totalfunctions from I m to C. Each relation r ∈ L C is interpretedbyr Cm (〈t j 〉 j ) = ({i | r C (〈t j (i)〉 j )} = I m )The notion of term power is the central notion of this <strong>paper</strong>.Definition 2 (Term Power) The Σ-term-power of C is astructure P = P Σ (C), defined as follows. Let Σ ′ = Σ ∪ C.2


The domain of P is the set P of finite ground Σ ′ -terms,where we let ar(c) = 0 <strong>for</strong> c ∈ C.The structure P has the language L P = Σ ∪ L C ∪{Is PRI }. A constructor f ∈ Σ is interpreted in P as in thefree term algebra:f P (〈t j 〉 j ) = f(〈t j 〉 j )If r ∈ L C with ar(r) = n then r P is the least relation ρsuch that:1. if r C (〈c j 〉 n j ) then ρ(〈c j〉 n j )2. if ρ(〈t ij 〉 n j ) <strong>for</strong> all i where 1 ≤ i ≤ k, <strong>and</strong> ar(f) = kthenρ(〈f(〈t ij 〉 k i ) n j 〉)Is PRI is a unary relation symbol interpreted by<strong>for</strong> all p ∈ P .Is PRI P (p) ⇐⇒ p ∈ CThe reason <strong>for</strong> introducing Is PRI is that we allow C to beinfinite, but we keep L P finite. If there is a need to identifyexplicitly some elements of C as constants, we representthem as some of the unary relations r ∈ L C . Note furtherthat if F is a L C -<strong>for</strong>mula <strong>and</strong> F ′ results from F by replacingquantifiers with quantifiers bounded by the Is PRI predicate,then F C η = F ′ P η <strong>for</strong> every valuation η of C.2. The Decidability ResultThe main result of this <strong>paper</strong> is the following Theorem 3,which states the existence of a quantifier-elimination algorithm<strong>for</strong> term powers that is uni<strong>for</strong>m with respect to thestructure C.Theorem 3 Let L C be a language consisting of relationsymbols, Σ a language consisting of function symbols, <strong>and</strong>L P the language of Σ-term-powers of L C -structures. Thereexists a quantifier-elimination algorithm q mapping L P -sentences to L C -sentences such that <strong>for</strong> every structure Cin the language L C <strong>and</strong> <strong>for</strong> every L P -sentence FF PΣ(C) = q(F) CProposition 4 follows directly from Theorem 3.Proposition 4 Let L C be a language consisting of relationsymbols, Σ a language consisting of function symbols, <strong>and</strong>L P the language of Σ-term-powers of L-structures. Thereexists a quantifier-elimination algorithm q mapping L P -sentences to L C -sentences with the following property. LetK be a family of L C structures <strong>and</strong>K P = {P Σ (C) | C ∈ K}the family of Σ-term-powers of structures in K.F KP = q(F) K <strong>for</strong> every L P -sentence F .ThenThe following Corollary 5 captures the consequence of Theorem3 <strong>for</strong> the theory of structural subtyping, it follows fromthe fact that the structure C = 〈C, ≤〉 <strong>for</strong> finite C <strong>and</strong> anybinary relation ≤ ⊆ C 2 is decidable.Corollary 5 Let C be a finite set of primitive types <strong>and</strong>≤ a binary relation on C representing an order on primitivetypes. Let Σ be a finite set of covariant constructors.Then the first-order theory of structural subtyping of nonrecursivetypes built from elements of C as constants usingconstructors in Σ is decidable.Our technique can be generalized to h<strong>and</strong>le contravariantconstructors as well, see [25, Section 5.5]. The remainderof this <strong>paper</strong> sketches the proof of Theorem 3. Whenreading the proof the reader may find it useful to comparehow our technique works in two special cases: termalgebras [25, Section 3.4] <strong>and</strong> structural subtyping withtwo primitive types [25, Section 4]. In the case of structuralsubtyping with two primitive types it suffices to usequantifier-elimination <strong>for</strong> Boolean algebras [40] instead ofthe Feferman-Vaught theorem [30, 13].2.1. Proof PlanOur proof uses two main ideas.The first idea is to extend P into the extended termpower structure P E . The domain of the new structure P Eis inspired by the observation that if r is a partial orderwith a least element, then the relation t 1 ∼ t 2 definedby ∃t 0 .r P (t 0 , t 1 ) ∧ r P (t 0 , t 2 ) is a congruence relationon P with respect to the constructor operations f P <strong>for</strong>f ∈ Σ. Like [45, Page 313], we call the ∼ equivalenceclasses shapes. A shape is an abstraction of a term obtainedby throwing away the in<strong>for</strong>mation about the constants occurringwithin the term, e.g. f(a, f(a, a)) <strong>and</strong> f(a, f(b, a))both have the shape f s (c s , f s (c s , c s )). We introduce shapesas explicit elements of P E , <strong>and</strong> introduce into the languageof P E the homomorphism sh mapping terms to theirshapes. Our next observation is that elements of the same∼-equivalence class s together with the operations r P <strong>for</strong>r ∈ L C <strong>for</strong>m a finite power structure C m where m is thenumber of constants occurring in the shape s. This allowsus to use the Feferman-Vaught theorem [13, 30] as a stepin our quantifier elimination algorithm. To enable the applicationof the Feferman-Vaught technique, we introduce<strong>for</strong> every n <strong>and</strong> <strong>for</strong> every L C -<strong>for</strong>mula φ(〈x i 〉 n i ) whose variablesare among 〈x i 〉 n i relations (|φ(〈x i 〉 n i )|=k)(s, 〈t i〉 n i )<strong>and</strong> (|φ(〈x i 〉 n i )|≥k)(s, 〈t i〉 n i ) of arity n + 1. We call theserelations cardinality constraints. Our cardinality constraintsgeneralize the relations in [30] by introducing an additionalshape argument s.The second idea of our proof is the choice of canonical<strong>for</strong>mulas, which we call structural base <strong>for</strong>mulas. Structuralbase <strong>for</strong>mulas are existentially quantified conjunctions3


¬, ∧, ∨✲quantifier-free<strong>for</strong>mulaProposition 13✲✛Proposition 25disjunction ofstruct. base <strong>for</strong>mulasFigure 1. Scheme of Quantifier Eliminationof unnested literals that satisfy certain consistency rules.These consistency rules help justify the elimination of aquantified variable u because they ensure that the remainingconjuncts in the structural base <strong>for</strong>mula entail all the relationshipsbetween the remaining variables that are a consequenceof the existence of u.Figure 1 gives a schematic view of our quantifier eliminationalgorithm <strong>for</strong> term powers. On the one h<strong>and</strong>, existentiallyquantifying a structural base <strong>for</strong>mula yields a structuralbase <strong>for</strong>mula because structural base <strong>for</strong>mulas are existentiallyquantified conjunctions. On the other h<strong>and</strong>, theconjunction, disjunction, <strong>and</strong> most importantly, negation,of a quantifier-free <strong>for</strong>mula yields a quantifier-free <strong>for</strong>mula.Quantifier elimination there<strong>for</strong>e reduces to finding an effectivetrans<strong>for</strong>mation from quantifier-free <strong>for</strong>mulas to disjunctionof structural base <strong>for</strong>mulas (Proposition 13), <strong>and</strong> fromstructural base <strong>for</strong>mulas to quantifier-free <strong>for</strong>mulas (Proposition25).Applying Proposition 13, then applying existential quantification<strong>and</strong> then applying Proposition 25 to obtain a quantifierfree <strong>for</strong>mula corresponds to the usual method of eliminatingquantifiers from conjunctions of literals [20, Lemma2.7.4, Page 70]. Dually, applying Proposition 25, negatingthe resulting quantifier-free <strong>for</strong>mula <strong>and</strong> then applyingProposition 13 corresponds to the elimination of quantifieralternations [10, 46], [28, Chapter 23].Several operations in the extended structure P E are naturallyviewed as partial operations. We use Kleene’s threevaluedlogic [23, Page 334], [22] to give a systematic accountof partial functions in quantifier elimination, see [25,Section 2.3]. The use of partial functions <strong>and</strong> the threevaluedlogic in quantifier elimination can be avoided, butwe find that it naturally captures the ideas of our quantifierelimination algorithm.2.2. Extended Term Power StructureFor the purpose of quantifier elimination we define thestructure P E by extending the domain <strong>and</strong> the set of operationsof the term power structure P.The domain of P E is P E = P ∪ P S where P S is the setof shapes defined as follows. Let Σ s = {c s } ∪ {f s | f ∈ Σ}be a set of function symbols such that c s is a fresh constantsymbol with ar(c s ) = 0 <strong>and</strong> f s are fresh distinct constant✛∃symbols with ar(f s ) = ar(f) <strong>for</strong> each f ∈ Σ. The set ofshapes P S is the set of ground Σ s -terms. When referringto elements of P E by term we mean an element of P ; byshape we mean an element of P S . We write X s to denotean entity pertaining to shapes as opposed to terms, so x s , u sdenote variables ranging over shapes, <strong>and</strong> t s denotes termsthat evaluate to shapes.To specify the semantics of cardinality constraints, wedefine the sets φ(x 1 , . . . , x k ) PE (s, t 1 , . . . , t k ). We makea parallel with finite direct products [13, Definition 2.1,Page 63], [20, Section 9.6, Page 458].Definition 6 (Index Sets <strong>for</strong> Products) If φ(〈x j 〉 n j ) is anL C -<strong>for</strong>mula whose variables are among 〈x j 〉 n j <strong>and</strong>〈t j 〉 n j : I m → C, thenφ(〈x j 〉 n j ) Cm (〈t j 〉 n j ) = {i ∈ I m | φ〈x j 〉 n j C (〈t j (i)〉 n j )}Define |φ(〈x j 〉 n j )|=kCm (〈t j 〉 n j ) as|φ(〈x j 〉 n j ) Cm (〈t j 〉 n j )| = k,similarly <strong>for</strong> |φ(〈x j 〉 n j )|≥kCm (〈t j 〉 n j ).In the case of term powers, we replace the notion of an indexi ∈ I m by the notion of a leaf of the tree representing a term,as follows.Definition 7 (Leaf Sets <strong>for</strong> Term Powers) If s is a shape,we call the set of positions of constant c s in s leaves of s,<strong>and</strong> denote this set by leaves(s). We represent each leaf asa sequence of pairs 〈f, i〉 where f is a constructor of arityk <strong>and</strong> 1 ≤ i ≤ k. If l ∈ leaves(s) <strong>and</strong> sh(t) = s, thent[l] denotes the element c ∈ C at position l in term t i.e. ifl = 〈f 1 , i 1 〉...〈f n , i n 〉 thenDefine:t[l] = f n i n(. . . f2 i 2(f1 i 1(t))...)φ(〈x j 〉 n j )PE (s, 〈t j 〉 n j ) ={l ∈ leaves(s) | φ(〈x j 〉 n j )C (〈t j [l]〉 n j ) }Definition 8 (Extended Term Power) The extended termpower structure P E contains term algebra operations onterms <strong>and</strong> shapes (including selector operations <strong>and</strong> testsas in [20, Page 61]), the homomorphism sh, <strong>and</strong> cardinalityconstraint relations |φ|=k <strong>and</strong> |φ|≥k, defined as follows:1. constructors in the term algebra of terms, f ∈ Σf PE (〈t j 〉 k j )=f(〈t j〉 k j );2. selectors in the term algebra of terms,f i PE (f(〈t j 〉 k j )) = t i;3. constructor tests in the term algebra of terms,Is f PE (t) = ∃〈t j 〉 k j . t = f(〈t j〉 k j ),Is PRI PE (t) = (t ∈ C);4


4. constructors in the term algebra of shapes, f s ∈ Σ sf s PE (〈t s j 〉k j ) = fs (〈t s j 〉k j );5. selectors in the term algebra of shapes,f s i PE (f s (〈t s j 〉k j )) = ts i ;6. constructor tests in the term algebra of shapes,Is f s PE (t s ) = ∃〈t s j 〉k j . ts = f s (〈t s j 〉k j );7. the homomorphism mapping terms to shapes suchthat:sh PE (f(〈t j 〉 k j )) =shapified(f)(〈sh PE (t j )〉 k j )where shapified(x)=c s if x ∈ C <strong>and</strong> shapified(f)=f sif f ∈ Σ;8. cardinality constraint relations<strong>and</strong>|φ(〈x j 〉 n j )|=kPE (s, 〈t j 〉 n j ) =|φ(〈x j 〉 n j )PE (s, 〈t j 〉 n j )| = k|φ(〈x j 〉 n j )|≥kPE (s, 〈t j 〉 n j ) =|φ(〈x j 〉 n j )PE (s, 〈t j 〉 n j )|≥kwhere φ(〈x j 〉 n j ) is is a first-order <strong>for</strong>mula over thebase-structure language L C with free variables〈x j 〉 n j , argument s is a shape, arguments 〈t j〉 n j areterms, <strong>and</strong> k is a nonnegative integer constant.The following equations follow from Definition 8 <strong>and</strong> Definition7 <strong>and</strong> can be used as an equivalent alternative definitionof cardinality constraints:|φ(〈x j 〉 n j )PE (c s , 〈c j 〉 n j )| ={ 1, φ(〈xj 〉 n j )C (〈c j 〉 n j )0, ¬φ(〈x j 〉 n j )C (〈c j 〉 n j )|φ(〈x j 〉 n j (f s (〈s )PE i 〉 k i ), 〈f(〈t ij〉 k i )〉n j )|= ∑ ki=1 |φ(〈x j〉 n j (s )PE i , 〈t ij 〉 n j )| (1)We write |φ(〈t j 〉 n j )| s=k as a shorth<strong>and</strong> <strong>for</strong> the atomic<strong>for</strong>mula (|φ(〈x j 〉 n j )|=k)(s, 〈t j〉 n j ), similarly <strong>for</strong>|φ(〈t j 〉 n j )| s≥k. This is more than a notational convenience,see [25] <strong>for</strong> an approach which introduces sets ofleaves as elements of the domain of P E <strong>and</strong> defines a cylindricalgebra interpreted over sets of leaves. The approachin the present <strong>paper</strong> follows [30] in merging the quantifierelimination <strong>for</strong> products <strong>and</strong> quantifier elimination <strong>for</strong>boolean algebras.Some of the operations in P E are partial. f i (t) is definediff Is f (t) holds, fi s(ts ) is defined iff Is f s(t s ) holds.Cardinality constraints |φ(〈t j 〉 n j )| t s=k <strong>and</strong> |φ(〈t j〉 n j )| t s≥kare defined iff ∧ n i=1 sh(t i)=t s holds. We assume that a termevaluates to ⊥ if some term operation is undefined. Partial<strong>and</strong> total operations are strict in ⊥; when a value of atomic<strong>for</strong>mula is undefined it evaluates to undef. Logical operations<strong>and</strong> quantifiers are interpreted as in Kleene’s threevaluedlogic with truth values {false, undef, true}. We saythat a <strong>for</strong>mula is well-defined iff it evaluates to true or false(as opposed to undef) <strong>for</strong> every valuation assigning valuesto free variables. The structure P E has the property thatthe domain of every partial function is expressible as a conjunctionof atomic <strong>for</strong>mulas. This property enables trans<strong>for</strong>mationof each well-defined quantifier-free <strong>for</strong>mula to adisjunction of well-defined conjunctions in Proposition 13,see also [25, Section 2.3].The structure P E is at least as expressive as P becausethe only operations or relations present in P but not in P Eare r P <strong>for</strong> r ∈ L C , <strong>and</strong> we can express r P (t 1 , . . . , t k )ask∧|¬r(〈t j 〉 n j )| sh(t 1)=0 ∧ sh(t i ) = sh(t 1 ) (2)i=2By a quantifier-free <strong>for</strong>mula we mean a <strong>for</strong>mula withoutquantifiers outside cardinality constraints, e.g. the <strong>for</strong>mula|∀x.x ≤ t| x s = k is quantifier-free.We define a subclass of quantifier-free cardinality constraintscalled primitive <strong>for</strong>mulas, denoted prim(φ) <strong>for</strong> everyL C -sentence φ: prim(φ) ≡ |φ| c s = 1. Note thatprim(φ) PΣ(C) = φ C (3)so <strong>for</strong> a given concrete structure C we may replace primitive<strong>for</strong>mulas with true <strong>and</strong> false. We nevertheless retainprimitive <strong>for</strong>mulas throughout the quantifier elimination algorithm.This ensures that our quantifier elimination algorithmis uni<strong>for</strong>m with respect to the base structure C. In thesequel we there<strong>for</strong>e assume some fixed structure C <strong>and</strong> proceedto give a quantifier elimination algorithm that per<strong>for</strong>msequivalence-preserving trans<strong>for</strong>mations with respect to theextended term power P E corresponding to P Σ (C).2.3. Structural Base FormulasOur quantifier-elimination algorithm is centered aroundcertain existentially quantified unnested conjunctions of literals.We call these conjunctions structural base <strong>for</strong>mulas.We first introduce several auxiliary definitions. Letdistinct(u 1 , . . . , u n ) be a shorth<strong>and</strong> <strong>for</strong> ∧ 1≤i


Definition 9 (Base Formula) A base <strong>for</strong>mula with• free term variables x 1 , . . .,x m ;• internal non-parameter term variables u 1 , . . . , u p ;• internal parameter term variables u p+1 , . . . , u p+q ;is a <strong>for</strong>mula of the <strong>for</strong>m:base(u 1 , . . .,u n , x 1 , . . . , x m ) =p∧u i = t i (u 1 , . . . , u n ) ∧i=1∧ distinct(u 1 , . . . , u n )m ∧i=1x i = u jiwhere n = p + q, each t i is a term of the <strong>for</strong>mf(u i1 , . . . , u ik ) <strong>for</strong> some f ∈ Σ, k = ar(f), <strong>and</strong> j :{1, . . ., m} → {1, . . .,n} is a function mapping indicesof free term variables to indices of internal term variables.We require each base <strong>for</strong>mula to satisfy the followingconditions:C1) base does not violate the occur-check [26, 10]:¬(u + baseu) <strong>for</strong> every variable u occurring in base;C2) congruence closure property: there are no two distinctvariables u i <strong>and</strong> u j such that both u i =f(u l1 , . . .,u lk ) <strong>and</strong> u j = f(u l1 , . . .,u lk ) occur asconjuncts in base.The following Lemma 10 is important <strong>for</strong> quantifierelimination in term algebras <strong>and</strong> term powers.Lemma 10 Let β be a base <strong>for</strong>mula of the <strong>for</strong>m∃u 1 , . . .,u p , u p+1 , . . . , u p+q . β 0where u p+1 , . . .,u p+q are parameter variables of β, <strong>and</strong>β 0 is quantifier-free. Let S p+1 , . . . , S p+q be infinite sets ofterms. Then there exists a valuation σ such that β 0 σ =true <strong>and</strong> u i σ ∈ S i <strong>for</strong> p + 1 ≤ i ≤ p + q.The notion of base <strong>for</strong>mula <strong>and</strong> Lemma 10 apply to termsP as well as shapes P S in the structure P E because shapesare also terms over the alphabet Σ s . For brevity we write u ∗<strong>for</strong> an internal shape or term variable, <strong>and</strong> similarly x ∗ <strong>for</strong> afree shape or term variable, t ∗ <strong>for</strong> terms, f ∗ <strong>for</strong> a constructorin the term algebra of terms or shapes, <strong>and</strong> fi ∗ <strong>for</strong> a selectorin the term algebra of terms or shapes.Definition 11 below introduces structural base <strong>for</strong>mulas.The disjunction of structural base <strong>for</strong>mulas can bethought of as a normal <strong>for</strong>m <strong>for</strong> existential <strong>for</strong>mulas interpretedover P E . A structural base <strong>for</strong>mula contains a copyof a base <strong>for</strong>mula <strong>for</strong> shapes (shapeBase), a base <strong>for</strong>mula<strong>for</strong> terms but without term disequalities (termBase), a <strong>for</strong>mulaexpressing mapping of term variables to shape variables(termHom), <strong>and</strong> cardinality constraints on term parameter<strong>and</strong> primitive non-parameter variables of the termbase <strong>for</strong>mula (cardin). A structural base <strong>for</strong>mula containsseveral kinds of variables, classified according to the positionsin which they appear within the structural base <strong>for</strong>mula.Free variables are the free variables of the structuralbase <strong>for</strong>mula; internal variables are the existentially quantifiedvariables. Parameter variables are variables whosetop-level constructor is not specified by the structural base<strong>for</strong>mula, in contrast to non-parameter variables. Primitivenon-parameter term variables denote terms in C, composednon-parameter term variables denote terms in P \ C.Definition 11 (Structural Base Formula)A structural base <strong>for</strong>mula with:• free term variables x 1 , . . . , x m ;• internal composed non-parameter term variablesu 1 , . . .,u r ;• internal primitive non-parameter term variablesu r+1 , . . . , u p ;• internal parameter term variables u p+1 , . . .,u p+q ;• free shape variables x s 1 , . . .,xs m s;• internal non-parameter shape variables u s 1, . . . , u s p s;• internal parameter shape variables u s p s, . . . , us p s +q sis a <strong>for</strong>mula of the <strong>for</strong>m:∃u 1 , . . .,u n , u s 1, . . . , u s n s.shapeBase(u s 1 , . . . , us n s, xs 1 , . . .,xs m s) ∧termBase(u 1 , . . . , u n , x 1 , . . . , x m ) ∧termHom(u 1 , . . .,u n , u s 1 , . . .,us n s) ∧cardin(u r+1 , . . . , u n , u s p s +1 , . . . , us n s)where n = p + q, n s = p s + q s , <strong>and</strong> <strong>for</strong>mulas shapeBase,termBase, termHom, cardin are defined as follows.shapeBase(u s 1 , . . . , us n s, xs 1 , . . . , xs m s) =∧p si=1u s i = t i(u s 1, . . .,u s ms∧ns) ∧ x s i = us j i∧ distinct(u s 1 , . . . , us n )i=1where each t i is a shape term of the <strong>for</strong>m f s (u s i 1, . . . , u s i k)<strong>for</strong> some f ∈ Σ 0 , k = ar(f), <strong>and</strong>j : {1, . . .,m s } → {1, . . ., n s } is a function mappingindices of free shape variables to indices of internal shapevariables.termBase(u 1 , . . . , u n , x 1 , . . . , x m ) =r∧p∧u i = t i (u 1 , . . . , u n ) ∧ Is PRI (u i ) ∧i=1m∧x i = u jii=1i=r+1where each t i is a term of the <strong>for</strong>m f(u i1 , . . . , u ik ) <strong>for</strong>some f ∈ Σ, k = ar(f), <strong>and</strong> j : {1, . . .,m} → {1, . . ., n}6


is a function mapping indices of free term variables toindices of internal term variables.termHom(u 1 , . . .,u n , u s 1 , . . .,us n s) =n ∧i=1sh(u i ) = u s j iwhere j : {1, . . .,n} → {1, . . .,n s } is a function such that{j 1 , . . .,j p } ⊆ {1, . . ., p s } <strong>and</strong>{j p+1 , . . .,j p+q } ⊆ {p s + 1, . . . , p s + q s } (a term variableis a parameter variable iff its shape is a parameter shapevariable).cardin(u r+1 , . . .,u n , u s p s +1 , . . .,us n s) = ψ 1 ∧ · · · ∧ ψ dwhere each ψ i is a cardinality constraint of the <strong>for</strong>mor|φ(u j1 , . . . , u jl )| u s = k|φ(u j1 , . . . , u jl )| u s ≥ kwhere {j 1 , . . . , j l } ⊆ {r + 1, . . .,n} <strong>and</strong> the conjunctsh(u jd ) = u s occurs in termHom <strong>for</strong> 1 ≤ d ≤ l. Werequire each structural base <strong>for</strong>mula to satisfy thefollowing conditions:P0) shapeBase does not violate the occur-check:¬(u s + shapeBase us ) <strong>for</strong> every shape variable u soccurring in shapeBase;P1) congruence closure property <strong>for</strong> shapeBasesub<strong>for</strong>mula: there are no two distinct variables u s i <strong>and</strong>u s j such that both us i = f(us l 1, . . .,u s l k) <strong>and</strong>u s j = f(us l 1, . . .,u s l k) occur as conjuncts in <strong>for</strong>mulashapeBase;P2) congruence closure property <strong>for</strong> termBasesub<strong>for</strong>mula: there are no two distinct variables u i <strong>and</strong>u j such that both u i = f(u l1 , . . .,u lk ) <strong>and</strong>u j = f(u l1 , . . .,u lk ) occur as conjuncts in <strong>for</strong>mulatermBase;P3) homomorphism property of sh: <strong>for</strong> every composednon-parameter term variable u such thatu = f(u i1 , . . . , u ik ) occurs in termBase, if conjunctsh(u) = u s occurs in termHom, then <strong>for</strong> some shapevariables u s j 1, . . . , u s j kterm u s = f s (u s j 1, . . .,u s j k)occurs in shapeBase where f s = shapified(f) <strong>and</strong> <strong>for</strong>every r where 1 ≤ r ≤ k, conjunct sh(u ir ) = u s j roccurs in termHom; furthermore:<strong>for</strong> every primitive non-parameter variable u (i.e. us.t. Is PRI (u) occurs in termBase), conjunct sh(u) = u soccurs in termHom where u s is the shape variablesuch that u s = c s occurs in shapeBase.As a special case, we allow quantifier-free <strong>for</strong>mulas prim(φ)in cardin. Note that ¬(u + termBaseu) <strong>for</strong> each term variableu follows from P0) <strong>and</strong> P3). An immediate consequenceof Definition 11 is the following Proposition 12.Proposition 12 (Quantification of Structural Base) If βis a structural base <strong>for</strong>mula <strong>and</strong> x a free shape or termvariable in β, then there exists a structural structural base<strong>for</strong>mula β 1 equivalent to ∃x.β.For example, if β ≡ ∃u, u s . sh(u)=u s ∧ x=u then ∃x.βis equivalent to ∃u, u s . sh(u)=u s where x=u conjunct wasremoved.We proceed to show that a quantifier-free <strong>for</strong>mula can bewritten as a disjunction of structural base <strong>for</strong>mulas, <strong>and</strong> astructural base <strong>for</strong>mula can be written as a quantifier-free<strong>for</strong>mula.2.4. Conversion to Structural Base FormulasThe conversion to structural base <strong>for</strong>mulas builds on theconversion to disjunctions of well-defined conjunctions ofunnested literals [25, Section 2.3], congruence closure algorithms[33], <strong>and</strong> the equality (1).Proposition 13 (Quantifier-Free to Structural Base)Every well-defined quantifier-free <strong>for</strong>mula φ is equivalenton P E to true, false, or a disjunction of structural base<strong>for</strong>mulas.Proof Sketch. We outline an algorithm <strong>for</strong> converting φinto a disjunction of structural base <strong>for</strong>mulas. Rules <strong>for</strong> per<strong>for</strong>mingthe trans<strong>for</strong>mation are presented in the Appendix.First convert φ into the disjunctive normal <strong>for</strong>m (DNF)using rules DNF. These rules are valid in three-valued logicbecause the three-valued domain is a distributive lattice,¬ is idempotent <strong>and</strong> DeMorgan’s laws hold. For example,¬(Is f (x) ∧ y=f 1 (x)) gets trans<strong>for</strong>med into ¬Is f (x) ∨y≠f 1 (x). The resulting DNF is well-defined, but the individualconjunctions (e.g. y≠f 1 (x)) need not be welldefined.Applying rules WDNF to all conjuncts yields adisjunction of well-defined conjunctions (e.g. y ≠ f 1 (x)becomes Is f (x) ∧ y ≠ f 1 (x)). This trans<strong>for</strong>mation preservesthe equivalence because the starting disjunction waswell-defined, see [25, Section 2.3].The next step converts the <strong>for</strong>mula into the unnested(flat) <strong>for</strong>m by introducing existentially quantified variables<strong>for</strong> subterms <strong>and</strong> free variables, using rules UNF (e.g.x=f(f(y, z), y) becomes ∃u. u=f(y, z) ∧ x=f(u, y)whereas y≠f 1 (x) becomes ∃u.u=f 1 (x) ∧ y≠u). Theresult is a disjunction of well-defined existentially quantifiedconjunctions of unnested literals. Apply rules ELNGto eliminate negations of all atomic <strong>for</strong>mulas except <strong>for</strong>disequalities (e.g. if Σ = {f} then ¬Is f (x) becomesIs PRI (x)). ELNG rules may violate DNF; use DNF rulesagain to reestablish the normal <strong>for</strong>m (this also applies toall subsequent rules that may violate DNF). Eliminateselector functions <strong>and</strong> constructor tests using rules SelEl(e.g. if f is a binary constructor, then ∃u. Is f (x) ∧ u=f 1 (x)7


ecomes ∃u, v 1 , v 2 . x=f(v 1 , v 2 ) ∧ u=v 1 ). The resultcontains only the relation <strong>and</strong> function symbols thatoccur in structural base <strong>for</strong>mulas. Make sure each termvariable has a corresponding shape variable by applyingrules ShpInt. For example, ∃v 1 , v 2 . x=f(v 1 , v 2 )becomes ∃v 1 , v 2 , x s , v1 s, vs 2 . sh(v 1)=v1 s ∧ sh(v 2)=v2 s ∧sh(x)=x s ∧ x=f(v 1 , v 2 ). Next, apply congruenceclosure (CongCl) <strong>and</strong> occur check (OccChk). For example,∃x, u, v 1 , v 2 . x=f(v 1 , v 2 ) ∧ y=f(u, v 2 ) ∧ u=v 1becomes ∃x, u, v 2 . x=f(u, v 2 ) ∧ y=x, whereasx=f(u, v) ∧ u=f(x, v) becomes false. Use HomExprules to ensure that parameter term variables are mapped toparameter shape variables, non-parameter term variablesare mapped to non-parameter shape variables, <strong>and</strong> thatthe homomorphism property P3) of Definition 11 holds.Repeat CongCl <strong>and</strong> OccChk rules if needed. For example,∃v 1 , v 2 , x s , v1 s, vs 2 . sh(v 1)=v1 s ∧ sh(v 2)=v2 s ∧ sh(x)=xs ∧x=f(v 1 , v 2 ) becomes ∃v 1 , v 2 , x s , v1, s v2. s sh(v 1 )=v1 s ∧sh(v 2 )=v2 s ∧ sh(x)=xs ∧ x=f(v 1 , v 2 ) ∧ x s =f s (v1 s, vs 2 ).Eliminate all disequalities between term variables usingthe NEQEl rule, which is justified by the negation of theequivalence:t 1 = t 2 ⇐⇒ sh(t 1 ) = sh(t 2 ) ∧ |t 1 = t 2 | sh(t1) = 0 (4)For example, u≠x ∧ sh(u)=u s ∧ sh(x)=x s becomes((u s ≠x s )∨(u s =x s ∧|u≠x| u s≥1))∧sh(u)=u s ∧sh(x)=x s .Repeat previous stages (e.g. DNF, CongCl, OccChk) ifneeded. Convert all cardinality constraints into constraintson parameter term variables, using CCD rules justifiedby (1), e.g. |u≠v| u s=1 becomes (|u 1 ≠v 1 | u s1=0 ∧|u 2 ≠v 2 | u s2=1) ∨ (|u 1 ≠v 1 | u s1=1 ∧ |u 2 ≠v 2 | u s2=0)in the context of u=f(u 1 , v 1 ) ∧ v=f(v 1 , v 2 ) ∧u s =f s (u s 1 , us 2 ) ∧ sh(u)=sh(v)=us ∧ sh(u 1 )=sh(v 1 )=u s 1 ∧sh(u 2 )=sh(v 2 )=u s 2. Finally, to produce the <strong>for</strong>muladistinct(u s 1 , . . .,us n ) use ShDis to ensure that <strong>for</strong> every twoshape variables x s 1 <strong>and</strong> xs 2 occurring in the conjunctionexactly one of the conjuncts x s 1=x s 2 or x s 1≠x s 2 is present.2.5. Conversion to Quantifier-Free FormulasThe conversion from structural base <strong>for</strong>mulas toquantifier-free <strong>for</strong>mulas is the main phase of our quantifiereliminationalgorithm. We split this conversion into severalstages; Proposition 25 below summarizes the overall conversionprocess.Consider a structural base <strong>for</strong>mula β ≡ ∃ū ∗ . C(¯x ∗ , ū ∗ )with free variables ¯x ∗ <strong>and</strong> internal variables ū ∗ , whereC(¯x ∗ , ū ∗ ) is quantifier-free. C(¯x ∗ , ū ∗ ) defines a relationbetween variables ¯x ∗ , ū ∗ . If this relation has a functionaldependence from the free variables ¯x ∗ to some internal variableu, with a term t(¯x ∗ ) such that C(¯x ∗ , ū ∗ ) |= u = t(¯x ∗ ),then the internal variable u can be replaced by t(¯x ∗ ) <strong>and</strong>the quantification over u can be eliminated. This leads tothe notion of determinations.Definition 14 The set dets of variable determinations of astructural base <strong>for</strong>mula β is the least set S of pairs 〈u ∗ , t ∗ 〉where u ∗ is an internal term or shape variable <strong>and</strong> t ∗ is aterm over the free variables of β, such such that:1. if x ∗ = u ∗ occurs in termBase or shapeBase <strong>for</strong> afree variable x ∗ , then 〈u ∗ , x ∗ 〉 ∈ S;2. if 〈u ∗ , t ∗ 〉 ∈ S <strong>and</strong> u ∗ = f ∗ (u ∗ 1 , . . . , u∗ k) occurs inshapeBase or termBase then{〈u ∗ 1, f1 ∗ (t ∗ )〉, . . . , 〈u ∗ k , f k ∗(t∗ )〉} ⊆ S;3. if {〈u ∗ 1 , t∗ 1 〉, . . . , 〈u∗ k , t∗ k 〉} ⊆ S <strong>and</strong>u ∗ = f ∗ (u ∗ 1, . . . , u ∗ k ) occurs in shapeBase ortermBase then 〈u ∗ , f ∗ (t ∗ 1 , . . .,t∗ k)〉 ∈ S;4. if 〈u, t〉 ∈ S <strong>and</strong> sh(u) = u s occurs in termHom then〈u s , sh(t)〉 ∈ S.Definition 15 An internal variable u ∗ is determined if〈u ∗ , t ∗ 〉 ∈ dets <strong>for</strong> some term t s . An internal variable isundetermined if it is not determined.Lemma 16 follows by induction using Definition 14.Lemma 16 Let β ≡ ∃ū. C(¯x ∗ , ū ∗ ) be a structural base<strong>for</strong>mula. If 〈u ∗ , t ∗ 〉 ∈ dets(β) then C(¯x ∗ , ū ∗ ) |= u ∗ = t ∗ .Corollary 17 Let β ≡ ∃〈u ∗ i 〉 i. C(¯x ∗ , 〈u ∗ i 〉 i) be a structuralbase <strong>for</strong>mula such that each internal variable u ∗ i isdetermined by some term t ∗ i , that is, 〈u∗ i , t∗ i 〉 ∈ dets(β).Then β is equivalent to the well-defined quantifier-free <strong>for</strong>mulaβ ′ ≡ C(¯x ∗ , 〈t ∗ i 〉 i).Proof. By Lemma 16 using the rule∃u.u = t ∧ φ(u) ⇐⇒ φ(t) (5)which holds when the term t is well-defined. If t is notwell-defined, then both β <strong>and</strong> β ′ evaluate to false.Our goal thus reduces to eliminating all undeterminedvariables from a structural base <strong>for</strong>mula. We first show howto eliminate undetermined composed non-parameter termvariables.Lemma 18 Let u be an undetermined composed nonparameterterm variable in a structural base <strong>for</strong>mula βsuch that u is a source i.e. no conjunct of the <strong>for</strong>mu ′ =f(u 1 , . . .,u, . . .,u k ) occurs in termBase. Let β ′ be theresult of removing from β the variable u <strong>and</strong> all conjunctscontaining u. Then β is equivalent to β ′ .8


Proof. The conjunct containing sh(u) = u s in termHomis a consequence of the remaining conjuncts in β, so wemay drop it. The only remaining occurrence of u is in theatomic <strong>for</strong>mula u=f(¯v) of termBase sub<strong>for</strong>mula. Applying(5) there<strong>for</strong>e makes u disappear from β.Corollary 19 (Composed Term Variable Elimination)Dropping all undetermined composed non-parameter termvariables from a structural base <strong>for</strong>mula together with theconjuncts that contain them yields an equivalent structuralbase <strong>for</strong>mula.Proof. If a structural base <strong>for</strong>mula has an undeterminednon-parameter composed term variable, then it has an undeterminednon-parameter composed term variable that is asource. Repeatedly apply Lemma 18 to eliminate all undeterminednon-parameter term variables.Our next goal is to eliminate undetermined primitivenon-parameter term variables <strong>and</strong> undetermined parameterterm variables. The key insight is that these variables arerelated to the determined variables of a structural base <strong>for</strong>mulaonly through the relations that are expressible in theproduct structure of the terms of the same shape. To clarifythe connection with the product-structure, let s ∈ P Sbe a shape <strong>and</strong> P (s) = {t ∈ P | sh(t) = s}. Defineη : P S → C ∗ where C ∗ is the set of finite sequencesof elements from C, as follows: η(c) = c if c ∈ C;η(f(t 1 , . . . , t k )) = η(t 1 ) · . . . · η(t k ) where l 1 · l 2 denotesthe concatenation of sequences l 1 <strong>and</strong> l 2 . Let η s = η| P (s)be the restriction of η to the set P (s) . Let m = |leaves(s)|.Observation 20 The map η s is an isomorphism of the substructureof P with the domain P (s) <strong>and</strong> the finite powerC m . Moreover,|φ(〈x j 〉 n j ) PE (s, 〈t j 〉 n j )| = |φ(〈x j 〉 n j ) Cm (〈η s (t j )〉 n j )|The following is the quantifier-elimination property that impliesFeferman-Vaught theorem [13, 30], [20, Section 9.6,Page 460] <strong>for</strong> the case of finite products.Lemma 21 Let k ≥ 0. Consider a <strong>for</strong>mula α of the <strong>for</strong>mα ≡ ∃u. ∧ pi=1 ψ i where each ψ i is a cardinality constraintof the <strong>for</strong>m (|φ i |=k)(u, 〈u j 〉 n j ) or (|φ i|≥k)(u, 〈u j 〉 n j ). Thenα can be effectively trans<strong>for</strong>med into α ′ where α ′ is a disjunctionof conjunctions of cardinality constraints of the<strong>for</strong>m (|φ ′ i |=k)(〈u j〉 n j ) <strong>and</strong> (|φ′ i |≥k)(〈u j〉 n j ). The result α′is equivalent to α on each finite power C m .Lemma 22 is a direct consequence of Lemma 21 <strong>and</strong> Observation20.Lemma 22 Let k ≥ 0. Consider a <strong>for</strong>mula α of the <strong>for</strong>mα ≡ ∃u. sh(u) = u s ∧ ∧ ni=1 sh(u i) = u s ∧ ∧ pi=1 ψ i<strong>for</strong> some shape variable u s where each ψ i is a cardinalityconstraint of the <strong>for</strong>m (|φ i |=k)(u s , u, 〈u j 〉 n j ) or of the <strong>for</strong>m(|φ i |≥k)(u s , u, 〈u j 〉 n j ). Then α can be effectively trans<strong>for</strong>medinto the <strong>for</strong>mula α ′ which is a disjunction of <strong>for</strong>mulasof the <strong>for</strong>mα ′ j ≡ ∧ ni=1 sh(u i) = u s ∧ ∧ qi=1 ψ′ i,jwhere each ψ ′ i,j is of the <strong>for</strong>m (|φ′ i,j |=k)(us , 〈u j 〉 n j ) or(|φ ′ i,j |≥k)(us , 〈u j 〉 n j ). The resulting <strong>for</strong>mula α′ is equivalentto α on all term powers P E .Lemma 23 (Term Parameter Elimination) Every structuralbase <strong>for</strong>mula β without undetermined composed nonparameterterm variables can be effectively trans<strong>for</strong>medinto an equivalent disjunction of structural base <strong>for</strong>mulaswithout undetermined term variables.Proof. We show how to eliminate undetermined parameterterm variables <strong>and</strong> undetermined primitive non-parameterterm variables from β.Let u be an undetermined parameter term variable or anundetermined primitive non-parameter term variable. If uis a parameter variable then u does not occur in termBasebecause ¬(u + u ′ ) <strong>for</strong> all u ′ , <strong>and</strong> ¬(u ′′ + u) <strong>for</strong> all u ′′since there are no undetermined composed non-parameterterm variables. There<strong>for</strong>e, u occurs only in termHom <strong>and</strong>cardin. If u is a primitive non-parameter term variable, thentermBase contains only one occurrence of u, namely theconjunct Is PRI (u), which is a consequence of the conjunctssh(u) = u s in termHom <strong>and</strong> u s = c s in shapeBase, so wedrop Is PRI (u). In both cases, the resulting <strong>for</strong>mula containsu only in termHom <strong>and</strong> cardin.Let u s be the shape variable such that u s = sh(u) occursin termHom. Let ψ 1 , . . . , ψ p be all conjuncts of cardin thatcontain u. Each ψ i is of the <strong>for</strong>m |φ| u s ≥ k i or |φ| u s = k i<strong>and</strong> <strong>for</strong> each variable u ′ free in φ the conjunct sh(u) = u soccurs in termHom. The structural base <strong>for</strong>mula can there<strong>for</strong>ebe written in the <strong>for</strong>m ∃ū ∗ . φ ∧α where α has the <strong>for</strong>mas in Lemma 22. Applying Lemma 22 we eliminate u. Applyingrules DNF results in a disjunction of structural base<strong>for</strong>mulas. By repeating this process we eliminate all undeterminedparameter term variables <strong>and</strong> undetermined primitivenon-parameter term variables from a structural base<strong>for</strong>mula. Each of the resulting structural base <strong>for</strong>mulas containsno undetermined term variables.Finally, we show how to eliminate the undetermined shapevariables.Lemma 24 (Shape Variable Elimination) Every structuralbase <strong>for</strong>mula β without undetermined term variablescan be effectively trans<strong>for</strong>med into an equivalent disjunctionof structural base <strong>for</strong>mulas without undeterminedvariables.9


Proof Sketch. It remains to eliminate undetermined shapevariables from β. This process is similar to term algebraquantifier elimination [25, Section 3.4]; the key ingredientis Lemma 10, which relies on the fact that undeterminedparameter variables may take on infinitely many values. Wethere<strong>for</strong>e ensure that the conjuncts outside shapeBase donot constrain the undetermined parameter shape variablesto denote the values from a finite set.Consider an undetermined parameter shape variable u s .u s does not occur in termHom, because all term variablesare determined <strong>and</strong> a conjunct u s =sh(u) would implythat u s is determined as well. u s can thus occur onlyin cardin within some cardinality constraint |φ| u s=k or|φ| u s≥k. Moreover, <strong>for</strong>mula φ in each such cardinality constraintis closed: otherwise φ would contain some free termvariable u <strong>and</strong> since all term variables are determined, u swould be determined as well.Let u s denote some shape s. Because φ is a closed <strong>for</strong>mula,|φ| is equal to 0 if φ C =false <strong>and</strong> to the shape sizem = |leaves(s)| if φ C =true. (The fact that closed <strong>for</strong>mulasreduce to the constraints on the domain size appears in[30, Theorem 3.36, Page 13]. In term powers, these constraintsbecome constraints on the size of the shape.) Wetrans<strong>for</strong>m β into the disjunction β 1 ∨ β 2 of base <strong>for</strong>mulaswhere β 1 ≡ β ∧ prim(φ) <strong>and</strong> β 2 ≡ β ∧ prim(¬φ). Constraintsof the <strong>for</strong>m prim(¬φ) ∧ |φ| u s=k reduce to 0=k,we replace them by true if k≡0 <strong>and</strong> false if k≢0. Onthe other h<strong>and</strong>, prim(φ) ∧ |φ| u s=k denotes the constraintm = k <strong>and</strong> prim(φ) ∧ |φ| u s≥k denotes m≥k. Hence,by repeating this process <strong>for</strong> every <strong>for</strong>mula φ which appearsin some cardinality constraint |φ| u s=k or |φ| u s≥k,we obtain a conjunction of linear constraints of the <strong>for</strong>mm = k <strong>and</strong> m ≥ k. These constraints specify a finiteor infinite set S ⊆ {0, 1, . . .} of possible sizes m. LetA = {s | |leaves(s)| ∈ S}. By nature of our constraints,if the set S is infinite then it contains an infinite intervalof <strong>for</strong>m {m 0 , m 0 + 1, . . .}, so the set A is infinite. If Σcontains a unary constructor <strong>and</strong> S is nonempty, then A isalso infinite. If Σ contains no unary constructors <strong>and</strong> S isfinite then A is finite <strong>and</strong> we can effectively compute A.The cardinality constraints containing u s are thus equivalentto ∨ pi=1 us = t s i where A = {ts 1 , . . . , ts p }. Trans<strong>for</strong>m∨the structural base <strong>for</strong>mula β into a disjunction of <strong>for</strong>mulaspi=1 β i where β i results from β by replacing the cardinalityconstraints containing u s with u s = t s i . Convert each β ito a structural base <strong>for</strong>mula by labelling the subterms of t s iwith internal shape variables using UNF rules, <strong>and</strong> by doingcase analysis on the equality between the new internalshape variables, using ShDis rule. By repeating this process<strong>for</strong> all shape variables u s where the set S is finite, we obtainbase <strong>for</strong>mulas where the set A is infinite <strong>for</strong> every undeterminedparameter shape variable u s . We may then eliminateall undetermined parameter <strong>and</strong> non-parameter shape variablesalong with the conjuncts that contain them. The resultis an equivalent <strong>for</strong>mula because Lemma 10 implies that itis always possible to find the values of eliminated parametervariables, so their existence is a redundant condition. Wethere<strong>for</strong>e eliminate all undetermined shape variables <strong>and</strong> theresulting structural base <strong>for</strong>mulas contain only determinedvariables.Proposition 25 (Struct. Base to Quantifier-Free) Everystructural base <strong>for</strong>mula β can be effectively trans<strong>for</strong>med toan equivalent well-defined quantifier-free <strong>for</strong>mula φ.Proof. Apply Corollary 19, then Lemma 23, <strong>and</strong> thenLemma 24. All variables in the resulting disjunction ofstructural base <strong>for</strong>mulas are determined, so each of themis equivalent to some quantifier free <strong>for</strong>mula φ i by Corollary17. The disjunction ∨ i φ i is the desired quantifier-free<strong>for</strong>mula φ.Summary of Our Quantifier Elimination Algorithm.Consider a closed L P -<strong>for</strong>mula φ. Convert φ to an extendedterm-power<strong>for</strong>mula φ 1 using (2). Convert φ 1 to prenex<strong>for</strong>m φ 2 . Eliminate all quantifiers from φ 2 starting from theinnermost one, as follows. If φ 2 ≡ 〈Q i u ∗ i 〉 i∃v ∗ . ψ where ψis quantifier-free then apply Proposition 13, Proposition 12<strong>and</strong> then Proposition 25. If φ 2 ≡ 〈Q i u ∗ i 〉∀v∗ . ψ then consider〈Q i u ∗ i 〉.¬∃v∗ . ¬ψ <strong>and</strong> proceed as in the previous case.By applying Proposition 13 <strong>and</strong> Proposition 25 to the resultingvariable-free <strong>for</strong>mula we obtain a propositional combinationof prim(φ) <strong>for</strong>mulas. Theorem 3 then follows by (3).Acknowledgements We thank Albert Meyer, Jens Palsberg,Tim Priesnitz, Stefan Ratschan, Jakob Rehof, ZhendongSu, <strong>and</strong> anonymous reviewers <strong>for</strong> useful comments.References[1] A. Aiken, D. Kozen, <strong>and</strong> E. Wimmers. Decidability ofsystems of set constraints with negative constraints.In<strong>for</strong>mation <strong>and</strong> Computation, 122, 1995.[2] A. Aiken, E. L. Wimmers, <strong>and</strong> T. K. Lakshman. Soft typingwith conditional types. In Proc. 21st ACM POPL, pages163–173, New York, NY, 1994.[3] H. Ait-Kaci, A. Podelski, <strong>and</strong> G. Smolka. A featureconstraint system <strong>for</strong> logic programming with entailment.In Theoretical Computer Science, volume 122, pages263–283, January 1994.[4] R. M. Amadio <strong>and</strong> L. Cardelli. Subtyping recursive types.Transactions on Programming Languages <strong>and</strong> Systems,15(4):575–631, 1993.[5] L. O. Andersen. Program <strong>Analysis</strong> <strong>and</strong> Specialization ofthe C Programming Language. PhD thesis, DIKU,University of Copenhagen, 1994.[6] R. Backofen. A complete axiomatization of a theory withfeature <strong>and</strong> arity constraints. Journal of LogicProgramming, 24:37–72, 1995.10


[7] W. Charatonik <strong>and</strong> L. Pacholski. Set constraints withprojections are in NEXPTIME. In Proc. 35th AnnualSymposium on Foundations of Computer Science (FOCS),pages 642–653, 1994.[8] W. Charatonik <strong>and</strong> A. Podelski. Set constraints withintersection. In Proc. 12th IEEE LICS, pages 362–372,1997.[9] H. Comon <strong>and</strong> C. Delor. Equational <strong>for</strong>mulae withmembership constraints. In<strong>for</strong>mation <strong>and</strong> Computation,112(2):167–216, 1994.[10] H. Comon <strong>and</strong> P. Lescanne. Equational problems <strong>and</strong>disunification. Journal of Symbolic Computation, 7(3):371,1989.[11] K. J. Compton <strong>and</strong> C. W. Henson. A uni<strong>for</strong>m method <strong>for</strong>proving lower bounds on the computational complexity oflogical theories. Annals of Pure <strong>and</strong> Applied Logic,48(1):1–79, July 1990.[12] R. Davies <strong>and</strong> F. Pfenning. Intersection types <strong>and</strong>computational effects. In Proc. ICFP, pages 198–208,2000.[13] S. Feferman <strong>and</strong> R. L. Vaught. The first order properties ofproducts of algebraic systems. Fundamenta Mathematicae,47:57–103, 1959.[14] J. Ferrante <strong>and</strong> C. W. Rackoff. The ComputationalComplexity of Logical Theories, volume 718 of LectureNotes in Mathematics. Springer-Verlag, 1979.[15] T. Freeman <strong>and</strong> F. Pfenning. Refinement types <strong>for</strong> ML. InProc. ACM PLDI, 1991.[16] A. Frey. Satisfying subtype inequalities in polynomialspace. Theoretical Computer Science, 277:105–117, 2002.[17] N. Heintze <strong>and</strong> O. Tardieu. Ultra-fast aliasing analysisusing CLA: A million lines of C code in a second. In Proc.ACM PLDI, 2001.[18] F. Henglein <strong>and</strong> J. Rehof. The complexity of subtypeentailment <strong>for</strong> simple types. In Proc. 12th IEEE LICS,pages 352–361, 1997.[19] M. Hoang <strong>and</strong> J. C. Mitchell. Lower bounds on typeinference with subtypes. In Proc. 22rd ACM POPL, pages176–185, 1995.[20] W. Hodges. Model Theory, volume 42 of Encyclopedia ofMathematics <strong>and</strong> its Applications. Cambridge UniversityPress, 1993.[21] T. Jim <strong>and</strong> J. Palsberg. Type inference in systems ofrecursive types with subtyping. http://www.cs.purdue.edu/homes/palsberg/, 1999.[22] M. Kerber <strong>and</strong> M. Kohlhase. A mechanization of strongKleene logic <strong>for</strong> partial functions. In A. Bundy, editor,Proc. 12th CADE, pages 371–385, Nancy, France, 1994.Springer Verlag, Berlin, Germany. LNAI 814.[23] S. C. Kleene. Introduction to Metamathematics. D. VanNostr<strong>and</strong> Company, Inc., Princeton, New Jersey, 1952. fifthreprint, 1967.[24] D. Kozen, J. Palsberg, <strong>and</strong> M. I. Schwartzbach. Efficientrecursive subtyping. Mathematical Structures in ComputerScience, 5(1):113–125, 1995.[25] V. Kuncak <strong>and</strong> M. Rinard. On the theory of structuralsubtyping. Technical Report 879, <strong>Lab</strong>oratory <strong>for</strong> ComputerScience, Massachusetts Institute of Technology, 2003.[26] J. W. Lloyd. Foundations of Logic Programming.Springer-Verlag, 2nd edition, 1987.[27] M. J. Maher. Complete axiomatizations of the algebras ofthe finite, rational, <strong>and</strong> infinite trees. IEEE Symposium onLogic in Computer Science, 1988.[28] A. I. Mal’cev. The Metamathematics of Algebraic Systems,volume 66 of Studies in Logic <strong>and</strong> The Foundations ofMathematics. North Holl<strong>and</strong>, 1971.[29] J. C. Mitchell. Type inference with simple types. Journal ofFunctional Programming, 1(3):245–285, 1991.[30] A. Mostowski. On direct products of theories. Journal ofSymbolic Logic, 17(1):1–31, March 1952.[31] M. Mueller <strong>and</strong> J. Niehren. Ordering constraints overfeature trees expressed in second-order monadic logic.In<strong>for</strong>mation <strong>and</strong> Computation, 159(1/2):22–58, 2000.[32] M. Mueller, J. Niehren, <strong>and</strong> R. Treinen. The first-ordertheory of ordering constraints over feature trees. DiscreteMathematics <strong>and</strong> Theoretical Computer Science,4(2):193–234, September 2001.[33] G. Nelson <strong>and</strong> D. C. Oppen. Fast decision proceduresbased on congruence closure. Journal of the ACM (JACM),27(2):356–364, 1980.[34] J. Palsberg <strong>and</strong> P. M. O’Keefe. A type system equivalent toflow analysis. Transactions on Programming Languages<strong>and</strong> Systems, 17(4):576–599, July 1995.[35] F. Pottier. Simplifying subtyping constraints: A theory.In<strong>for</strong>mation <strong>and</strong> Computation, 170(2):153–183, Nov. 2001.[36] M. Presburger. über die vollständigkeit eines gewissensystems der aritmethik ganzer zahlen, in welchem dieaddition als einzige operation hervortritt. In ComptesRendus du premier Congrès des Mathématiciens des Paysslaves, Warsawa, pages 92–101, 1929.[37] W. C. Rounds. Feature logics. In J. v. Benthem <strong>and</strong> A. terMeulen, editors, H<strong>and</strong>book of Logic <strong>and</strong> Language.Elsevier, 1997.[38] T. Rybina <strong>and</strong> A. Voronkov. A decision procedure <strong>for</strong> termalgebras with queues. ACM Transactions on ComputationalLogic (TOCL), 2(2):155–181, 2001.[39] V. Simonet. Type inference with structural subtyping: Afaithful <strong>for</strong>malization of an efficient constraint solver.Submitted <strong>for</strong> publication, Mar. 2003.[40] T. Skolem. Untersuchungen über die Axiome desKlassenkalküls <strong>and</strong> über “Produktations- undSummationsprobleme”, welche gewisse Klassen vonAussagen betreffen. Skrifter utgit av Vidnskapsselskapet iKristiania, I. klasse, no. 3, Oslo, 1919.[41] T. Sturm <strong>and</strong> V. Weispfenning. Quantifier elimination interm algebras: The case of finite languages. In V. G.Ganzha, E. W. Mayr, <strong>and</strong> E. V. Vorozhtsov, editors,Computer Algebra in Scientific Computing (CASC), TUMMuenchen, 2002.[42] Z. Su, A. Aiken, J. Niehren, T. Priesnitz, <strong>and</strong> R. Treinen.First-order theory of subtyping constraints. In Proc. 29thACM POPL, 2002.[43] A. Tarski. Arithmetical classes <strong>and</strong> types of algebraicallyclosed <strong>and</strong> real-closed fields. Bull. Amer. Math. Soc., 55,64, 1192, 1949.[44] A. Tarski. Arithmetical classes <strong>and</strong> types of booleanalgebras. Bull. Amer. Math. Soc., 55, 64, 1192, 1949.11


[45] J. Tiuryn. Subtype inequalities. In Proc. 7th IEEE LICS, SelEl: Selector <strong>and</strong> Test Elimination1992.C 1 ∨ (∃ȳ ∗ .C 2 ∧ Is f ∗(y ∗ )) →[46] R. Treinen. Feature trees over arbitrary structures. InC 1 ∨ (∃ȳ ∗ ∃¯z ∗ .C 2 ∧ y ∗ = f ∗ (¯z ∗ ))P. Blackburn <strong>and</strong> M. de Rijke, editors, Specifying SyntacticC 1 ∨ (∃ȳ ∗ .C 2 ∧ u ∗ =f ∗ (〈u ∗ i 〉 i) ∧ v ∗ =fj ∗ (u ∗ )) →Structures, chapter 7, pages 185–211. CSLI PublicationsC 1 ∨ (∃ȳ ∗ .C 2 ∧ u ∗ =f ∗ (〈u ∗ i 〉 i) ∧ v ∗ =u ∗ j)<strong>and</strong> FoLLI, 1997.[47] V. Trifonov <strong>and</strong> S. Smith. Subtyping constrained types. In ShpInt: Shape IntroductionProc. 3rd International Static <strong>Analysis</strong> Symposium, volumeC 1 ∨ (∃ū ∗ . C 2) → C 1 ∨ (∃ū ∗ , u s . sh(u)=u s ∧ C 2)1145 of LNCS, 1996.u occurs in C 2[48] I. Walukiewicz. Monadic second-order logic on tree-likeu s fresh shape variablestructures. Theoretical Computer Science,C 2 contains no sh(u) = u s′275(1–2):311–346, Mar. 2002.[49] M. W<strong>and</strong>, P. M. O’Keefe, <strong>and</strong> J. Palsberg. StrongCongCl: Congruence Closurenormalization with non-structural subtyping. MathematicalC 1 ∨ (∃ȳ ∗ ∃u ∗Structures in Computer Science, 5(3):419–430, 1995.1∃u ∗ 2. u ∗ 1=u ∗ 2 ∧ C 2) →C 1 ∨ (∃ȳ ∗ ∃u ∗ 1. C 2(u ∗ 2 ↦→ u ∗ 1))C[u ∗ 1=f ∗ (¯z ∗ ) ∧ u ∗ 2=f ∗ (¯z ∗ )] → C[u ∗ 1=f ∗ (¯z ∗ ) ∧ u ∗ 2=u ∗ 1]Appendix: Trans<strong>for</strong>ming Quantifier Free FormulasC[u ∗ =f ∗ (¯z ∗ ) ∧ u ∗ =g ∗ (¯x ∗ )] → C[false], f ∗ ≢ g ∗to Structural Base FormulasC[u ∗ =f ∗ (ū ∗ ) ∧ u ∗ =f ∗ (¯v ∗ )] →C[u ∗ =f ∗ (ū ∗ ) ∧ u ∗ =f ∗ (¯v ∗ ) ∧ ∧ iu ∗ i =vi ∗ ]Rules are applied modulo associativity <strong>and</strong> commutativity of ∧, ∨C[u ∗ ≠u ∗ ] → C[false]<strong>and</strong> symmetry of equality =. Ē denotes a sequence of expressionsC[u ∗ =u ∗ ] → C[true]〈E i〉 i. The result of substituting term t <strong>for</strong> variable x in <strong>for</strong>mulaC[P ∧ false] → C[false]C is denoted C(x ↦→ t).C[P ∨ false] → C[P]DNF: Disjunctive Normal FormC[P ∧ true] → C[P]C[P ∨ true] → C[true]C[¬(P ∧ Q)] → C[¬P ∨ ¬Q]C[¬(P ∨ Q)] → C[¬P ∧ ¬Q]OccChk: Occur CheckC[¬¬P] → C[P]C 1 ∨ β → C 1 whereC[P ∧ (Q ∨ R)] → C[(P ∧ Q) ∨ (P ∧ R)]β ≡ ∃ū.C 2 <strong>for</strong> C 2 conjunction of literalsu +WDNF: Disjunction of Well-Defined Conjunctionsβu <strong>for</strong> some variable uHomExp: Homomorphism Property <strong>and</strong> ExpansionF → DomCl(F) where F in DNFDomCl(∨ iC i) = ∨ iDomCl(C i)C[sh(u)=u s 1 ∧ sh(u)=u s 2] →DomCl(∧ iL i) = ∧ iDomCl(L i)C[sh(u)=u s 1 ∧ sh(u)=u s 2 ∧ u s 1 = u s 2]DomCl(R(¯t)) = R(¯t) ∧ DefCl(¯t)C 1 ∨ (∃ȳ ∗ .C 2 ∧ v=f(ū) ∧ sh(v)=v s ) →DomCl(¬R(¯t)) = ¬R(¯t) ∧ DefCl(¯t)DefCl(¯t) = V C 1 ∨ (∃ȳ ∗ ∃ū s .C 2 ∧ v=f(ū) ∧ sh(v)=v s{D f (¯s) |∧ v s =f s (ū s ) ∧ ∧ ish(u i) = u s i)f a partial function symbol of arity nC 1 ∨ (∃ȳ ∗ .C 2 ∧ v s =f s (ū s ) ∧ sh(v)=v s ) →D f the relation specifying the domain of fC 1 ∨ (∃ȳ ∗ ∃ū.C 2 ∧ v s =f s (ū s ) ∧ sh(v)=v sf(¯s) a subterm occuring in ¯t }∧ v=f(ū) ∧ ∧ ish(u i) = u s i)NEQEl: Term Disequality EliminationUNF: Unnested FormC[u 1≠u 2 ∧ sh(u 1)=u s 1 ∧ sh(u 2)=u s 2] →C 1 ∨ (∃ȳ.C 2[f(¯x)]) → C 1 ∨ (∃ȳ∃z.z=f(¯x) ∧ C 2[z]) whereC[(u s 1 ≠ u s 2 ∨ (u s 1 ≠ u s 2 ∧ |u 1 ≠ u 2| u sC 2[f(¯x)] a conjunction of literals1≥ 1)) ∧sh(u 1)=u s 1 ∧ sh(u 2)=u s 2]occurence C 2[ ] not in a literal of <strong>for</strong>m w = f(¯x)C 1 ∨ (∃ȳ.C 2) → C 1 ∨ (∃ȳ∃u.u=x ∧ C 2(x ↦→ u)) where CCD: Cardinality Constraint Decompositionu a fresh variablex a free variable s.t. C 2 contains no u ′ =x <strong>for</strong> u ′ C 1[|φ(〈f(〈u ij〉 j)〉 i)| u s=k] →boundC W 1[ {∧ j|φ(〈u ij〉 i)| u sj=k j | Σ jk j = k } ∧ C 2]ELNG: Negative Literal EliminationC 1[|φ(〈f(〈u ij〉 j)〉 i)| u s≥k] →C[¬Is f (y)] → C[Is PRI (y) ∨ W C W 1[ {∧ j|φ(〈u ij〉 i)| u sj≥k j | Σ jk j = k } ∧ C 2]{Is g(y) | g ∈ Σ \ {f} }]C[¬Is PRI (y)] → C[ W where C 2 contains{Is g(y) | g ∈ Σ }]C[¬Is f s(y s )] → C[Is c s(y s ) ∨ W u s = f(〈u s j〉 j) ∧ V{Is g s(y s i,j sh(uij)=us j) | g ∈ Σ \ {f} }]C[¬Is c s(y s )] → C[ W {Is g s(y s ShDis: Shape Distinction) | g ∈ Σ }]C[¬|φ| u s=k] → C[|φ| u s≥k+1 ∨ W k−1i=0 |φ|us=i]C[¬|φ| u s≥k] → C[ W C 1 ∨ (∃ū ∗ .C 2) → C 1 ∨ (∃ū ∗ .(u s i = u s j ∨ u s i ≠ u s j) ∧ C 2)k−1i=0 |φ|us=i]12

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!