This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

Satisfiability for two-variable logic
with two successor relations on finite linear orders111Work supported by the FET-Open grant agreement FOX, number FP7-ICT-233599.

Diego Figueira dfigueir@inf.ed.ac.uk University of Edinburgh
Abstract

We study the finite satisfiability problem for first order logic with two variables and two binary relations, corresponding to the induced successor relations of two finite linear orders. We show that the problem is decidable in NExpTime.

1 Introduction

First-order logic with two variables (henceforth denoted by FO2\textup{FO}^{\textup{2}}) is of importance in computer science due to its decidable satisfiability problem (contrary to fragments of FO with 3 or more variables), and since it has connections with many formalisms, such as modal, temporal or description logics. Many fragments of FO2\textup{FO}^{\textup{2}} have been studied because of this, especially in the presence of linear orders or equivalence relations. There are, still, a few relevant basic problems that remain open, and our work aims at expanding the classification of FO2\textup{FO}^{\textup{2}} in the presence of linear orders. In this setting, linear orders are related with temporal logics, but it is also applicable in other scenarios, like in databases or description logics.

We study the two variable fragment of first-order logic with two variables and two successor relations on two finite linear orders. We show that the problem is decidable in NExpTime. This bound is optimal, since the problem is NExpTime-hard [4]. This logic has been previously claimed to be decidable in 2NExpTime in [12], but the proof was flawed.222In fact, according to its author, the proof of Lemma 4 in [12] is wrong [13], and there does not appear to be an easy way of fixing it. This is a key lemma employed to obtain the decidability results contained in [12]. (Of course, this does not affect the undecidability results contained in [12].) Here we adopt a different strategy to prove decidability. As a corollary of the results from the report [14], this logic is shown to be decidable with a non-primitive-recursive algorithm.333By this we mean an algorithm whose time or space is not bounded by any primitive-recursive function. Our result also trivially extends to the satisfiability of existential monadic second order logic with two variables (EMSO2\textup{EMSO}^{2}) and two successor relations on finite linear orders.

This work focuses on the finite satisfiability problem and hence all the results discussed next are relative to finite structures. FO2\textup{FO}^{\textup{2}} is a well-known decidable fragment of first-order logic. Over arbitrary relations, it is known to be decidable [15], NExpTime-complete [5]. FO2\textup{FO}^{\textup{2}} over words (i.e., with two relations: a successor relation over a finite linear order, and its transitive closure) is NExpTime-complete [4]. The satisfiability problem was shown to be undecidable: in the presence of two transitive relations (even without equality) the satisfiability problem is undecidable [8]; in the presence of one transitive relation and one equivalence relation [11]; in the presence of three linear orders [9]; or in the presence of three equivalence relations [10]. However, if it has only two equivalence relations it is decidable [11]. Over words with one equivalence relation it is decidable [1]. If it only has a transitive closure over a finite linear order and an equivalence relation, then it is NExpTime-complete [1]. If it only has a successor relation over a finite linear order and an equivalence relation, it is in 2NExpTime [1]. On trees, with only successor relations (i.e., the child and next sibling relations) and an equivalence relation it is decidable in 3NExpTime [2].

There have also been works in the presence of a linear order and a linear preorder [17, 14]. In the presence of two finite linear orders, if there is a successor and its transitive closure over one linear order, and a successor over another linear order, it is decidable, and as hard as reachability of VAS according to the report [14]. If there are only two successors, it is known to be NExpTime-hard. Indeed, it is already NExpTime-hard even when no binary relations are present [4]. Here, we show that it is indeed NExpTime-complete. In fact, it sits in the same complexity class as FO2\textup{FO}^{\textup{2}} with just one successor relation on a linear order.

2 Preliminaries

Let ={1,2,}\mathds{N}=\{1,2,\dotsc\}, 0={0}\mathds{N}_{0}=\mathds{N}\cup\{0\}, and for every n,mn,m\in\mathds{N}, [n,m]={inim}[n,m]=\{i\in\mathds{N}\mid n\leq i\leq m\}, [n]=[1,n][n]=[1,n]. Given a function f:ABf:A\to B and a set AAA^{\prime}\subseteq A, by f|Af|_{A^{\prime}} we denote ff restricted to the elements of AA^{\prime}, and by f[ab]:A{a}B{b}f[a\mapsto b]:A\cup\{a\}\to B\cup\{b\} we denote the function where f[ab](a)=bf[a\mapsto b](a)=b and f[ab](a)=f(a)f[a\mapsto b](a^{\prime})=f(a^{\prime}) for all aA{a}a^{\prime}\in A\setminus\{a\}. We write [ab][a\mapsto b] to denote ι[ab]\iota\,[a\mapsto b], where ι\iota is the identity function, and [ab,ab][a\mapsto b,a^{\prime}\mapsto b^{\prime}] to denote [ab][ab][a\mapsto b][a^{\prime}\mapsto b^{\prime}]. For any number nn, we denote by |n||n| its absolute value. We write #S\#S to denote the number of elements of a set SS. Given a string wAw\in A^{*}, we write |w||w| to denote the length of ww, w[i,j]w[i,j] to denote the subword of ww restricted to positions [i,j][i,j], and w[i]w[i] to denote w[i,i]w[i,i], for any 1ij|w|1\leq i\leq j\leq|w|.

2.1 Permutations

First-order structures with nn elements and two linear orders can be naturally represented as a permutation on [n][n] with nn valuations.444We do not claim that we are the first to use this encoding, it may have been used before. This representation will prove useful in the proofs that follow. A permutation of [n][n] is represented as a set π[n]×[n]\pi\subseteq[n]\times[n] so that for every i[n]i\in[n], π\pi has exactly one pair with ii in the first component, and exactly one pair with ii in the second component. We will normally use the symbols (r,c),(s,d)(r,c),(s,d) to denote elements of a permutation.

Refer to caption
Figure 1: Representation of: (aa) a 44-permutation π={(4,1),(2,2),(1,3),(3,4)}\pi=\{(4,1),(2,2),(1,3),(3,4)\}; (bb) a valued permutation (π,σ)(\pi,\sigma) where, e.g., σ(1,3)={p,q}\sigma(1,3)=\{p,q\}; (cc) the maximal blocks of π\pi; (d)(d) the fingerprints of (π,σ)(\pi,\sigma).

Formally, given nn\in\mathds{N}, we say that π[n]×[n]\pi\subseteq[n]\times[n] is an n-permutation if for every k[n]k\in[n] we have #{c(k,c)π}=#{r(r,k)π}=1\#\{c\mid(k,c)\in\pi\}=\#\{r\mid(r,k)\in\pi\}=1. We say that π\pi is a permutation if it is an nn-permutation for some nn. Given a permutation π\pi and (r,c),(r,c)π(r,c),(r^{\prime},c^{\prime})\in\pi we say that the neighborhood type of (r,c),(r,c)(r,c),(r^{\prime},c^{\prime}) in π\pi is an element t{,,,,,,,,,}t\in\{\bullet,\nearrow,\uparrow,\nwarrow,\leftarrow,\swarrow,\downarrow,\searrow,\rightarrow,\infty\} so that: t{,,}t\in\{\searrow,\downarrow,\swarrow\} iff rr=1r^{\prime}-r=1, t{,,}t\in\{\nearrow,\uparrow,\nwarrow\} iff rr=1r^{\prime}-r=-1, t{,,}t\in\{\nearrow,\rightarrow,\searrow\} iff cc=1c^{\prime}-c=1, t{,,}t\in\{\nwarrow,\leftarrow,\swarrow\} iff rr=1r^{\prime}-r=-1, and t=t=\bullet iff (r,c)=(r,c)(r,c)=(r^{\prime},c^{\prime}). We denote it with [(r,c),(r,c)]π[(r,c),(r^{\prime},c^{\prime})]_{\pi}. Figure 1-aa contains a graphical representation of a 44-permutation, where [(2,2),(3,4)]π=[(2,2),(3,4)]_{\pi}=\downarrow, [(2,2),(1,3)]π=[(2,2),(1,3)]_{\pi}=\nearrow, [(1,3),(4,1)]π=[(1,3),(4,1)]_{\pi}=\infty.

Let us fix 𝕍\mathbb{V} to be an enumerable set of propositional letters. A valued permutation is a pair (π,σ)(\pi,\sigma) consisting of a permutation π\pi and a function σ:π2𝕍\sigma:\pi\to 2^{\mathbb{V}} that assigns a set of propositional letters to each element of π\pi. We say that σ(r,c)𝕍\sigma(r,c)\subseteq\mathbb{V} is the valuation of (r,c)(r,c) in (π,σ)(\pi,\sigma). Since for every rr [resp. for every cc] there is only one cc [resp. only one rr] such that (r,c)π(r,c)\in\pi we use the notation σ(r,  )\sigma(r,\raisebox{1.30487pt}{\hskip-0.40149pt\text{\lx@text@underline{\hskip 4.73611pt}\hskip 0.6458pt}}) [resp. σ(  ,c)\sigma(\raisebox{1.30487pt}{\hskip-0.40149pt\text{\lx@text@underline{\hskip 4.73611pt}\hskip 0.6458pt}},c)] to denote σ(r,c)\sigma(r,c) for the only cc [resp. only rr] such that (r,c)π(r,c)\in\pi. For example, the valued permutation of Figure 1-bb is such that σ(3,  )=σ(3,4)={r,q}\sigma(3,\raisebox{1.30487pt}{\hskip-0.40149pt\text{\lx@text@underline{\hskip 4.73611pt}\hskip 0.6458pt}})=\sigma(3,4)=\{r,q\}. A valued permutation can be seen as a finite first-order structure with two linear orders, where the permutation element (r,c)(r,c) represents the rr-th element in the first linear order, and the cc-th element in the second linear order, and its valuation is σ(r,c)\sigma(r,c). Likewise, any finite first-order structure with two linear orders can be represented by a valued permutation.

For convenience in our proofs, we also represent an nn-permutations with any set πS×T\pi^{\prime}\subseteq S\times T with S,TS,T\subseteq\mathds{N}, #S=#T=n\#S=\#T=n such that for every (c,r)S×T(c,r)\in S\times T, #{c(r,c)π}=#{r(r,c)π}=1\#\{c^{\prime}\mid(r,c^{\prime})\in\pi^{\prime}\}=\#\{r^{\prime}\mid(r^{\prime},c)\in\pi^{\prime}\}=1. In this case we say that π\pi^{\prime} is a permutation over S×TS\times T. Note that for every nn-permutation π\pi^{\prime} over S×TS\times T there is an nn-permutation π\pi and a bijection f:ππf:\pi^{\prime}\to\pi that preserves the order of the elements: for all f(r,c)=(r,c)f(r,c)=(r^{\prime},c^{\prime}), f(s,d)=(s,d)f(s,d)=(s^{\prime},d^{\prime}), we have that rsr\leq s iff rsr^{\prime}\leq s^{\prime} and cdc\leq d iff cdc^{\prime}\leq d^{\prime}. For any (r,c),(r,c)π(r,c),(r^{\prime},c^{\prime})\in\pi^{\prime} we define [(r,c),(r,c)]π=[f(r,c),f(r,c)]π[(r,c),(r^{\prime},c^{\prime})]_{\pi^{\prime}}=[f(r,c),f(r^{\prime},c^{\prime})]_{\pi}.

Valued permutations represent, precisely, first-order finite structures with two linear orders. We define then the semantics of FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) over valued permutations.

2.2 FO2\textup{FO}^{\textup{2}} with two linear orders

We define FO2\textup{FO}^{\textup{2}} on finite structures with the induced successor relations of two finite linear orders, that we denote by FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}). The atoms of FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) are: p(a)p(a), aba{\rightarrow}b, and aba{\downarrow}b, for every a,b{x,y}a,b\in\{x,y\} and every propositional letter p𝕍p\in\mathbb{V}. If φ,ψ\varphi,\psi are formulas of FO2\textup{FO}^{\textup{2}}, so are a.φ\exists a.\varphi, a.φ\forall a.\varphi, ¬φ\lnot\varphi, φψ\varphi\land\psi, φψ\varphi\lor\psi, where a{x,y}a\in\{x,y\}. For any φFO2(,)\varphi\in\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}), let 𝒱φ𝕍\mathcal{V}_{\varphi}\subseteq\mathbb{V} be the set of all propositional variables occurring in φ\varphi.

Semantics

We define FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) on valued permutations. The semantics are as expected, we give only some cases to fix notation. Here, (π,σ)(\pi,\sigma) is a valued permutation and μ\mu is a partial function μ:{x,y}π\mu:\{x,y\}\to\pi.

