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