(π,σ)\displaystyle(\pi,\sigma) μp(x)\displaystyle\models_{\mu}p(x)  if pσ(μ(x))\displaystyle~~\text{ if }p\in\sigma(\mu(x))
(π,σ)\displaystyle(\pi,\sigma) μx.φ\displaystyle\models_{\mu}\exists x.\varphi if for some (r,c)π(r,c)\in\pi we have
(π,σ)μ[x(r,c)]φ\displaystyle~~~(\pi,\sigma)\models_{\mu[x\mapsto(r,c)]}\varphi
(π,σ)\displaystyle(\pi,\sigma) μ(xy)\displaystyle\models_{\mu}(x{\rightarrow}y) if for some (r,c),(r,c+1)π(r,c),(r^{\prime},c+1)\in\pi we
have μ(x)=(r,c)\mu(x)=(r,c), μ(y)=(r,c+1)\mu(y)=(r^{\prime},c+1)
(π,σ)\displaystyle(\pi,\sigma) μ(xy)\displaystyle\models_{\mu}(x{\downarrow}y) if for some (r,c),(r+1,c)π(r,c),(r+1,c^{\prime})\in\pi we
have μ(x)=(r,c)\mu(x)=(r,c), μ(y)=(r+1,c)\mu(y)=(r+1,c^{\prime})

For any closed formula φ\varphi, we define (π,σ)φ(\pi,\sigma)\models\varphi if (π,σ)vφ(\pi,\sigma)\models_{v_{\emptyset}}\varphi, where v(x)=v(y)=v_{\emptyset}(x)=v_{\emptyset}(y)=\bot. In this case we say that (π,σ)(\pi,\sigma) satisfies φ\varphi. For example, the valued permutation of Figure 1-bb satisfies the formula xy.¬(xyyxp(x))\forall x\forall y.\lnot({x{\rightarrow}y}\,\land\,{y{\downarrow}x}\,\land\,{p(x)}). The satisfiability problem for FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) is then, given a closed formula φFO2(,)\varphi\in\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}), whether (π,σ)φ(\pi,\sigma)\models\varphi for some (π,σ)(\pi,\sigma).

Scott normal form

Any formula φFO2(,)\varphi\in\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) can be converted into a satisfiability equivalent formula in Scott normal form, which is of the form

xyχixyψi,\displaystyle\forall x\forall y~\chi~~\land~~\bigwedge_{i}\forall x\exists y~\psi_{i},

where χ\chi and all the ψi\psi_{i}’s are quantifier-free formulas of FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}). The resulting formula is linear in terms of the size of the original formula. Further, this reduction is polynomial-time (see, e.g.[6]). Henceforward we assume that all the formulas we work with are in Scott normal form, unless otherwise stated.

3 Results

Theorem 1.

The satisfiability problem for FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) is NExpTime-complete.

As an immediate corollary we have that the same bound holds for EMSO2(,)\textup{EMSO}^{2}({\rightarrow},{\downarrow}), where EMSO2(,)\textup{EMSO}^{2}({\rightarrow},{\downarrow}) stands for formulas of FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) prefixed by existential quantification over sets of permutation elements.

Corollary 1.

The satisfiability problem for EMSO2(,)\textup{EMSO}^{2}({\rightarrow},{\downarrow}) is NExpTime-complete.

Proof sketch

First, in Section 4 we show a property of the blocks of a valued permutation. A block of a permutation can be seen as a set of positions {(r,c),(r+1,c+1),,(r+k,c+k)}\{(r,c),(r+1,c+1),\dotsc,(r+k,c+k)\} (or {(r,c),(r+1,c1),,(r+k,ck)}\{(r,c),(r+1,c-1),\dotsc,(r+k,c-k)\}) of the permutation.555A similar notion of block is also used in [14]. We prove that if a FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) formula φ\varphi is satisfiable, then it is satisfiable in a valued model where every block is of size bounded exponentially in the size of φ\varphi. Moreover, the number of different types of blocks that can appear in the valued permutation is also bounded exponentially in the size of φ\varphi.

Second, in Section 5 we show a combinatorial proposition. This involves what we call nn-permutation constraints, which are sets of positions of [n]×[n][n]\times[n] where a permutation satisfying this constraint is not allowed to have an element. We give a sufficient condition on how large nn must be to ensure that there exists a permutation satisfying any constraint with a certain property—namely that it has at most 4 elements in any row or column.

Finally, in Section 6 we introduce a problem called the Restricted Labeled Permutation problem (RLP), which we show to be decidable in NP using the result of Section 5. We then show that satisfiability for FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) can be reduced in NExpTime to the RLP problem, by using the results on the size of the blocks of Section 4. Thus, decidability of the satisfiability problem for FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) follows, with a tight upper bound of NExpTime.

4 Few and small blocks properties

Definition 1 (Block).

Given an nn-permutation π\pi we say that B[n]×[n]B\subseteq[n]\times[n] is a block of π\pi if B=[i,i+k]×[j,j+k]B=[i,i+k]\times[j,j+k] for some k0k\in\mathds{N}_{0} so that i,j,i+k,j+k[n]i,j,i+k,j+k\in[n], and either

  • #B=1\#B=1, and in this case we say that BB has type ‘\bullet’, or, otherwise,

  • for every (r,c),(r+1,c)Bπ(r,c),(r+1,c^{\prime})\in B\cap\pi, we have c=c+1c^{\prime}=c+1, and in this case we say that BB has type ‘\searrow’, or

  • for every (r,c),(r+1,c)Bπ(r,c),(r+1,c^{\prime})\in B\cap\pi, we have c=c1c^{\prime}=c-1, and in this case we say that BB has type ‘\nearrow’.

We say that kk is the size of the block BB. A block BB is maximal if there is no block BB^{\prime} of π\pi with BBB\subsetneq B^{\prime}. Figure 1-cc shows the three maximal blocks of a permutation, one with type \nearrow and two with type \bullet.

Proposition 1.

Any minimal valued permutation satisfying φFO2(,)\varphi\in\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) is such that every block is of size at most exponential in φ\varphi.

In fact, note that FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) on blocks is basically like FO2()\textup{FO}^{\textup{2}}({\rightarrow}) (first order logic with a successor relation on a linear order), where we have the exponential length model property [4]. However, note that a block is within a context of other blocks, and special care must be taken in order to preserve all the elements that may be needed outside the block.

Definition 2 (Fingerprint).

Given a maximal block B=[k,k+n]×[l,l+n]B=[k,k+n]\times[l,l+n] of a valued permutation (π,σ)(\pi,\sigma), we define ξ(B)=(t,b1,b+1,b1,b+1,a0an)\xi(B)=(t,b^{\rightarrow}_{-1},b^{\rightarrow}_{+1},b^{\downarrow}_{-1},b^{\downarrow}_{+1},a_{0}\dotsb a_{n}), where

  • t{,,}t\in\{\nearrow,\searrow,\bullet\} is the type of BB,

  • b+1=σ(k+n+1,  )b^{\rightarrow}_{+1}=\sigma(k+n+1,\raisebox{1.30487pt}{\hskip-0.40149pt\text{\lx@text@underline{\hskip 4.73611pt}\hskip 0.6458pt}}) if it exists, or b+1=b^{\rightarrow}_{+1}=\bot otherwise; b+1=σ(  ,l+n+1)b^{\downarrow}_{+1}=\sigma(\raisebox{1.30487pt}{\hskip-0.40149pt\text{\lx@text@underline{\hskip 4.73611pt}\hskip 0.6458pt}},l+n+1) if it exists, or b+1=b^{\downarrow}_{+1}=\bot otherwise,

  • b1=σ(k1,  )b^{\rightarrow}_{-1}=\sigma(k-1,\raisebox{1.30487pt}{\hskip-0.40149pt\text{\lx@text@underline{\hskip 4.73611pt}\hskip 0.6458pt}}) if it exists, or b1=b^{\rightarrow}_{-1}=\bot otherwise; b1=σ(  ,l1)b^{\downarrow}_{-1}=\sigma(\raisebox{1.30487pt}{\hskip-0.40149pt\text{\lx@text@underline{\hskip 4.73611pt}\hskip 0.6458pt}},l-1) if it exists, or b1=b^{\downarrow}_{-1}=\bot otherwise,

  • ai=σ(k+i,  )a_{i}=\sigma(k+i,\raisebox{1.30487pt}{\hskip-0.40149pt\text{\lx@text@underline{\hskip 4.73611pt}\hskip 0.6458pt}}) for all 0in0\leq i\leq n.

ξ(B)\xi(B) is the fingerprint of BB, and tt is the type of ξ(B)\xi(B) (notation: type(τ)=t\textrm{type}(\tau)=t, where ξ(B)=τ\xi(B)=\tau). For ξ(B)=τ\xi(B)=\tau, we also define τ=b1a0anb+1\tau_{\rightarrow}=b^{\rightarrow}_{-1}a_{0}\dotsb a_{n}b^{\rightarrow}_{+1}; and τ=b1a0anb+1\tau_{\downarrow}=b^{\rightarrow}_{-1}a_{0}\dotsb a_{n}b^{\rightarrow}_{+1} if t=t=\searrow, or τ=b1ana0b+1\tau_{\downarrow}=b^{\rightarrow}_{-1}a_{n}\dotsb a_{0}b^{\rightarrow}_{+1} otherwise. The set of fingerprints of a valued permutation is the set of the fingerprints of all its maximal blocks. Figure 1-dd contains an example of the fingerprints of a valued permutation.

Proposition 2.

If φ\varphi is satisfiable, then it is satisfiable in a minimal model with at most an exponential number of fingerprints.

By Propositions 1 and 2, we can restrict our attention to permutations with labels, over the exponential alphabet of fingerprints of maximal blocks. However, to do this we need restrict the possible permutations. For example, there cannot be two elements (r,c),(r+1,c+1)(r,c),(r+1,c+1) in the permutation where both its labels contain fingeprints with type \searrow. Indeed, this would imply that the blocks to which these fingerprint correspond were not actually maximal. This suggests that we need to deal with some sort of constraints defining valid permutations. This is the theme of the following section.

5 Permutations under constraints

We define constraints that restrict where permutations may or may not contain elements. A constraint specify some positions in which a permutation satisfying it is not allowed to have an element. More precisely, a (n,k)(n,k) constraint contains not more than kk forbidden positions in an nn-permutation.

Definition 3 ((n,k)(n,k)-constraint).

Given n,kn,k\in\mathds{N}, and S,TS,T\subseteq\mathds{N} with #S=#T=n\#S=\#T=n, we say that ζS×T\zeta\subseteq S\times T is a (n,k)(n,k)-constraint over S×TS\times T if for every (r,c)S×T(r,c)\in S\times T we have #{c(r,c)ζ}k\#\{c^{\prime}\mid(r,c^{\prime})\in\zeta\}\leq k and #{r(r,c)ζ}k\#\{r^{\prime}\mid(r^{\prime},c)\in\zeta\}\leq k. An nn-permutation π\pi over S×TS\times T satisfies a (n,k)(n,k)-constraint ζ\zeta over S×TS\times T if πζ=\pi\cap\zeta=\emptyset. If S=T=[n]S=T=[n] we say that ζ\zeta is just a (n,k)(n,k)-constraint.

Remark 1.

As with the permutations, any nn-permutation π\pi over SS satisfying a (n,k)(n,k)-constraint ζ\zeta can be equivalently seen as a nn-permutation π\pi^{\prime} satisfying a (n,k)(n,k)-constraint ζ\zeta^{\prime} and vice-versa.

Proposition 3.

For every (n,k)(n,k)-constraint ζ\zeta with n>2kn>2k, there is an nn-permutation π\pi satisfying ζ\zeta.

Proof.

This can be shown by a simple application of Hall’s Marriage Theorem [7] (see also [3, p.36]). Remember that Hall’s theorem—in its finite, graph theoretic formulation—states that for any bipartite graph G=(V1V2,E)G=(V_{1}\cup V_{2},E) with bipartite sets V1V_{1} and V2V_{2} of equal size, GG has a perfect matching if, and only if, every subset SV1S\subseteq V_{1} verifies |NG(S)||S||N_{G}(S)|\geq|S|. In the formulation, NG(S)V2N_{G}(S)\subseteq V_{2} is the neighbourhood of SS in GG (i.e., the set of vertices adjacent to some vertex of SS).

Let ζ\zeta be a (n,k)(n,k) constraint where n>2kn>2k. Consider a bipartite graph G=(VrVc,E)G=(V_{r}\cup V_{c},E), where Vr={r}×[n]V_{r}=\{r\}\times[n], Vc={c}×[n]V_{c}=\{c\}\times[n]. Vertices from VrV_{r} represent rows and vertices from VcV_{c} represent a columns. The set of edges EVr×VcE\subseteq V_{r}\times V_{c} is defined as all pairs ((r,i),(c,j))((r,i),(c,j)) so that (i,j)ζ(i,j)\not\in\zeta (i.e., they represent permutation positions that do not interefere any constraint). Hence, there is a perfect matching between VrV_{r} and VcV_{c} if, and only if, there is an nn-permutation satisfying ζ\zeta. To prove that there is such a matching, by Halls’ theorem it suffices to verify |NG(S)||S||N_{G}(S)|\geq|S| for every SVrS\subseteq V_{r}. We show this by case distinction.

  • Suppose first |S|nk|S|\leq n-k. Note that every vertex of VrV_{r} has at least nkn-k edges because there are only kk constraints in ζ\zeta. Then, NG(S)N_{G}(S) has nkn-k vertices because every single vertex in SS has already nkn-k edges.

  • Suppose now |S|>nk|S|>n-k. Since n>2kn>2k, we have nk>kn-k>k. Then, every vertex from VcV_{c} already has one neighbor in SS, as every vertex from VcV_{c} has at least nk>kn-k>k neighbors.

Hence, there is a perfect matching, and thus there exists a permutation satisfying ζ\zeta. ∎

We then have the following corollary.

Corollary 2.

For every (n,4)(n,4)-constraint ζ\zeta with n9n\geq 9, there is an nn-permutation π\pi that satisfies ζ\zeta.

6 Labeled permutations

In this section we prove the NExpTime upper bound of the satisfiability problem for FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}), using the developments of the two previous sections. The idea is to guess the (exponentially many) blocks (of exponential size) of a minimal model that satisfies φ\varphi, and use them as letters of our alphabet. Using this guessing, we reduce the satisfiability problem into a problem we introduce next, the Restricted Labeled Permutation problem (RLP).

6.1 Restricted labeled permutation problem

Definition 4.

A labeled permutation over a (finite) alphabet 𝔸\mathbb{A} is a pair (π,λ)(\pi,\lambda) where π\pi is a permutation and λ:π𝔸\lambda:\pi\to\mathbb{A}. Note that (π,λ)(\pi,\lambda) is nothing else than a valued permutation where exactly one propositional variable holds at any position.

Definition 5 ((π,λ)(\pi,\lambda)_{\rightarrow}, (π,λ)(\pi,\lambda)_{\downarrow}).

Given a labeled nn-permutation (π,λ)(\pi,\lambda) we define (π,λ)(\pi,\lambda)_{\rightarrow} and (π,λ)(\pi,\lambda)_{\downarrow} as follows: (π,λ)=λ(1,c1)λ(n,cn)(\pi,\lambda)_{\rightarrow}=\lambda(1,c_{1})\dotsb\lambda(n,c_{n}) and (π,λ)=λ(r1,1)λ(rn,n)(\pi,\lambda)_{\downarrow}=\lambda(r_{1},1)\dotsb\lambda(r_{n},n), where {(1,c1),,(n,cn)}={(r1,1),,(rn,n)}=π\{(1,c_{1}),\dotsc,(n,c_{n})\}=\{(r_{1},1),\dotsc,(r_{n},n)\}=\pi.

Definition 6.

A label restriction over an alphabet 𝔸\mathbb{A} is a triple (a,t,b)(a,t,b), where a,b𝔸a,b\in\mathbb{A} and t{,}t\in\{\nearrow,\searrow\}. We say that a labeled permutation (π,λ)(\pi,\lambda) satisfies (a,t,b)(a,t,b) if for every (r,c),(s,d)π(r,c),(s,d)\in\pi such that λ(r,c)=a\lambda(r,c)=a, λ(s,d)=b\lambda(s,d)=b we have [(r,c),(s,d)]πt[(r,c),(s,d)]_{\pi}\neq t. We say that (π,λ)(\pi,\lambda) satisfies a set of label restrictions if it satisfies all of its members.

We define the main problem of this section. Using the result of Section 5 on permutations under constraints, we show that this problem is in NP.

Problem: The Restricted Labeled Permutation
problem (RLP)
Input: A finite alphabet 𝔸\mathbb{A},
a set of label restrictions RR, and
two regular languages 1,2𝔸\mathcal{L}_{1},\mathcal{L}_{2}\subseteq\mathbb{A}^{*}
(given as NFA).
Question: Is there a labeled permutation (π,λ)(\pi,\lambda)
satisfying RR such that
(π,λ)1(\pi,\lambda)_{\rightarrow}\in\mathcal{L}_{1} and (π,λ)2(\pi,\lambda)_{\downarrow}\in\mathcal{L}_{2}?
Proposition 4.

The RLP problem is in NP.

Proof.
Refer to caption
Figure 2: Example of the labeled permutation (π,λ)(\pi^{\prime},\lambda^{\prime}) over the alphabet {a,b,c,}\{a,b,c,\Box\}, showing the zones (depicted as Refer to caption) where the label \Box (depicted as Refer to caption) can appear. Here, g(a)=g(b)=g(c)=1g(a)=g(b)=g(c)=1.

Let 𝒜1,𝒜2\mathcal{A}_{1},\mathcal{A}_{2} be two NFA over the alphabet 𝔸\mathbb{A} corresponding to the regular languages 1,2\mathcal{L}_{1},\mathcal{L}_{2} respectively. Let RR be a set of restrictions.

The algorithm first guesses some properties of the labeled permutation (π,λ)(\pi,\lambda) that satisfies RR and is such that (π,λ)1(\pi,\lambda)_{\rightarrow}\in\mathcal{L}_{1} and (π,λ)2(\pi,\lambda)_{\downarrow}\in\mathcal{L}_{2}. (We cannot simply guess (π,λ)(\pi,\lambda) because it may be too big.) For each letter a𝔸a\in\mathbb{A} we guess if it appears exactly kk times in (π,λ)(\pi,\lambda) for some k17k\leq 17, or if it appears more than 1717 times. Let g:𝔸{0,1,,17,}g:\mathbb{A}\to\{0,1,\dotsc,17,\infty\} be this guessing; and let us define 𝔸={a𝔸g(a)}\mathbb{A}_{\leq}=\{a\in\mathbb{A}\mid g(a)\neq\infty\} and 𝔸>={a𝔸g(a)=}\mathbb{A}_{>}=\{a\in\mathbb{A}\mid g(a)=\infty\}.

Let us call zone to any set S=[i,i+l]×[j,j+l]S=[i,i+l]\times[j,j+l] for i,j,li,j,l\in\mathds{N}. Next, we guess a small labeled permutation (π,λ)(\pi^{\prime},\lambda^{\prime}) over the alphabet 𝔸{}\mathbb{A}_{\leq}\cup\{\Box\}. This labeled permutation is such that:

  1. 1.

    All the letters a𝔸a\in\mathbb{A}_{\leq} in (π,λ)(\pi^{\prime},\lambda^{\prime}) appear exactly g(a)g(a) times.

  2. 2.

    There is no zone SS so that

    • πS\pi^{\prime}\cap S has at least two elements, and

    • λ(r,c)=\lambda^{\prime}(r,c)=\Box for all (r,c)πS(r,c)\in\pi^{\prime}\cap S.

  3. 3.

    (π,λ)(\pi^{\prime},\lambda^{\prime}) satisfies the restrictions RR.

Claim 1.

All possible (π,λ)(\pi^{\prime},\lambda^{\prime}) satisfying the conditions above are labeled permutations of size polynomially bounded by #𝔸\#\mathbb{A}.

Proof.

Note that, once we fix gg, there are not more than N=(1+a𝔸g(a)g(a))2N=(~1+\sum_{\begin{subarray}{c}a\in\mathbb{A}\\ g(a)\neq\infty\end{subarray}}g(a)~)^{2} different zones containing only \Box labels, that cover all positions where the label \Box can occur in (π,λ)(\pi^{\prime},\lambda^{\prime}). These are the zones defined in between the elements of {a𝔸g(a)}\{a\in\mathbb{A}\mid g(a)\neq\infty\}. Then, there cannot be more than NN elements with label \Box, since otherwise there would be at least one zone with more than one element, contradicting condition (2). Since N(1+17#𝔸)2N\leq(1+17\cdot\#\mathbb{A})^{2}, the claim follows. For example, Figure 2-aa depicts the 16=(1+g(a)+g(b)+g(c))216=(1+g(a)+g(b)+g(c))^{2} possible zones where the label \Box can appear as the dark gray areas. In Figure 2-bb we see that there is one zone (in fact, two) that contains more than one element \Box, and therefore condition (2) is falsified (for instance, when S=[4,5]×[4,5]S=[4,5]\times[4,5]). Finally, Figure 2-cc shows a labeled permutation (π,λ)(\pi^{\prime},\lambda^{\prime}) satisfying condition (2). ∎

Let 𝒜>\mathcal{A}_{>} be an NFA over 𝔸\mathbb{A} that accepts all words w𝔸w\in\mathbb{A}^{*} such that every a𝔸>a\in\mathbb{A}_{>} appears more than 17 times in ww. Let e1\textit{e}_{1} [resp. e2\textit{e}_{2}] be the regular expression resulting from replacing every appearance of \Box in (π,λ)(\pi^{\prime},\lambda^{\prime})_{\rightarrow} [resp. in (π,λ)(\pi^{\prime},\lambda^{\prime})_{\downarrow}] with the expression (𝔸>)+(\mathbb{A}_{>})^{+}. Notice that, for every i{1,2}i\in\{1,2\}, any word ww of L(ei)L(𝒜>)L(\textit{e}_{i})\cap L(\mathcal{A}_{>}) is such that the number of appearances of a𝔸a\in\mathbb{A}_{\leq} in ww is exactly g(a)g(a), and every other letter a𝔸>a\in\mathbb{A}_{>} appears more than 17 times. Let 𝒜i\mathcal{A}^{\prime}_{i} denote the NFA corresponding to L(𝒜i)L(ei)L(𝒜>)L(\mathcal{A}_{i})\cap L(\textit{e}_{i})\cap L(\mathcal{A}_{>}), for every i{1,2}i\in\{1,2\}. Observe that 𝒜>\mathcal{A}_{>}, 𝒜1\mathcal{A}^{\prime}_{1} and 𝒜2\mathcal{A}^{\prime}_{2} can be built in polynomial time. Given a language 𝔸\mathcal{L}\subseteq\mathbb{A}^{*}, let pk()pk(\mathcal{L}) denote the Parikh image of \mathcal{L}. We finally check whether

pk(L(𝒜1))pk(L(𝒜2)).pk(L(\mathcal{A}^{\prime}_{1}))~\cap~pk(L(\mathcal{A}^{\prime}_{2}))~\neq~\emptyset.

This can be verified in NP by computing the existential Presburger formulas for both automata in polynomial time [18] and checking for emptiness of its intersection in NP [16].

Claim 2.

pk(L(𝒜1))pk(L(𝒜2))pk(L(\mathcal{A}^{\prime}_{1}))~\cap~pk(L(\mathcal{A}^{\prime}_{2}))~\neq~\emptyset if, and only if, there is a labeled permutation (π,λ)(\pi,\lambda) that satisfies RR, such that (π,λ)1(\pi,\lambda)_{\rightarrow}\in\mathcal{L}_{1} and (π,λ)2(\pi,\lambda)_{\downarrow}\in\mathcal{L}_{2}.

The rest of the proof is dedicated to prove the statement above.

[][\Rightarrow] If pk(L(𝒜1))pk(L(𝒜2))pk(L(\mathcal{A}^{\prime}_{1}))~\cap~pk(L(\mathcal{A}^{\prime}_{2}))\neq\emptyset, we show that there is a labeled permutation (π,λ)(\pi,\lambda) that satisfies RR and such that (π,λ)1(\pi,\lambda)_{\rightarrow}\in\mathcal{L}_{1} and (π,λ)2(\pi,\lambda)_{\downarrow}\in\mathcal{L}_{2}.

Let w1L(𝒜1)w_{1}\in L(\mathcal{A}^{\prime}_{1}), w2L(𝒜2)w_{2}\in L(\mathcal{A}^{\prime}_{2}) such that pk(w1)=pk(w2)pk(w_{1})=pk(w_{2}), and let m=|w1|=|w2|m=|w_{1}|=|w_{2}|. For every a𝔸a\in\mathbb{A}, let Xa[m]×[m]X_{a}\subseteq[m]\times[m] be defined as all (r,c)[m]×[m](r,c)\in[m]\times[m] such that w1[r]=aw_{1}[r]=a or w2[c]=aw_{2}[c]=a (i.e., XaX_{a} is the set of possible permutation elements labeled with aa). For any A𝔸A\subseteq\mathbb{A}, let XA=aAXaX_{A}=\bigcup_{a\in A}X_{a}.

We define the labeled permutation (π𝔸,λ𝔸)(\pi_{\mathbb{A}_{\leq}},\lambda_{\mathbb{A}_{\leq}}) as all the elements (r+r,c+c)(r+r^{\prime},c+c^{\prime}) such that

  • (r,c)π(r,c)\in\pi^{\prime}, λ(r,c)\lambda^{\prime}(r,c)\neq\Box, and

  • rr^{\prime} [resp. cc^{\prime}] is kk-\ell, where

    • kk is the number of occurrences of letters from 𝔸>\mathbb{A}_{>} in w1w_{1} [resp. in w2w_{2}] before the rr-th [resp. cc-th] appearance of a letter from 𝔸\mathbb{A}_{\leq}, and

    • \ell is the number of letters \Box in (π,λ)[1,r](\pi^{\prime},\lambda^{\prime})_{\rightarrow}[1,r] [resp. in (π,λ)[1,c](\pi^{\prime},\lambda^{\prime})_{\downarrow}[1,c]].

    Note that kk\geq\ell.

We define λ𝔸(r+r,c+c)=λ(r,c)\lambda_{\mathbb{A}_{\leq}}(r+r^{\prime},c+c^{\prime})=\lambda^{\prime}(r,c). We have that (π𝔸,λ𝔸)(\pi_{\mathbb{A}_{\leq}},\lambda_{\mathbb{A}_{\leq}}) is a labeled permutation over X𝔸X_{\mathbb{A}_{\leq}} satisfying RR, as (π,λ)(\pi^{\prime},\lambda^{\prime}) satisfies RR by (3). In fact, it is equivalent to (π,λ)(\pi^{\prime},\lambda^{\prime}) when restricted to elements with labels in 𝔸\mathbb{A}_{\leq} (cf. Figures 3-aa, 3-bb).

Refer to caption
Figure 3: Example where 𝔸={a,b}\mathbb{A}_{\leq}=\{a,b\}, 𝔸>={c,d}\mathbb{A}_{>}=\{c,d\}, w1=ddccdabw_{1}=ddccdab, w2=bcddcdaw_{2}=bcddcda, m=7m=7. For illustration purposes, we let the threshold defining 𝔸\mathbb{A}_{\leq} and 𝔸>\mathbb{A}_{>} to be 11 instead of 1717.

We build, for every H𝔸>H\subseteq\mathbb{A}_{>}, a labeled permutation (π𝔸H,λ𝔸H)(\pi_{\mathbb{A}_{\leq}\cup H},\lambda_{\mathbb{A}_{\leq}\cup H}) over X𝔸HX_{\mathbb{A}_{\leq}\cup H} satisfying RR, so that (π𝔸H,λ𝔸H)(\pi_{\mathbb{A}_{\leq}\cup H},\lambda_{\mathbb{A}_{\leq}\cup H})_{\rightarrow} [resp. (π𝔸H,λ𝔸H)(\pi_{\mathbb{A}_{\leq}\cup H},\lambda_{\mathbb{A}_{\leq}\cup H})_{\downarrow}] is w1w_{1} [resp. w2w_{2}] projected onto 𝔸H\mathbb{A}_{\leq}\cup H. Note that when H=𝔸>H=\mathbb{A}_{>}, (π𝔸H,λ𝔸H)(\pi_{\mathbb{A}_{\leq}\cup H},\lambda_{\mathbb{A}_{\leq}\cup H}) is the labeled permutation over X𝔸=[m]×[m]X_{\mathbb{A}}=[m]\times[m] we are looking for. We build these inductively.

The base case is when H=H=\emptyset and we then have (π𝔸,λ𝔸)(\pi_{\mathbb{A}_{\leq}},\lambda_{\mathbb{A}_{\leq}}), which clearly satisfies RR. Suppose now we have constructed (π𝔸H,λ𝔸H)(\pi_{\mathbb{A}_{\leq}\cup H},\lambda_{\mathbb{A}_{\leq}\cup H}) for some HH, and let a𝔸>a\in\mathbb{A}_{>} be such that aHa\not\in H. Let ζa\zeta_{a} be the set of all (r,c)Xa(r,c)\in X_{a} such that there is some (r,c)π𝔸H(r^{\prime},c^{\prime})\in\pi_{\mathbb{A}_{\leq}\cup H} with |rr|=|cc|=1|r-r^{\prime}|=|c-c^{\prime}|=1. Using Corollary 2 one can show that there is always a permutation over XaX_{a} satisfying ζa\zeta_{a}, so that it does not have any two elements one next to the other. In the example of Figure 3, we see in item cc an illustration of a possible such permutation over XdX_{d}, and the constraints originating in this case from (π𝔸,λ𝔸)(\pi_{\mathbb{A}_{\leq}},\lambda_{\mathbb{A}_{\leq}}).)

Claim 3.

There is a permutation πa\pi_{a} over XaX_{a} satisfying the constraints ζa\zeta_{a} such that there are no two (r,c),(r,c)πa(r,c),(r^{\prime},c^{\prime})\in\pi_{a} with |rr|=|cc|=1|r-r^{\prime}|=|c-c^{\prime}|=1.

Proof.

We first partition XaX_{a} into two sets XaX^{\prime}_{a}, Xa′′X^{\prime\prime}_{a} so that there are no two elements in XaX^{\prime}_{a} (resp. Xa′′X^{\prime\prime}_{a}) with neighboring rows or columns. Let XaX^{\prime}_{a} be the set of all (r,c)Xa(r,c)\in X_{a} such that #{rrr(r,c)Xa}\#\{r^{\prime}\mid r^{\prime}\leq r\land(r^{\prime},c)\in X_{a}\} and #{ccc(r,c)Xa}\#\{c^{\prime}\mid c^{\prime}\leq c\land(r,c^{\prime})\in X_{a}\} are odd; and let Xa′′X^{\prime\prime}_{a} be the set of all (r,c)Xa(r,c)\in X_{a} such that #{rrr(r,c)Xa}\#\{r^{\prime}\mid r^{\prime}\leq r\land(r^{\prime},c)\in X_{a}\} and #{ccc(r,c)Xa}\#\{c^{\prime}\mid c^{\prime}\leq c\land(r,c^{\prime})\in X_{a}\} are even. Since #Xa182\#X_{a}\geq 18^{2}, we have that #Xa92\#X^{\prime}_{a}\geq 9^{2} and #Xa′′92\#X^{\prime\prime}_{a}\geq 9^{2}. Note that ζa\zeta_{a} does not have more than 44 restrictions on each row and on each column. Then, ζaXa\zeta_{a}\cap X^{\prime}_{a} is an (,4)(\ell,4)-constraint with 9\ell\geq 9. Hence, by Corollary 2, there exists a permutation πa\pi^{\prime}_{a} over XaX^{\prime}_{a} that satisfies ζaXa\zeta_{a}\cap X^{\prime}_{a}. Now let ζa\zeta^{\prime}_{a} be the set of all (r,c)Xa′′(r,c)\in X^{\prime\prime}_{a} such that there is some (r,c)πaπ𝔸H(r^{\prime},c^{\prime})\in\pi^{\prime}_{a}\cup\pi_{\mathbb{A}_{\leq}\cup H} where |rr|=|cc|=1|r-r^{\prime}|=|c-c^{\prime}|=1. Notice that ζaXa′′ζa\zeta_{a}\cap X^{\prime\prime}_{a}\subseteq\zeta^{\prime}_{a}. Remember that #Xa′′92\#X^{\prime\prime}_{a}\geq 9^{2} and note that ζa\zeta^{\prime}_{a} does not have more than 44 restrictions on each row and on each column. Then, applying again Corollary 2, there is a permutation πa′′\pi^{\prime\prime}_{a} over Xa′′X^{\prime\prime}_{a} that satisfies ζaXa′′\zeta^{\prime}_{a}\cap X^{\prime\prime}_{a}. By definition of XaX^{\prime}_{a} and Xa′′X^{\prime\prime}_{a} we have that πa=πaπa′′\pi_{a}=\pi^{\prime}_{a}\cup\pi^{\prime\prime}_{a} is a permutation over XaX_{a} that satisfies both ζaXa\zeta_{a}\cap X^{\prime}_{a} and ζa\zeta^{\prime}_{a}. Further, since ζaXa′′ζa\zeta_{a}\cap X^{\prime\prime}_{a}\subseteq\zeta^{\prime}_{a}, we have that πa\pi_{a} satisfies ζa\zeta_{a}. Also, by definition of ζa\zeta^{\prime}_{a}, we further have that there are no two (r,c),(r,c)πa(r,c),(r^{\prime},c^{\prime})\in\pi_{a} with |rr|=|cc|=1|r-r^{\prime}|=|c-c^{\prime}|=1. ∎

We therefore define the new permutation π𝔸H{a}=πaπ𝔸H\pi_{\mathbb{A}_{\leq}\cup H\cup\{a\}}=\pi_{a}\cup\pi_{\mathbb{A}_{\leq}\cup H}; and λ𝔸H{a}(r,c)=a\lambda_{\mathbb{A}_{\leq}\cup H\cup\{a\}}(r,c)=a for all (r,c)Xa(r,c)\in X_{a}, and λ𝔸H{a}(r,c)=λ𝔸H(r,c)\lambda_{\mathbb{A}_{\leq}\cup H\cup\{a\}}(r,c)=\lambda_{\mathbb{A}_{\leq}\cup H}(r,c) otherwise. Note that it satisfies RR since for all new positions (r,c)(r,c) added there is no other position (r,c)(r^{\prime},c^{\prime}) such that |rr|=|cc|=1|r-r^{\prime}|=|c-c^{\prime}|=1.

Finally, the desired labeled permutation is (π𝔸𝔸>,λ𝔸𝔸>)(\pi_{\mathbb{A}_{\leq}\cup\mathbb{A}_{>}},\lambda_{\mathbb{A}_{\leq}\cup\mathbb{A}_{>}}).

[][\Leftarrow] Suppose that pk(L(𝒜1))pk(L(𝒜2))=pk(L(\mathcal{A}^{\prime}_{1}))~\cap~pk(L(\mathcal{A}^{\prime}_{2}))=\emptyset; we show that there is no labeled permutation (π,λ)(\pi,\lambda) verifying the restrictions imposed by the problem.

First, we show that there cannot be a solution whose every label appears at most 1717 times. By means of contradiction, suppose (π,λ)(\pi,\lambda) is such a solution. Then, the algorithm can guess (π,λ)(\pi,\lambda), and we would then have that, by construction, pk(L(𝒜1))=pk(L(𝒜2))pk(L(\mathcal{A}^{\prime}_{1}))=pk(L(\mathcal{A}^{\prime}_{2}))\neq\emptyset, which is in contradiction of our hypothesis.

Now suppose that (π,λ)(\pi,\lambda) is a solution, where 𝔸>\mathbb{A}_{>}\neq\emptyset is the set of letters that appear more than 1717 times in (π,λ)(\pi,\lambda). Let (π′′,λ′′)(\pi^{\prime\prime},\lambda^{\prime\prime}) be the replacement in (π,λ)(\pi,\lambda) of every label from 𝔸>\mathbb{A}_{>} with \Box. We can now build (π,λ)(\pi^{\prime},\lambda^{\prime}) from (π′′,λ′′)(\pi^{\prime\prime},\lambda^{\prime\prime}), by replacing each block containing only elements \Box (and is maximal in size with respect to this property) with only one element \Box. For example, if (π′′,λ′′)(\pi^{\prime\prime},\lambda^{\prime\prime}) is as depicted in Figure 2-bb, we produce (π,λ)(\pi^{\prime},\lambda^{\prime}) by removing two rows and two columns, ending up with the labeled permutation of Figure 2-cc.

Let e1,e2,𝒜>,𝒜1,𝒜2\textit{e}_{1},\textit{e}_{2},\mathcal{A}_{>},\mathcal{A}_{1}^{\prime},\mathcal{A}^{\prime}_{2} be defined as before from (π,λ)(\pi^{\prime},\lambda^{\prime}). It is clear that (π,λ)(\pi,\lambda)_{\rightarrow} is in L(e1)L(\textit{e}_{1}) and (π,λ)(\pi,\lambda)_{\rightarrow} in L(e2)L(\textit{e}_{2}). It is therefore true that (π,λ)L(𝒜1)(\pi,\lambda)_{\rightarrow}\in L(\mathcal{A}_{1}^{\prime}) and (π,λ)L(𝒜2)(\pi,\lambda)_{\downarrow}\in L(\mathcal{A}_{2}^{\prime}). Since (π,λ)(\pi,\lambda) is a labeled permutation we have that pk((π,λ))=pk((π,λ))pk((\pi,\lambda)_{\rightarrow})=pk((\pi,\lambda)_{\downarrow}). Then, pk(L(𝒜1))pk(L(𝒜2))pk(L(\mathcal{A}^{\prime}_{1}))~\cap~pk(L(\mathcal{A}^{\prime}_{2}))\neq\emptyset, which is in contradiction with our hypothesis. Therefore, if pk(L(𝒜1))pk(L(𝒜2))=pk(L(\mathcal{A}^{\prime}_{1}))~\cap~pk(L(\mathcal{A}^{\prime}_{2}))=\emptyset, there cannot be a solution (π,λ)(\pi,\lambda) to the RLP instance. ∎

6.2 Satisfiability for FO2\textup{FO}^{\textup{2}}

We now show that there is a NExpTime reduction from the satisfiability problem for FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) into the RLP problem. This, combined with the fact that RLP is in NP (Proposition 4), concludes the proof of Theorem 1, showing that the satisfiability problem for FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) is in NExpTime; hence it is NExpTime-complete [4].

Before going into the reduction, we show that the satisfaction of a formula in a valued permutation depends solely on its sets of fingerprints, plus some summary information. This summary information says, for every possible valuation SS, how many times SS appears in (π,σ)(\pi,\sigma) (counting up to a threshold of 3). In the reduction from FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) into RLP we guess the summary information and set of fingerprints of a minimal model (bounded by Propositions 1 and 2), translating the formula into a RLP instance.

Definition 7.

Given a set of fingerprints XX, let X^\hat{X} be the set of all the valuations in XX, that is X^={τ[i]τX,1i|τ|τ[i]}\hat{X}=\{\tau_{\rightarrow}[i]\mid\tau\in X,1\leq i\leq|\tau_{\rightarrow}|\land\tau_{\rightarrow}[i]\neq\bot\}. Given a set of fingerprints XX and disjoint sets of valuations V1,V2,V3X^V_{1},V_{2},V_{3}\subseteq\hat{X}, a valued permutation (π,σ)(\pi,\sigma) over X,V1,V2,V3X,V_{1},V_{2},V_{3} is any valued permutation such that XX is the set of fingerprints of (π,σ)(\pi,\sigma), and for every 1i31\leq i\leq 3, ViV_{i} is the set of valuations that appear exactly ii times in (π,σ)(\pi,\sigma). We also say that X,V1,V2,V3X,V_{1},V_{2},V_{3} is the summary of (π,σ)(\pi,\sigma).

Given a formula y.ψ\forall y.\psi where ψ\psi is a quantifier-free formula, and a valued permutation (π,σ)(\pi,\sigma) with a block BB, whether all the elements from BB verify y.ψ\forall y.\psi or not, depends only on: the summary of (π,σ)(\pi,\sigma), and the fingerprint of BB. Similarly for formulas y.ψ\exists y.\psi. Moreover, we can test this in polynomial time.

We introduce the concept of a fingerprint being consistent with a formula xy.χ\forall x\forall y.\chi [resp. xy.ψ\forall x\exists y.\psi] and a summary.666In fact, we do not need the set of fingerprints XX to define this notion but just the set of valuations X^\hat{X}, and it is therefore defined over X^\hat{X}. These are the necessary and sufficient conditions to ensure that every element of a block with such fingerprint in a valued permutation over such summary satisfies y.χ\forall y.\chi [resp. y.ψ\exists y.\psi].

First, note that for any quantifier-free formula ψ\psi of FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}), the validity of (π,σ)μψ(\pi,\sigma)\models_{\mu}\psi only depends on: SS, SS^{\prime} and tt, where: S=σ(μ(x))S=\sigma(\mu(x)), S=σ(μ(y))S^{\prime}=\sigma(\mu(y)), and t=[μ(x),μ(y)]πt=[\mu(x),\mu(y)]_{\pi}. We will then write (S)t(S)ψ(S)\,{t}\,(S^{\prime})\models\psi, to denote that ψ\psi holds in any model that assigns SS to xx, SS^{\prime} to yy and so that the neighborhood type between xx and yy is tt. Notice that we can decide (S)t(S)ψ(S)\,{t}\,(S^{\prime})\models\psi in polynomial time. For example, if ψ=xy(a(x)¬b(y))\psi={x{\rightarrow}y}\land(a(x)\lor\lnot b(y)), we have ({b})({a,c})ψ(\{b\})\,{\nearrow}\,(\{a,c\})\models\psi but ({a})({a,b})⊧̸ψ(\{a\})\,{\downarrow}\,(\{a,b\})\not\models\psi.

The formal definition of consistency is given next.

Definition 8.

r Let τ\tau be a fingerprint, and m=|τ|m=|\tau_{\rightarrow}|. Given a set of valuations Y2𝒱φY\subseteq 2^{\mathcal{V}_{\varphi}} and three disjoint sets V1,V2,V3YV_{1},V_{2},V_{3}\subseteq Y, we say that τ\tau is consistent with a universal formula y.χ\forall y.\chi and V1,V2,V3,YV_{1},V_{2},V_{3},Y if all of the following conditions hold:

  1. 1.

    For every 1<i<m1<i<m, we have (τ[i])(τ[i])χ(\tau_{\rightarrow}[i])\,{\bullet}\,(\tau_{\rightarrow}[i])\models\chi.

  2. 2.

    If τ[1]\tau_{\rightarrow}[1]\neq\bot, (τ[2])(τ[1])χ(\tau_{\rightarrow}[2])\,{\leftarrow}\,(\tau_{\rightarrow}[1])\models\chi.

  3. 3.

    If τ[m]\tau_{\rightarrow}[m]\neq\bot, (τ[m1])(τ[m])χ(\tau_{\rightarrow}[m-1])\,{\rightarrow}\,(\tau_{\rightarrow}[m])\models\chi.

  4. 4.

    For every 1<i,i+1<m1<i,i+1<m, if type(τ)=\textrm{type}(\tau)=\searrow, (τ[i])(τ[i+1])χ(\tau_{\rightarrow}[i])\,{\searrow}\,(\tau_{\rightarrow}[i+1])\models\chi, (τ[i+1])(τ[i])χ(\tau_{\rightarrow}[i+1])\,{\nwarrow}\,(\tau_{\rightarrow}[i])\models\chi, otherwise, if type(τ)=\textrm{type}(\tau)=\nearrow, (τ[i])(τ[i+1])χ(\tau_{\rightarrow}[i])\,{\nearrow}\,(\tau_{\rightarrow}[i+1])\models\chi, (τ[i+1])(τ[i])χ(\tau_{\rightarrow}[i+1])\,{\swarrow}\,(\tau_{\rightarrow}[i])\models\chi.

  5. 5.

    For every 1i1,i,i+1m1\leq i-1,i,i+1\leq m,

    • for every gY{τ[i1],τ[i],τ[i+1]}g\in Y\setminus\{\tau_{\rightarrow}[i-1],\tau_{\rightarrow}[i],\tau_{\rightarrow}[i+1]\} then (τ[i])(g)χ(\tau_{\rightarrow}[i])\,{\infty}\,(g)\models\chi,

    • for every g{τ[i1],τ[i],τ[i+1]}g\in\{\tau_{\rightarrow}[i-1],\tau_{\rightarrow}[i],\tau_{\rightarrow}[i+1]\}, if gVjg\not\in V_{j} for j=#{t{1,0,1}τ[i+t]=g}j=\#\{t\in\{1,0,-1\}\mid\tau_{\rightarrow}[i+t]=g\} then (τ[i])(g)χ(\tau_{\rightarrow}[i])\,{\infty}\,(g)\models\chi.

  6. 6.

    Idem to items 2 and 3, but replacing {\rightarrow} with {\downarrow}, \leftarrow with \uparrow, and τ\tau_{\rightarrow} with τ\tau_{\downarrow}.

We say that τ\tau is consistent with an existential formula y.ψ\exists y.\psi if for every 1<i<m1<i<m either

  1. 1.
    1. (a)

      (τ[i])(τ[i])ψ(\tau_{\rightarrow}[i])\,{\bullet}\,(\tau_{\rightarrow}[i])\models\psi,

    2. (b)

      i+1=mi+1=m and τ[i+1]\tau_{\rightarrow}[i+1]\neq\bot and (τ[i])(τ[i+1])ψ(\tau_{\rightarrow}[i])\,{\rightarrow}\,(\tau_{\rightarrow}[i+1])\models\psi, or

    3. (c)

      i=2i=2, τ[1]\tau_{\rightarrow}[1]\neq\bot and (τ[2])(τ[1])ψ(\tau_{\rightarrow}[2])\,{\leftarrow}\,(\tau_{\rightarrow}[1])\models\psi,

  2. 2.

    type(τ)=\textrm{type}(\tau)=\searrow, and either

    1. (a)

      1<i,i+1<m1<i,i+1<m and (τ[i])(τ[i+1])ψ(\tau_{\rightarrow}[i])\,{\searrow}\,(\tau_{\rightarrow}[i+1])\models\psi,

    2. (b)

      1<i1,i<m1<i-1,i<m and (τ[i])(τ[i1])ψ(\tau_{\rightarrow}[i])\,{\nwarrow}\,(\tau_{\rightarrow}[i-1])\models\psi,

    3. (c)

      1i1,i,i+1m1\leq i-1,i,i+1\leq m and there is some gY{τ[i1],τ[i],τ[i+1]}g\in Y\setminus\{\tau_{\rightarrow}[i-1],\tau_{\rightarrow}[i],\tau_{\rightarrow}[i+1]\}, such that (τ[i])(g)ψ(\tau_{\rightarrow}[i])\,{\infty}\,(g)\models\psi, or

    4. (d)

      1i1,i,i+1m1\leq i-1,i,i+1\leq m and there is g{τ[i1],τ[i],τ[i+1]}g\in\{\tau_{\rightarrow}[i-1],\tau_{\rightarrow}[i],\tau_{\rightarrow}[i+1]\} with gVjg\not\in V_{j} for j=#{t{1,0,1}τ[i+t]=g}j=\#\{t\in\{1,0,-1\}\mid\tau_{\rightarrow}[i+t]=g\} such that (τ[i])(g)ψ(\tau_{\rightarrow}[i])\,{\infty}\,(g)\models\psi,

  3. 3.

    type(τ)=\textrm{type}(\tau)=\nearrow, and some condition as the ones in item 2 holds, where \searrow and \nwarrow are replaced with \nearrow and \swarrow, or

  4. 4.

    Idem as condition 11, replacing {\rightarrow} with {\downarrow}, \leftarrow with \uparrow, and τ\tau_{\rightarrow} with τ\tau_{\downarrow}.

Finally, we say that a fingerprint τ\tau is consistent with a formula in Scott normal form φ=xy.χixy.ψi\varphi=\forall x\forall y.\chi\land\bigwedge_{i}\forall x\exists y.\psi_{i} and sets Y,V1,V2,V3Y,V_{1},V_{2},V_{3} if it is consistent with y.χ\forall y.\chi and with y.ψi\exists y.\psi_{i} for all ii.

The following Lemmas follow straightforward from the previous definitions.

Lemma 1.

For every valued permutation (π,σ)(\pi,\sigma) over X,V1,V2,V3X,V_{1},V_{2},V_{3}, with a maximal block BB, and for every formula y.χ\forall y.\chi where χ\chi is quantifier-free, we have that all the elements from BB verify y.χ\forall y.\chi if and only if ξ(B)\xi(B) is consistent with y.χ\forall y.\chi and X^,V1,V2,V3\hat{X},V_{1},V_{2},V_{3}.

Lemma 2.

For every valued permutation (π,σ)(\pi,\sigma) over X,V1,V2,V3X,V_{1},V_{2},V_{3}, with a maximal block BB, for every formula y.ψ\exists y.\psi where ψ\psi is quantifier-free, we have that all the elements from BB verify y.ψ\exists y.\psi if and only if ξ(B)\xi(B) is consistent with y.ψ\exists y.\psi and X^,V1,V2,V3\hat{X},V_{1},V_{2},V_{3}.

Remark 2.

Note that the property of consistency of Definition 8 can be checked in polynomial time.

Lemma 3.

There is a NExpTime reduction from the satisfiability problem for FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) into the RLP problem.

Proof.

Let φFO2(,)\varphi\in\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) be in Scott normal form, φ=xy.χixy.ψi\varphi=\forall x\forall y.\chi\land\bigwedge_{i}\forall x\exists y.\psi_{i}. By Proposition 2, there are at most an exponential number of different fingerprints, and by Proposition 1 each one of them is at most of exponential size. The algorithm guesses the set XX of all fingerprints needed in a minimal valued permutation that satisfies φ\varphi, and summary sets V1,V2,V3X^V_{1},V_{2},V_{3}\subseteq\hat{X}. The algorithm checks that for every τX\tau\in X, τ\tau is consistent with φ\varphi and X^,V1,V2,V3\hat{X},V_{1},V_{2},V_{3}.

We define the language 1X\mathcal{L}_{1}\subseteq X^{*} [resp. 2X\mathcal{L}_{2}\subseteq X^{*}] of all words wXw\in X^{*} such that

  • the first element of (w[1])(w[1])_{\rightarrow} [resp. of (w[1])(w[1])_{\downarrow}] is \bot, and the last element of (w[|w|])(w[|w|])_{\rightarrow} [resp. of (w[|w|])(w[|w|])_{\downarrow}] is \bot,

  • for every 1i<|w|1\leq i<|w| such that (w[i])=a1an1an(w[i])_{\rightarrow}=a_{1}\dotsb a_{n-1}a_{n} [resp. (w[i])=a1an1an(w[i])_{\downarrow}=a_{1}\dotsb a_{n-1}a_{n}] and (w[i+1])=b1b2bm(w[i+1])_{\rightarrow}=b_{1}b_{2}\dotsb b_{m} [resp. (w[i+1])=b1b2bm(w[i+1])_{\downarrow}=b_{1}b_{2}\dotsb b_{m}] we have an1an=b1b2a_{n-1}a_{n}=b_{1}b_{2},

  • all the elements of XX appear in ww,

  • for every 1i31\leq i\leq 3, ViV_{i} is the set of valuations that appear exactly ii times in w^\hat{w}, where w^=w^1w^|w|\hat{w}=\hat{w}_{1}\dotsb\hat{w}_{|w|} and w^i=(w[i])[2](w[i])[mi1]\hat{w}_{i}=(w[i])_{\rightarrow}[2]\dotsb(w[i])_{\rightarrow}[m_{i}-1] for mi=|(w[i])|m_{i}=|(w[i])_{\rightarrow}|.

It is immediate that 1\mathcal{L}_{1} and 2\mathcal{L}_{2} are regular languages, and that they can be defined by two NFA that can be built in polynomial time in the size of XX.

Finally, we define the label restrictions, avoiding having two blocks that actually define a bigger block (because these blocks are supposed to be maximal). Let RR be the set of all triples (τ,d,τ)(\tau,d,\tau^{\prime}) such that τ,τX\tau,\tau^{\prime}\in X and either

  • d=d=\searrow, type(τ)\textrm{type}(\tau)\neq\nearrow, type(τ)\textrm{type}(\tau^{\prime})\neq\nearrow, or

  • d=d=\nearrow, type(τ)\textrm{type}(\tau)\neq\searrow, type(τ)\textrm{type}(\tau^{\prime})\neq\searrow.

We reduced the satisfiability problem into the RLP problem for (X,R,1,2)(X,R,\mathcal{L}_{1},\mathcal{L}_{2}), concluding the proof.

Claim 4.

The RLP instance (X,R,1,2)(X,R,\mathcal{L}_{1},\mathcal{L}_{2}) has a positive solution iff the formula φ\varphi is satisfiable.∎

7 Conclusion

Our work shows that the following combinatorial problem is at the core of the satisfiability for FO2(,)\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) and of the RLP problem, and is decidable in NP. Given two regular languages ,𝔸\mathcal{L},\mathcal{L}^{\prime}\subseteq\mathbb{A}^{*}, is there a word a1ana_{1}\dotsb a_{n}\in\mathcal{L} and a permutation p:[n][n]p:[n]\to[n] so that ap(1)ap(n)a_{p(1)}\dotsb a_{p(n)}\in\mathcal{L}^{\prime} and |p(i+1)p(i)|>1|p(i+1)-p(i)|>1 for all i[n]i\in[n]?

A natural question left open is whether this decidability result can be extended to FO2\textup{FO}^{\textup{2}} with kk successor relations over finite linear orders is decidable, for arbitrary kk (or at least for k=3k=3).

References

  • [1] Mikołaj Bojańczyk, Claire David, Anca Muscholl, Thomas Schwentick, and Luc Segoufin. Two-variable logic on data words. ACM Trans. Comput. Log., 2010.
  • [2] Mikołaj Bojańczyk, Anca Muscholl, Thomas Schwentick, and Luc Segoufin. Two-variable logic on data trees and XML reasoning. Journal of the ACM, 56(3):1–48, 2009.
  • [3] Reinhard Diestel. Graph Theory, volume 173 of Graduate Texts in Mathematics. Springer-Verlag, Heidelberg, third edition, 2005.
  • [4] Kousha Etessami, Moshe Y. Vardi, and Thomas Wilke. First-order logic with two variables and unary temporal logic. Inf. Comput., 179(2):279–295, 2002.
  • [5] Erich Grädel, Phokion G. Kolaitis, and Moshe Y. Vardi. On the decision problem for two-variable first-order logic. Bulletin of Symbolic Logic, 3(1):53–69, 1997.
  • [6] Erich Grädel and Martin Otto. On logics with two variables. Theoretical Computer Science, 224(1-2):73–113, 1999.
  • [7] Philip Hall. On representatives of subsets. Journal of the London Mathematical Society, 10:26–30, 1935.
  • [8] Emanuel Kieroński. Results on the guarded fragment with equivalence or transitive relations. In CSL, volume 3634 of Lecture Notes in Computer Science, pages 309–324. Springer, 2005.
  • [9] Emanuel Kieroński. Decidability issues for two-variable logics with several linear orders. In EACSL Annual Conference on Computer Science Logic (CSL’11), volume 12 of Leibniz International Proceedings in Informatics (LIPIcs), pages 337–351. Schloss Dagstuhl, 2011.
  • [10] Emanuel Kieroński and Martin Otto. Small substructures and decidability issues for first-order logic with two variables. In LICS, pages 448–457. IEEE Computer Society, 2005.
  • [11] Emanuel Kieroński and Lidia Tendera. On finite satisfiability of two-variable first-order logic with equivalence relations. In LICS, pages 123–132. IEEE Computer Society, 2009.
  • [12] Amaldev Manuel. Two orders and two variables. In Int. Symp. on Mathematical Foundations of Comp. Sci. (MFCS’10), Lecture Notes in Computer Science. Springer, 2010.
  • [13] Amaldev Manuel. Personal communication, 2012.
  • [14] Amaldev Manuel and Thomas Zeume. Two-variable logic with a linear successor and a preorder. Unpublished manuscript available at http://www.imsc.res.in/~amal/manuelzeume.pdf, 2011.
  • [15] Michael Mortimer. On languages with two variables. Mathematical Logic Quarterly, 21:135–140, 1975.
  • [16] Christos H. Papadimitriou. On the complexity of integer programming. Journal of the ACM, 28(4):765–768, 1981.
  • [17] Thomas Schwentick and Thomas Zeume. Two-variable logic with two order relations. Logical Methods in Computer Science, 8(1:15):1–27, 2012.
  • [18] Kumar Neeraj Verma, Helmut Seidl, and Thomas Schwentick. On the complexity of equational horn clauses. In International Conference on Automated Deduction (CADE’05), volume 3632 of Lecture Notes in Computer Science, pages 337–352. Springer, 2005.

Appendix A Missing proofs

Proof of Lemma 1.

[\Rightarrow] Suppose that every element (r,c)Bπ(r,c)\in B\cap\pi verifies (π,σ)[x(r,c)]y.χ(\pi,\sigma)\models_{[x\mapsto(r,c)]}\forall y.\chi. We show that τ=ξ(B)\tau=\xi(B) is consistent with y.χ\forall y.\chi and X^,V1,V2,V3\hat{X},V_{1},V_{2},V_{3}.

Condition 1 is met, since in particular (π,σ)[x(r,c),y(r,c)]χ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r,c)]}\chi for every (r,c)Bπ(r,c)\in B\cap\pi; this means that (σ(r,c))(σ(r,c))χ(\sigma(r,c))\,{\bullet}\,(\sigma(r,c))\models\chi, which implies condition 1.

If ii is the smallest column element of BB and i>1i>1, it means that τ[1]\tau_{\rightarrow}[1]\neq\bot, in fact τ[1]=σ(  ,i1)\tau_{\rightarrow}[1]=\sigma(\raisebox{1.30487pt}{\hskip-0.40149pt\text{\lx@text@underline{\hskip 4.73611pt}\hskip 0.6458pt}},i-1). Since for some (r,i),(r,i1)π(r,i),(r^{\prime},i-1)\in\pi, (π,σ)[x(r,i),y(r,i1)]χ(\pi,\sigma)\models_{[x\mapsto(r,i),y\mapsto(r^{\prime},i-1)]}\chi, and since BB is maximal, we have that |rr|>1|r-r^{\prime}|>1 and hence that (σ(r,i))(σ(r,i1))χ(\sigma(r,i))\,{\leftarrow}\,(\sigma(r^{\prime},i-1))\models\chi. As σ(r,i1)=τ[1]\sigma(r^{\prime},i-1)=\tau_{\rightarrow}[1] and σ(r,i)=τ[2]\sigma(r,i)=\tau_{\rightarrow}[2], condition 2 is met. Condition 3 is similar.

Suppose type(τ)=\textrm{type}(\tau)={\searrow} and 1<i,i+1<|τ|1<i,i+1<|\tau_{\rightarrow}|. This means that there are (r,c),(r+1,c+1)Bπ(r,c),(r+1,c+1)\in B\cap\pi with σ(r,c)=τ[i]\sigma(r,c)=\tau_{\rightarrow}[i], σ(r+1,c+1)=τ[i+1]\sigma(r+1,c+1)=\tau_{\rightarrow}[i+1]. Since (π,σ)[x(r,c),y(r+1,c+1)]χ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r+1,c+1)]}\chi and (π,σ)[y(r,c),x(r+1,c+1)]χ(\pi,\sigma)\models_{[y\mapsto(r,c),x\mapsto(r+1,c+1)]}\chi we have that (σ(r,c))(σ(r+1,c+1))χ(\sigma(r,c))\,{\searrow}\,(\sigma(r+1,c+1))\models\chi and (σ(r+1,c+1))(σ(r,c))χ(\sigma(r+1,c+1))\,{\nwarrow}\,(\sigma(r,c))\models\chi. Hence, (τ[i])(τ[i+1])χ(\tau_{\rightarrow}[i])\,{\searrow}\,(\tau_{\rightarrow}[i+1])\models\chi and (τ[i+1])(τ[i])χ(\tau_{\rightarrow}[i+1])\,{\nwarrow}\,(\tau_{\rightarrow}[i])\models\chi and thus condition 4 holds. The proof for type(τ)=\textrm{type}(\tau)={\nwarrow} is similar.

Suppose now that 1i1,i,i+1|τ|1\leq i-1,i,i+1\leq|\tau_{\rightarrow}|. Let gX^{τ[i1],τ[i],τ[i+1]}g\in\hat{X}\setminus\{\tau_{\rightarrow}[i-1],\tau_{\rightarrow}[i],\tau_{\rightarrow}[i+1]\}. This means that there is some (r,c)Bπ(r,c)\in B\cap\pi with σ(r,c)=τ[i]\sigma(r,c)=\tau_{\rightarrow}[i] and some (r,c)π(r^{\prime},c^{\prime})\in\pi with σ(r,c)=g\sigma(r^{\prime},c^{\prime})=g, [(r,c),(r,c)]π=[(r,c),(r^{\prime},c^{\prime})]_{\pi}=\infty. Since (π,σ)[x(r,c),y(r,c)]χ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r^{\prime},c^{\prime})]}\chi, we have that (σ(r,c))(σ(r,c))χ(\sigma(r,c))\,{\infty}\,(\sigma(r^{\prime},c^{\prime}))\models\chi and hence the first part of condition 5 is met. On the other hand, if g{τ[i1],τ[i],τ[i+1]}g\in\{\tau_{\rightarrow}[i-1],\tau_{\rightarrow}[i],\tau_{\rightarrow}[i+1]\} and gVjg\not\in V_{j} for j=#{t{1,0,1}τ[i+t]=g}j=\#\{t\in\{1,0,-1\}\mid\tau_{\rightarrow}[i+t]=g\}, this means that there must be necessarily some other position with valuation gg. That is, there is some (r,c)π(r^{\prime},c^{\prime})\in\pi with σ(r,c)=g\sigma(r^{\prime},c^{\prime})=g, [(r,c),(r,c)]π=[(r,c),(r^{\prime},c^{\prime})]_{\pi}=\infty. Then, the same reasoning as before applies to show that the second part of condition 5 is met.

[\Leftarrow] Suppose that τ=ξ(B)\tau=\xi(B) is consistent with y.χ\forall y.\chi and X^,V1,V2,V3\hat{X},V_{1},V_{2},V_{3}. Let us show that every element (r,c)Bπ(r,c)\in B\cap\pi verifies (π,σ)[x(r,c)]y.χ(\pi,\sigma)\models_{[x\mapsto(r,c)]}\forall y.\chi.

Let (r,c)Bπ(r,c)\in B\cap\pi and (r,c)π(r^{\prime},c^{\prime})\in\pi. If [(r,c),(r,c)]π=[(r,c),(r^{\prime},c^{\prime})]_{\pi}=\bullet then (π,σ)[x(r,c),y(r,c)]χ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r^{\prime},c^{\prime})]}\chi by condition 1. If [(r,c),(r,c)]π=[(r,c),(r^{\prime},c^{\prime})]_{\pi}={\leftarrow}, then (π,σ)[x(r,c),y(r,c)]χ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r^{\prime},c^{\prime})]}\chi by condition 2. If [(r,c),(r,c)]π=[(r,c),(r^{\prime},c^{\prime})]_{\pi}={\rightarrow}, then (π,σ)[x(r,c),y(r,c)]χ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r^{\prime},c^{\prime})]}\chi by condition 3. If [(r,c),(r,c)]π{,,,}[(r,c),(r^{\prime},c^{\prime})]_{\pi}\in\{\nearrow,\nwarrow,\searrow,\swarrow\}, then (π,σ)[x(r,c),y(r,c)]χ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r^{\prime},c^{\prime})]}\chi by condition 4. And if [(r,c),(r,c)]π=[(r,c),(r^{\prime},c^{\prime})]_{\pi}=\infty, then (π,σ)[x(r,c),y(r,c)]χ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r^{\prime},c^{\prime})]}\chi by condition 5. Hence, every element (r,c)Bπ(r,c)\in B\cap\pi verifies (π,σ)[x(r,c)]y.χ(\pi,\sigma)\models_{[x\mapsto(r,c)]}\forall y.\chi. ∎

Proof of Lemma 2.

[\Rightarrow] Suppose that every element (r,c)Bπ(r,c)\in B\cap\pi verifies (π,σ)[x(r,c)]y.ψ(\pi,\sigma)\models_{[x\mapsto(r,c)]}\exists y.\psi. We show that τ=ξ(B)\tau=\xi(B) is consistent with y.ψ\exists y.\psi and X^,V1,V2,V3\hat{X},V_{1},V_{2},V_{3}.

Let (r,c)Bπ(r,c)\in B\cap\pi, then there must be (r,c)π(r^{\prime},c^{\prime})\in\pi such that (π,σ)[x(r,c),y(r,c)]ψ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r^{\prime},c^{\prime})]}\psi. If [(c,r),(r,c)]π=[(c,r),(r^{\prime},c^{\prime})]_{\pi}={\bullet} then condition 1a is met. If [(c,r),(r,c)]π=[(c,r),(r^{\prime},c^{\prime})]_{\pi}={\rightarrow}, then condition 1b is met. If [(c,r),(r,c)]π=[(c,r),(r^{\prime},c^{\prime})]_{\pi}={\leftarrow}, then condition 1c is met. If [(c,r),(r,c)]π=[(c,r),(r^{\prime},c^{\prime})]_{\pi}={\searrow}, then condition 2a is met. If [(c,r),(r,c)]π=[(c,r),(r^{\prime},c^{\prime})]_{\pi}={\nwarrow}, then condition 2b is met. If [(c,r),(r,c)]π=[(c,r),(r^{\prime},c^{\prime})]_{\pi}={\infty}, then either condition 2c or 2d is met. If [(c,r),(r,c)]π{,}[(c,r),(r^{\prime},c^{\prime})]_{\pi}\in\{\nearrow,\swarrow\}, then condition 3 is met. If [(c,r),(r,c)]π{,}[(c,r),(r^{\prime},c^{\prime})]_{\pi}\in\{\uparrow,\downarrow\}, then condition 4 is met. Thus, τ=ξ(B)\tau=\xi(B) is consistent with y.ψ\exists y.\psi and X^,V1,V2,V3\hat{X},V_{1},V_{2},V_{3}.

[\Leftarrow] Suppose that τ=ξ(B)\tau=\xi(B) is consistent with y.ψ\exists y.\psi and X^,V1,V2,V3\hat{X},V_{1},V_{2},V_{3}. Let us show that every element (r,c)Bπ(r,c)\in B\cap\pi verifies (π,σ)[x(r,c)]y.ψ(\pi,\sigma)\models_{[x\mapsto(r,c)]}\exists y.\psi.

Let (r,c)Bπ(r,c)\in B\cap\pi. There must be some 1<i<|τ|1<i<|\tau_{\rightarrow}| such that τ[i]=σ(r,c)\tau_{\rightarrow}[i]=\sigma(r,c). If condition 1a holds, then (π,σ)[x(r,c),y(r,c)]ψ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r,c)]}\psi. If condition 1b holds, then (π,σ)[x(r,c),y(r,c+1)]ψ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r^{\prime},c+1)]}\psi for some (r,c+1)π(r^{\prime},c+1)\in\pi with |rr|>1|r^{\prime}-r|>1. If condition 1c holds, then (π,σ)[x(r,c),y(r,c1)]ψ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r^{\prime},c-1)]}\psi for some (r,c1)π(r^{\prime},c-1)\in\pi with |rr|>1|r^{\prime}-r|>1. If condition 2a holds, then (π,σ)[x(r,c),y(r+1,c+1)]ψ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r+1,c+1)]}\psi for (r+1,c+1)π(r+1,c+1)\in\pi. If condition 2b holds, then (π,σ)[x(r,c),y(r1,c1)]ψ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r-1,c-1)]}\psi for (r1,c1)π(r-1,c-1)\in\pi. If condition 2c or 2d holds, then (π,σ)[x(r,c),y(r1,c1)]ψ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r-1,c-1)]}\psi for some (r,c)π(r^{\prime},c^{\prime})\in\pi with [(r,c),(r,c)]π=[(r,c),(r^{\prime},c^{\prime})]_{\pi}=\infty. A similar reasoning applies if 3 or 4 hold. ∎

Proof of Proposition 1.

We show the following statement: Any minimal valued permutation satisfying φFO2(,)\varphi\in\textup{FO}^{\textup{2}}({\rightarrow},{\downarrow}) is such that every block is of size less or equal to

324#𝒱φ+3+23(#𝒱φ+1)+32#𝒱φ.3\cdot 2^{4\#\mathcal{V}_{\varphi}+3}+2^{3(\#\mathcal{V}_{\varphi}+1)}+3\cdot 2^{\#\mathcal{V}_{\varphi}}.

Let (π,σ)(\pi,\sigma) be a minimal valued permutation such that (π,σ)φ(\pi,\sigma)\models\varphi. Without loss of generality assume σ:π2𝒱φ\sigma:\pi\to 2^{\mathcal{V}_{\varphi}}.

Suppose, by means of contradiction, that B=[i,i+k]×[i,i+k]B=[i,i+k]\times[i^{\prime},i^{\prime}+k] is a block of π\pi of size k>324#𝒱φ+3+23(#𝒱φ+1)+32#𝒱φk>3\cdot 2^{4\#\mathcal{V}_{\varphi}+3}+2^{3(\#\mathcal{V}_{\varphi}+1)}+3\cdot 2^{\#\mathcal{V}_{\varphi}}. Let us assume that BB is of type \searrow (if it has type \nearrow a symmetrical reasoning applies). For every S𝒱φS\subseteq\mathcal{V}_{\varphi}, choose any three elements from {(r,c)πBσ(r,c)=S}\{(r,c)\in\pi\cap B\mid\sigma(r,c)=S\}, or, if there are less than three, all the elements; let SπS_{\pi} be the set of these three (or less) elements. Now consider all the sub-blocks BBB^{\prime}\subsetneq B defined strictly between elements of S𝒱φSπ\bigcup_{S\subseteq\mathcal{V}_{\varphi}}S_{\pi}, that is, such that BS𝒱φSπ=B^{\prime}\cap\bigcup_{S\subseteq\mathcal{V}_{\varphi}}S_{\pi}=\emptyset, consider the ones that are maximal with respect to inclusion. Since #S𝒱φSπ32#𝒱φ\#\bigcup_{S\subseteq\mathcal{V}_{\varphi}}S_{\pi}\leq 3\cdot 2^{\#\mathcal{V}_{\varphi}}, there are at most 32#𝒱φ+13\cdot 2^{\#\mathcal{V}_{\varphi}}+1 such sub-blocks having a total of at least k32#𝒱φk-3\cdot 2^{\#\mathcal{V}_{\varphi}} elements. By the Pigeonhole Principle, since k32#𝒱φ>324#𝒱φ+3+23(#𝒱φ+1)=(32#𝒱φ+1)23(#𝒱φ+1)k-3\cdot 2^{\#\mathcal{V}_{\varphi}}>3\cdot 2^{4\#\mathcal{V}_{\varphi}+3}+2^{3(\#\mathcal{V}_{\varphi}+1)}=(3\cdot 2^{\#\mathcal{V}_{\varphi}}+1)\cdot 2^{3(\#\mathcal{V}_{\varphi}+1)}, this means that there must be a sub-block with at least 23(#𝒱φ+1)+12^{3(\#\mathcal{V}_{\varphi}+1)}+1 elements; suppose it is

B=([i+,i++k]×[i+,i++k])B,B^{\prime}=([i+\ell,i+\ell+k^{\prime}]\times[i^{\prime}+\ell,i^{\prime}+\ell+k^{\prime}])\subseteq B,

where k>23(#𝒱φ+1)k^{\prime}>2^{3(\#\mathcal{V}_{\varphi}+1)} and +kk\ell+k^{\prime}\leq k. There must be two distinct elements (r,c),(r,c)πB(r,c),(r^{\prime},c^{\prime})\in\pi\cap B^{\prime} with

σ(r,c)=σ(r,c),σ(r1, )=σ(r1, ), andσ(r+1, )=σ(r+1, ).\displaystyle\begin{split}\sigma(r,c)&=\sigma(r^{\prime},c^{\prime})\text{,}\\ \sigma(r-1,\raisebox{1.30487pt}{\hskip-0.40149pt\text{\lx@text@underline{\hskip 4.73611pt}\hskip 0.6458pt}})&=\sigma(r^{\prime}-1,\raisebox{1.30487pt}{\hskip-0.40149pt\text{\lx@text@underline{\hskip 4.73611pt}\hskip 0.6458pt}})\text{, and}\\ \sigma(r+1,\raisebox{1.30487pt}{\hskip-0.40149pt\text{\lx@text@underline{\hskip 4.73611pt}\hskip 0.6458pt}})&=\sigma(r^{\prime}+1,\raisebox{1.30487pt}{\hskip-0.40149pt\text{\lx@text@underline{\hskip 4.73611pt}\hskip 0.6458pt}}).\end{split} ({\dagger})

Without any loss of generality, suppose that r<rr<r^{\prime} and c<cc<c^{\prime} (the same argument works if r<rr<r^{\prime} and c<cc^{\prime}<c). Let π=π([r+1,r]×[c+1,c])\pi^{\prime}=\pi\setminus([r+1,r^{\prime}]\times[c+1,c^{\prime}]). It is easy to verify that (π,σ)φ(\pi^{\prime},\sigma^{\prime})\models\varphi, where σ=σ|π\sigma^{\prime}=\sigma|_{\pi^{\prime}}.

Claim 5.

(π,σ)φ(\pi^{\prime},\sigma^{\prime})\models\varphi

Proof.

Let φ=xy.χjxy.ψj\varphi=\forall x\forall y.\chi~\land~\bigwedge_{j}\forall x\exists y.\psi_{j}. For any (s,d),(s,d)π(s,d),(s^{\prime},d^{\prime})\in\pi such that (s,d)π(s,d)\in\pi^{\prime} and (π,σ)[x(s,d),y(s,d)]ψj(\pi,\sigma)\models_{[x\mapsto(s,d),y\mapsto(s^{\prime},d^{\prime})]}\psi_{j}, we can find (s′′,d′′)π(s^{\prime\prime},d^{\prime\prime})\in\pi^{\prime} such that σ(s,d)=σ(s′′,d′′)\sigma(s^{\prime},d^{\prime})=\sigma^{\prime}(s^{\prime\prime},d^{\prime\prime}) and such that [(s′′,d′′),(s,d)]π=[(s,d),(s,d)]π[(s^{\prime\prime},d^{\prime\prime}),(s,d)]_{\pi^{\prime}}=[(s^{\prime},d^{\prime}),(s,d)]_{\pi}. This is because, if the neighborhood type is not \infty then it is taken care of by ({\dagger}A). Otherwise, it is witnessed by one of the elements from SπS_{\pi}, for σ(s,d)=S\sigma(s^{\prime},d^{\prime})=S. Therefore, (π,σ)(\pi^{\prime},\sigma^{\prime}) verifies xy.ψj\forall x\exists y.\psi_{j} for every jj.

On the other hand, if (s,d),(s,d)π(s,d),(s^{\prime},d^{\prime})\in\pi^{\prime} where (π,σ)[x(s,d),y(s,d)]χ(\pi,\sigma)\models_{[x\mapsto(s,d),y\mapsto(s^{\prime},d^{\prime})]}\chi, we have that, if [(s,d),(s,d)]π=[(s,d),(s,d)]π[(s,d),(s^{\prime},d^{\prime})]_{\pi^{\prime}}=[(s,d),(s^{\prime},d^{\prime})]_{\pi}, then (π,σ)[x(s,d),y(s,d)]χ(\pi^{\prime},\sigma^{\prime})\models_{[x\mapsto(s,d),y\mapsto(s^{\prime},d^{\prime})]}\chi. Otherwise, we necessarily have that (s,d)=(r,c)(s,d)=(r,c), (s,d)=(r+1,c+1)(s^{\prime},d^{\prime})=(r^{\prime}+1,c^{\prime}+1) (or vice-versa). But since σ(r+1,c+1)=σ(r+1,c+1)\sigma(r+1,c+1)=\sigma(r^{\prime}+1,c^{\prime}+1) and (π,σ)[x(r,c),y(r+1,c+1)]χ(\pi,\sigma)\models_{[x\mapsto(r,c),y\mapsto(r+1,c+1)]}\chi, then (π,σ)[x(s,d),y(s,d)]χ(\pi^{\prime},\sigma^{\prime})\models_{[x\mapsto(s,d),y\mapsto(s^{\prime},d^{\prime})]}\chi, because [(s,d),(s,d)]π=[(r,c),(r+1,c+1)]π=[(s,d),(s^{\prime},d^{\prime})]_{\pi^{\prime}}=[(r,c),(r+1,c+1)]_{\pi}={\searrow}. ∎

Since π\pi^{\prime} is smaller than π\pi, and (π,σ)(\pi^{\prime},\sigma^{\prime}) verifies φ\varphi, it cannot be that π\pi is minimal in size, which is in contradiction with our hypothesis. Therefore, π\pi does not have blocks of size bigger than 324#𝒱φ+3+23(#𝒱φ+1)+32#𝒱φ3\cdot 2^{4\#\mathcal{V}_{\varphi}+3}+2^{3(\#\mathcal{V}_{\varphi}+1)}+3\cdot 2^{\#\mathcal{V}_{\varphi}}. ∎

Proof of Proposition 2.

Let (π,σ)φ(\pi,\sigma)\models\varphi be such that (π,σ)(\pi,\sigma) is minimal in size. Without any loss of generality we assume that σ:π2𝒱φ\sigma:\pi\to 2^{\mathcal{V}_{\varphi}}. We show how to build another minimal valued permutation from (π,σ)(\pi,\sigma) with a number block fingerprints that is bounded by an exponential function on |φ||\varphi|.

Let π=B1BN\pi=B_{1}\cup\dotsb\cup B_{N}, where each BiB_{i} is a maximal block. We are going to mark some blocks (only exponentially many), and use only these to build a new valued permutation satisfying φ\varphi. For each S𝒱φS\subseteq\mathcal{V}_{\varphi}, let SππS_{\pi}\subseteq\pi be a set of 4 elements of {(r,c)πσ(r,c)=S}\{(r,c)\in\pi\mid\sigma(r,c)=S\} —if the set has less than 4 elements, then let SπS_{\pi} be all of them. For every S𝒱φS\subseteq\mathcal{V}_{\varphi} and every (r,c)Sπ(r,c)\in S_{\pi}, mark the block BkB_{k} such that (r,c)Bk(r,c)\in B_{k} with a color red. It follows that we end up with at most 42#𝒱φ4\cdot 2^{\#\mathcal{V}_{\varphi}} blocks marked with red. On the other hand, for every i[N]i\in[N], let us define hi=(d,b1,b+1,b1,b+1)h_{i}=(d,b^{\rightarrow}_{-1},b^{\rightarrow}_{+1},b^{\downarrow}_{-1},b^{\downarrow}_{+1}), where ξ(Bi)=(d,b1,b+1,b1,b+1,a0at)\xi(B_{i})=(d,b^{\rightarrow}_{-1},b^{\rightarrow}_{+1},b^{\downarrow}_{-1},b^{\downarrow}_{+1},a_{0}\dotsb a_{t}). For each h{hii[N] s.t. Bi is not marked red}h\in\{h_{i}\mid i\in[N]\text{ s.t.\ $B_{i}$ is not marked red}\} let us mark with color green one block BiB_{i} such that hi=hh_{i}=h and such that BiB_{i} is not marked red. Since there are no more than 324#𝒱φ3\cdot 2^{4\#\mathcal{V}_{\varphi}} different hih_{i}’s, there are only an exponential number of blocks marked with colors red or green.

Now, let BmB_{m} be a block with a fingerprint different from all the fingerprints of the marked blocks. There must be a block BnB_{n} marked with green, so that hn=hmh_{n}=h_{m}. Let (π,σ)(\pi^{\prime},\sigma^{\prime}) be the result of replacing of BmB_{m} with BnB_{n} in (π,σ)(\pi,\sigma), in the expected way. We then have that (π,σ)φ(\pi^{\prime},\sigma^{\prime})\models\varphi.

Claim 6.

(π,σ)φ(\pi^{\prime},\sigma^{\prime})\models\varphi.

Proof.

Let φ=xy.χixy.ψi\varphi=\forall x\forall y.\chi~\land~\bigwedge_{i}\forall x\exists y.\psi_{i}.

We first show that xy.χ\forall x\forall y.\chi holds in (π,σ)(\pi^{\prime},\sigma^{\prime}). Let (r,c),(r,c)π(r,c),(r^{\prime},c^{\prime})\in\pi^{\prime}.

  • If (r,c)(r,c) is in the edited block of the permutation (i.e., in the new copy of the fingerprint of BnB_{n}).

    • If [(r,c),(r,c)]π[(r,c),(r^{\prime},c^{\prime})]_{\pi}\neq\infty, then both elements are described inside the fingerprint ξ(Bn)\xi(B_{n}). Hence, there are two elements in the block BnB_{n} of (π,σ)(\pi,\sigma) with the same neighborhood type and with the same valuations. Since for those two we have that χ\chi holds, then it holds for (r,c),(r,c)(r,c),(r^{\prime},c^{\prime}) as well. Hence, (π,σ)[x(r,c),y(r,c)]χ(\pi^{\prime},\sigma^{\prime})\models_{[x\mapsto(r,c),y\mapsto(r^{\prime},c^{\prime})]}\chi.

    • Otherwise, suppose [(r,c),(r,c)]π=[(r,c),(r^{\prime},c^{\prime})]_{\pi}=\infty. Note that in the red colored blocks of (π,σ)(\pi,\sigma) there must be at least 4 elements with value σ(r,c)\sigma^{\prime}(r,c). By the same reason there must be 4 elements with value σ(r,c)\sigma^{\prime}(r^{\prime},c^{\prime}). Since marked blocks are preserved, there must be (s,l),(s,d)π(s,l),(s^{\prime},d^{\prime})\in\pi such that [(s,d),(s,d)]π=[(s,d),(s^{\prime},d^{\prime})]_{\pi}=\infty, and σ(s,d)=σ(r,c)\sigma(s,d)=\sigma^{\prime}(r,c), σ(s,d)=σ(r,c)\sigma(s^{\prime},d^{\prime})=\sigma^{\prime}(r^{\prime},c^{\prime}). Since (π,σ)[x(s,d),y(s,d)]χ(\pi,\sigma)\models_{[x\mapsto(s,d),y\mapsto(s^{\prime},d^{\prime})]}\chi, we have (π,σ)[x(r,c),y(r,c)]χ(\pi^{\prime},\sigma^{\prime})\models_{[x\mapsto(r,c),y\mapsto(r^{\prime},c^{\prime})]}\chi.

  • If both (r,c)(r,c) and (r,c)(r^{\prime},c^{\prime}) are in the part that was not modified, then there must clearly be (s,d),(s,d)π(s,d),(s^{\prime},d^{\prime})\in\pi with [(s,d),(s,d)]π=[(r,c),(r,c)]π[(s,d),(s^{\prime},d^{\prime})]_{\pi}=[(r,c),(r^{\prime},c^{\prime})]_{\pi^{\prime}}, so that σ(s,d)=σ(r,c)\sigma(s,d)=\sigma^{\prime}(r,c), σ(s,d)=σ(r,c)\sigma(s^{\prime},d^{\prime})=\sigma^{\prime}(r^{\prime},c^{\prime}). Hence, (π,σ)[x(r,c),y(r,c)]χ(\pi^{\prime},\sigma^{\prime})\models_{[x\mapsto(r,c),y\mapsto(r^{\prime},c^{\prime})]}\chi.

We now show that for every ii and (r,c)π(r,c)\in\pi^{\prime}, y.φi\exists y.\varphi_{i} holds.

  • If (r,c)(r,c) is in the edited block of the permutation (i.e., in the new copy of the fingerprint of BnB_{n}), then there must be some (r,c)(r^{\prime},c^{\prime}) in BnB_{n} such that σ(r,c)=σ(r,c)\sigma(r^{\prime},c^{\prime})=\sigma^{\prime}(r,c). Since (π,σ)[x(r,c)]y.φi(\pi,\sigma)\models_{[x\mapsto(r^{\prime},c^{\prime})]}\exists y.\varphi_{i}, there must be some (s,d)π(s^{\prime},d^{\prime})\in\pi such that (π,σ)[x(r,c),y(s,d)]φi(\pi,\sigma)\models_{[x\mapsto(r^{\prime},c^{\prime}),y\mapsto(s^{\prime},d^{\prime})]}\varphi_{i}.

    • If [(s,d),(r,c)]π[(s^{\prime},d^{\prime}),(r^{\prime},c^{\prime})]_{\pi}\neq\infty, then it is described in the fingerprint of BnB_{n} and therefore there must be some (s,d)(s,d) such that [(s,d),(r,c)]π=[(s,d),(r,c)]π[(s,d),(r,c)]_{\pi^{\prime}}=[(s^{\prime},d^{\prime}),(r^{\prime},c^{\prime})]_{\pi}, and σ(s,d)=σ(s,d)\sigma^{\prime}(s,d)=\sigma(s^{\prime},d^{\prime}), σ(r,c)=σ(r,c)\sigma^{\prime}(r,c)=\sigma(r^{\prime},c^{\prime}). Then, (π,σ)[x(r,c),y(s,d)]φi(\pi^{\prime},\sigma^{\prime})\models_{[x\mapsto(r,c),y\mapsto(s,d)]}\varphi_{i} since (π,σ)[x(r,c),y(s,d)]φi(\pi,\sigma)\models_{[x\mapsto(r^{\prime},c^{\prime}),y\mapsto(s^{\prime},d^{\prime})]}\varphi_{i}.

    • Otherwise, suppose that [(s,d),(r,c)]π=[(s^{\prime},d^{\prime}),(r^{\prime},c^{\prime})]_{\pi}=\infty. There must be 4 elements of (π,σ)(\pi,\sigma) with the same value σ(s,d)\sigma(s^{\prime},d^{\prime}) inside blocks marked red. Then, there must be a block marked red in π\pi^{\prime} containing some (s,d)(s,d) with σ(s,d)=σ(s,d)\sigma^{\prime}(s,d)=\sigma(s^{\prime},d^{\prime}) and such that [(s,d),(r,c)]π=[(s,d),(r,c)]_{\pi^{\prime}}=\infty. Then, (π,σ)[x(r,c),y(s,d)]φi(\pi^{\prime},\sigma^{\prime})\models_{[x\mapsto(r,c),y\mapsto(s,d)]}\varphi_{i} since (π,σ)[x(r,c),y(s,d)]φi(\pi,\sigma)\models_{[x\mapsto(r^{\prime},c^{\prime}),y\mapsto(s^{\prime},d^{\prime})]}\varphi_{i}.

  • If (r,c)(r,c) is in the part that was not modified, then there is some (r,c)π(r^{\prime},c^{\prime})\in\pi with σ(r,c)=σ(r,c)\sigma(r^{\prime},c^{\prime})=\sigma^{\prime}(r,c) and (r,c)Bm(r^{\prime},c^{\prime})\not\in B_{m}. Since (π,σ)[x(r,c)]y.φi(\pi,\sigma)\models_{[x\mapsto(r^{\prime},c^{\prime})]}\exists y.\varphi_{i}, there must be some (s,d)π(s^{\prime},d^{\prime})\in\pi such that (π,σ)[x(r,c),y(s,d)]φi(\pi,\sigma)\models_{[x\mapsto(r^{\prime},c^{\prime}),y\mapsto(s^{\prime},d^{\prime})]}\varphi_{i}.

    • If [(s,d),(r,c)]π[(s^{\prime},d^{\prime}),(r^{\prime},c^{\prime})]_{\pi}\neq\infty, then (s,d)(s^{\prime},d^{\prime}) is described in the fingerprint of the block where (r,c)(r^{\prime},c^{\prime}) belongs. Since this fingerprint is preserved (because it is not BmB_{m}), there must be some (s,d)(s,d) with σ(s,d)=σ(s,d)\sigma^{\prime}(s,d)=\sigma(s^{\prime},d^{\prime}) and such that [(r,c),(s,d)]π=[(r,c),(s,d)]π[(r,c),(s,d)]_{\pi^{\prime}}=[(r^{\prime},c^{\prime}),(s^{\prime},d^{\prime})]_{\pi}. Then, (π,σ)[x(r,c),y(s,d)]φi(\pi,\sigma)\models_{[x\mapsto(r^{\prime},c^{\prime}),y\mapsto(s^{\prime},d^{\prime})]}\varphi_{i}.

    • Otherwise, if [(s,d),(r,c)]π=[(s^{\prime},d^{\prime}),(r^{\prime},c^{\prime})]_{\pi}=\infty, there must be 4 other positions with the same value as (s,d)(s^{\prime},d^{\prime}) in (π,σ)(\pi,\sigma), in blocks marked red. Then, there must necessarily be some (s,d)π(s,d)\in\pi^{\prime} such that σ(s,d)=σ(s,d)\sigma^{\prime}(s,d)=\sigma(s^{\prime},d^{\prime}) and such that [(s,d),(r,c)]π=[(s,d),(r,c)]_{\pi^{\prime}}=\infty. Then, (π,σ)[x(r,c),y(s,d)]φi(\pi,\sigma)\models_{[x\mapsto(r^{\prime},c^{\prime}),y\mapsto(s^{\prime},d^{\prime})]}\varphi_{i}.

Therefore, (π,σ)[x(r,c)]y.φi(\pi^{\prime},\sigma^{\prime})\models_{[x\mapsto(r,c)]}\exists y.\varphi_{i}. ∎

Note that since BmB_{m} and BnB_{n} have the same type, then the number of maximal blocks in π\pi^{\prime} is the same as in π\pi, and moreover the number of maximal blocks with fingerprints different from the marked fingerprints is decremented by one. Note that in particular this means that #Bm=#Bn\#B_{m}=\#B_{n}. Otherwise, if #Bm>#Bn\#B_{m}>\#B_{n}, we would have that (π,σ)(\pi^{\prime},\sigma^{\prime}) is smaller than (π,σ)(\pi,\sigma) which cannot be since (π,σ)(\pi,\sigma) is minimal in size. Conversely, if #Bm<#Bn\#B_{m}<\#B_{n}, we could have marked BmB_{m} with green instead of BnB_{n} and we arrive to the same contradiction.

We can repeat this operation with all the unmarked blocks ending up with a valued permutation whose every block has the fingerprint of a marked block. Since there are only exponentially many marked blocks, there are exponentially many fingerprints. ∎