Abstract 1 Introduction 2 Meta-Level Problems 3 𝚺𝒌𝑷-Completeness of Level-𝒌 SAT 4 Arithmetic Puzzles: Definitions 5 Arithmetic Puzzles: Hardness 6 Arithmetic Puzzles: Algorithms 7 Open Questions References

A Bookworm Climbs up the Polynomial Hierarchy: Meta-Restoration Complexity in Arithmetic Puzzles

Brynmor Chapman CSAIL, Massachusetts Institute of Technology, Cambridge, MA, USA Lily Chung ORCID CSAIL, Massachusetts Institute of Technology, Cambridge, MA, USA Erik D. Demaine ORCID CSAIL, Massachusetts Institute of Technology, Cambridge, MA, USA Yota Irino Japan Advanced Institute of Science and
Technology, Nomi, Ishikawa, Japan
Della Hendrickson ORCID CSAIL, Massachusetts Institute of Technology, Cambridge, MA, USA Tonan Kamata ORCID Japan Advanced Institute of Science and
Technology, Nomi, Ishikawa, Japan
Ryuhei Uehara ORCID Japan Advanced Institute of Science and
Technology, Nomi, Ishikawa, Japan
Abstract

In arithmetic puzzles, a partially specified arithmetic expression must be completed to make the computation valid. Arithmetical restoration puzzles require filling in missing digits, while cryptarithms involve assigning digits to letters. The Japanese term mushikui-zan (“bookwormed arithmetic”) commonly refers to arithmetical restorations, where we imagine the missing digits have been eaten by a bookworm. Puzzle creator Yousuke Ikeda proposed a new type of puzzle in which a previously designed bookwormed arithmetic with multiplication – known to have a unique solution – has itself been “bookwormed”, that is, partially erased. The goal is to restore the specified blanks so that the resulting bookwormed puzzle again has a unique solution. We further generalize this framework: for each k2, we define level-k puzzles as those in which type-k blanks must be filled to make the resulting level-(k1) puzzle uniquely solvable. We study the level-k versions of the Boolean satisfiability problem, and show that they form a hierarchy of ΣkP-complete decision problems, tightly matching the levels of the polynomial hierarchy. As applications, we show that the level-k arithmetical restoration problem with multiplication is ΣkP-complete, as is the level-k cryptarithm problem. On the positive side, we show that level-2 arithmetical restoration puzzles with addition are solvable in polynomial time.

Keywords and phrases:
arithmetical restoration, cryptarithms, polynomial hierarchy, uniqueness quantifier, puzzle complexity
Copyright and License:
[Uncaptioned image] © Brynmor Chapman, Lily Chung, Erik D. Demaine, Yota Irino, Della Hendrickson, Tonan Kamata, and Ryuhei Uehara; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Problems, reductions and completeness
; Theory of computation Complexity classes
Editor:
John Iacono

1 Introduction

The relationship between puzzles and computational complexity has long attracted attention from both recreational and theoretical perspectives. Since Martin Gardner introduced Conway’s Game of Life to the public, various puzzles have been explored through the lens of computational hardness [7]. Among them, arithmetic puzzles offer a natural interface between everyday logic and formal algorithmic reasoning.

Two prominent types of arithmetic puzzles are cryptarithms and arithmetical restorations. A cryptarithm is a puzzle in which each digit is uniquely replaced by a letter, as in the classic example “SEND + MORE = MONEY” shown in Figure 1. These puzzles have been studied under various names such as alphametics and have been featured in mathematical recreations for over a century [3].

Figure 1: Cryptarithms: SEND+MORE=MONEY and its solution (Henry E. Dudeney, 1924).

An arithmetical restoration, on the other hand, requires filling in missing digits in partially erased expressions, as in “The Solitary Seven” shown in Figure 2 [8]. These puzzles, also known as figure logic or missing figure puzzles, emphasize reconstructing a valid equation rather than deciphering encoded symbols.

Figure 2: Arithmetical restorations: “The Solitary Seven” and its solution (E. F. Odling, 1922).

The computational complexity of these puzzles has been studied. In 1987, Eppstein [2] proved that solving cryptarithms with addition is NP-complete. De Bondt [1] showed that they are in fact ASP-complete [9], meaning there is a parsimonious reduction from any NP search problem such that the bijection between solutions to the instances can be computed in polynomial time. Finally, Matsui [6] showed that arithmetical restorations with multiplication are also ASP-complete via a reduction from Positive 1-in-3SAT, which was shown to be ASP-complete in [4].

In 2024, Japanese puzzle creator Yousuke Ikeda proposed a novel extension of the arithmetical restoration puzzle. He was inspired by the Japanese term mushikui-zan (literally “bookwormed arithmetic”), commonly used to describe arithmetical restorations in Japan; we imagine that a bookworm ate some of the digits in an arithmetic expression, and we are trying to figure out what they were. Ikeda’s extension shown in Figure 3 is a simple but powerful idea: take an instance of bookwormed arithmetic that is already uniquely solvable, and then bookworm it again – that is, erase part of the puzzle itself once more. The new challenge is to determine how to restore these higher-level bookwormed blanks so that the resulting puzzle, still with the original bookwormed blanks, is again uniquely solvable.

Refer to caption
Figure 3: Screen capture of Yousuke Ikeda’s post [5], proposing a “meta-restoration” puzzle in which a previously restored arithmetic expression is itself damaged again. This screenshot is used with permission from Yousuke Ikeda.

This idea can be generalized naturally to a recursive hierarchy of puzzles (Figure 4). Suppose the erased puzzle was itself a uniquely solvable instance of a prior restoration: this yields a meta-level restoration problem. At level 1, the task is to fill in missing digits in a partially erased arithmetic puzzle, i.e., to solve a standard bookwormed arithmetic. At level 2, some parts of a level-1 puzzle have been bookwormed again, and the goal is to assign digits to these higher-level blanks so that the resulting level-1 puzzle becomes uniquely solvable. This nesting continues: at level k, the solver must assign digits to type-k blanks so that the resulting type-(k1) puzzle admits a unique solution, and so on, all the way down to the base level. Only blanks of the highest type are solved at each level; lower-type blanks remain as part of the sub-instance being reconstructed.

Figure 4: A visual metaphor for meta-level puzzles: each level corresponds to a printout of a uniquely solvable puzzle from the previous level, which is then partially erased. This screenshot has been edited and used with permission from Yosuke Ikeda.

Our main results classify the computational complexity of meta-level puzzles across various settings.

  1. 1.

    We define a notion of “locally parsimonious reductions” between search problems, and prove that these yield reductions between the meta-level versions of these problems.

  2. 2.

    In the Boolean satisfiability setting, we show that the level-k SAT problem is complete for the class ΣkP. The level-k SAT problem is to decide the truth of quantified Boolean formulae of the form

    x1:!x2:!x3::!xk:ϕ(x1,,xk)

    where each xi denotes a vector of Boolean variables, and ! denotes the “exists and is unique” quantifier.

  3. 3.

    In the arithmetical restoration setting, we show the following partial classification according to which arithmetic operation is involved:

Theorem 1 (Meta-level restorations with multiplication/division).

Let k2. The level-k meta-restoration problem with multiplication or division is ΣkP-complete.

Theorem 2 (Meta-level restorations with addition/subtraction).

The level-2 meta-restoration problem with addition or subtraction is solvable in polynomial time.

As part of showing the latter result, we give a polynomial-time algorithm to determine whether an arithmetical restoration puzzle has a unique solution.

  1. 4.

    For cryptarithms, we show computational hardness with any of the four arithmetic operations:

Theorem 3 (Meta-level cryptarithms).

Let k2. The level-k meta-cryptarithm problem with addition, subtraction, multiplication, or division is ΣkP-complete.

Along the way to showing these results, we give parsimonious reductions from multiplication to division in arithmetical restorations, and from addition to subtraction, multiplication, or division in cryptarithms. This extends Matsui’s [6] and de Bondt’s [1] results to show ASP-completeness of the corresponding puzzle types.

2 Meta-Level Problems

2.1 Definitions

We define a framework for meta-level problems as follows.

Let 𝒟 be a domain, and let X be a set of variables. An assignment a𝒟X is a function assigning each variable in X a value in 𝒟. We can think of a subset A𝒟X as a solution set to a search problem over the variables X, with each variable taking values in 𝒟.

The level-1 problem corresponding to A is just the ordinary decision problem “Is A nonempty?”. The level-k problem for k2 is specified by assigning each variable in X an integer between 1 and k called its type. The question is whether it is possible to assign values to the type-k variables such that the resulting level-(k1) problem has a unique solution.

To analyze the computational complexity of such problems, we will consider problems specified by binary strings.

Definition 4.

A search problem P over a domain 𝒟 is a function that assigns to each string s{0,1} a solution set P(s)𝒟X, where the set of variables is X=[|s|].111We make the set X of variables explicit in this definition, but the point is that the number of variables is polynomially related to the size of the instance.

Note that the domain 𝒟 will commonly be infinite: for example, in arithmetic restoration the domain is since each variable represents a digit in the base specified by the problem instance.

Definition 5.

Let P be a search problem and k1 be an integer. The level-k P problem is the language of strings (s,t) such that the formula

vk:!vk1:!vk2::!v1:[vP(s)]

is satisfied, where t encodes a function from X=[|s|] to {1,,k}, and vi is the list of variables x of type t(x)=i.

2.2 Reductions between Meta-Level Versions of Constraint Satisfaction Problems

Now we define a type of reductions between search problems which will turn out to lift to reductions between the level-k versions of those problems.

Definition 6.

Let A𝒟X and BY be solution sets over the domains 𝒟 and respectively. We say that B locally reproduces A if there is a bijection f:AB with the following properties:

First, for each variable xX there must exist a corresponding set of variables SxY, and an injection fx:VxSx where Vx={a[x]:aA} is the set of all possible values taken by the variable x as part of a solution aA. The sets Sx are required to be disjoint from each other.

Second, the bijection f must satisfy the equation f(a)[y]=fx(a[x])[y] for every assignment aA and each pair of variables xX,ySx.

The definition states that the values of the variables Sx in f(a) depend only on the value of x in a. Another phrasing is that the function af(a)|xSx is the product of the functions fx.

More generally, let XX, and write Y=xXSx. Define the sets VX𝒟X,WYY by VX={a|X:aA} and WY={b|Y:bB}; these are the sets of feasible partial assignments to X (respectively, Y) which can be extended to an assignment in A (respectively, B). We write f~X:VXY for the product function f~X=xXfx.

Lemma 7.

The function f~X is in fact a bijection f~X:VXWY.

Proof.

We prove that f~X always outputs an element of WY, that it is injective, and that it is surjective on WY.

First, consider an arbitrary element of VX; it can be written as a|X for some aA. Then f~X(a|X) is equal to f(a)|Y, and the latter is in WY because f(a)B. So f~X always outputs an element of WY.

Second, f~X is injective because it is the product of the injective functions fx.

Third, consider an arbitrary element of WY; it can be written as b|Y for some bB. Then f~X(f1(b)|X)=b|Y, so f~X is surjective onto WY.

The purpose of Definition 6 is to prove the following:

Lemma 8.

Let A𝒟X and BY be solution sets, and t:X{1,,k} be a function assigning types to the variables in X. Suppose B locally reproduces A, so there exist f,fx,Sx as in Definition 6.

Assign types to the variables in Y according to the function

t(y)={t(x)if ySx for some xX1otherwise.

Now fix j{1,,k}, and let X>j and Y>j be the sets of variables in X and Y (respectively) of type strictly greater than j.

Suppose aVX>j is a feasible partial assignment to X>j. Then the equivalences

(!vj:!vj1::!v1:[avjv1A])
(!wj:!wj1::!w1:[f~X>j(a)wjw1B])

and

(vj:!vj1::!v1:[avjv1A])
(wj:!wj1::!w1:[f~X>j(a)wjw1B])

both hold, where vi is the list of variables in X of type i, wi is the list of variables in Y of type i, and denotes combination of assignments to disjoint sets of variables.

Proof.

The proof is by induction on j. We write X=j and Y=j for the sets of type-j variables in X and Y respectively. Note that by definition of t we have Y=j=xX=jSx except when j=1.

Let j=1, and fix a feasible partial assignment a to X>1. We exhibit a bijection between the sets {c1:ac1A} and {d1:f~X>1(a)d1B}. The bijection is given by c1f(ac1)|Y=1, whose inverse is d1f1(f~X>1(a)d1)|X=1. So these sets have the same size, which means the formulae in the lemma statement are equivalent.

Now let j>1, and fix a feasible partial assignment a to X>j. Suppose cj is a partial assignment to X=j such that acj is feasible. Then by the inductive hypothesis, the formula

!vj1::!v1:[acjvj1v1A] (1)

is equivalent to

!wj1::!w1:[f~X>j1(acj)wj1w1B].

Since f~X>j1(acj)=f~X>j(a)f~X=j(cj), it follows using Lemma 7 that f~X=j is a bijection between partial assignments cj satisfying the formula (1) and partial assignments dj to Y=j satisfying

!wj1::!w1:[f~X>j(a)djwj1w1B].

In particular, the number of such cj is equal to the number of such dj, which proves the lemma statement.

Using this lemma, we can define our desired reductions between search problems.

Definition 9.

Let P and Q be search problems. A locally parsimonious reduction from P to Q is a function g:{0,1}{0,1} such that Q(g(s)) locally reproduces P(s) for each s{0,1}, and the sets Sx can be computed in polynomial time.

Many existing parsimonious reductions are in fact locally parsimonious. For instance, this is true for the reduction from SAT to 3SAT given in [9], since every SAT variable is given a single corresponding 3SAT variable. The same holds for the reduction from SAT to 1-in-3SAT.

Theorem 10.

Let P and Q be search problems over the domains 𝒟 and respectively, and g be a locally parsimonious reduction from P to Q. Then there is a polynomial-time reduction from the level-k P problem to the level-k Q problem.

Proof.

Let (s,t) be an instance of the level-k P problem. We define the output of the reduction to be (g(s),t) where t is defined as in Lemma 8. It follows immediately from Lemma 8, that (s,t) is a YES instance if and only if (g(s),t) is.

Combined with the results of the next section, Theorem 10 can be used to show ΣkP-hardness for the level-k version of a problem by finding a locally parsimonious reduction from SAT (or 3SAT, or 1-in-3SAT) to that problem. Similarly, containment in ΣkP can be shown by finding a locally parsimonious reduction in the other direction.

3 𝚺𝒌𝑷-Completeness of Level-𝒌 SAT

In this section, we prove that level-k SAT is ΣkP-complete.

Theorem 11 (Level-𝒌 SAT is 𝚺𝒌𝑷-complete).

For every k1, the satisfiability problem for formulae of the form x1:!x2:!x3::!xk:ϕ(x1,,xk), where each xi denotes a vector of Boolean variables, is ΣkP-complete.

Proof of Theorem 11.

We claim that any formula of the form !x1:!x2::!xk:ϕ(x1,,xk,z), where xi,z are vectors of Boolean variables and z is free, can be transformed in polynomial time into two equivalent Boolean formulae with k+1 blocks of alternating quantifiers: one starting with and the other starting with . We refer to these two desired forms as the “Σk+1P form” and the “Πk+1P form” respectively.

The proof is by induction on k. The key observation is that each uniqueness quantifier !x can be rewritten using standard quantifiers in two different ways:

( rewriting) !x:ψ(x)x:x:[ψ(x)(ψ(x)x=x)],
( rewriting) !x:ψ(x)x1:x2:x:[ψ(x)((ψ(x1)ψ(x2))x1=x2)].

Let ψ(x1)=!x2::!xk:ϕ(x1,,xk,z). By the inductive hypothesis, we can rewrite ψ(x1) in both ΣkP form and ΠkP form. To write !x1:ψ(x1) in Σk+1P form, we apply the rewriting above. We then replace the positive occurrence of ψ(x1) with its ΠkP form and the negative occurrence of ψ(x1) with its ΣkP form. After applying De Morgan’s laws and the equivalences

(x:ϕ0(x))(x:ϕ1(x)) x:b{0,1}:(b=0ϕ0(x))(b=1ϕ1(x))
(x:ϕ0(x))(x:ϕ1(x)) x0:x1:ϕ0(x0)ϕ1(x1)

to move all quantifiers to the beginning, the result is a formula in Σk+1P form. Finding the Πk+1P form is analogous, but we use the rewriting and make the opposite choices for ψ(x1). These rewriting steps take polynomial time,222The time taken and the size of the output formula are both exponential in the constant k, but polynomial in the size of the input formula. so the claim is proved. It follows from this that satisfiability of formulae of the form x1:!x2::!xk:ϕ(x1,,xk) is contained in ΣkP, simply by rewriting !x2::!xk:ϕ(x1,,xk) in ΣkP form.

It remains to show ΣkP-hardness. Consider any formula of the form ¬x1:¬x2::¬xk:ϕ(x1,,xk,z) where xi,z are vectors of Boolean variables and z is free. An induction on k shows that this formula is equivalent to

!(x1,a1):!(x2,a2)::!(xk,ak):
(i=2k(ai1ai))(i=1k(aixi=0,,0))(ϕ(x1,,xk,z)i=1kai),

where each ai is a single Boolean variable. Proof by induction:
[!(x1,a1):!(x2,a2)::!(xk,ak):(i=2k(ai1ai))(i=1k(aixi=0,,0))(ϕ(x1,,xk,z)i=1kai)] !(x1,a1):{[!(x2,a2)::!(xk,ak):(i=3k(ai1ai))(i=2k(aixi=0,,0))(ϕ(x1,,xk,z)i=2kai)]if a1=0[!(x2,a2)::!(xk,ak):(i=2kai=1)(i=1kxi=0,,0)]if a1=1 !(x1,a1):{¬x2:¬x3::¬xk:ϕ(x1,,xk,z)if a1=0x1=0,,0if a1=1 ¬x1:¬x2::¬xk:ϕ(x1,,xk,z)

Since satisfiability of formulae of the form x1:¬x2:¬x3::¬xk:ϕ(x1,,xk) is ΣkP-complete, it follows from the above that satisfiability of formulae of the form x1:!x2:!x3::!xk:ϕ(x1,,xk) is ΣkP-complete also, by rewriting the rest of the formula after the first quantifier.

4 Arithmetic Puzzles: Definitions

4.1 Arithmetical Restorations

In order to formalize arithmetical restorations, we focus here on addition, which is the primary case where tractability arises. Other operations (subtraction, multiplication, and division) are treated analogously but lead to different complexity classifications, as discussed later.

An instance X+ consists of two m-digit addends and their sum in base n, possibly of length m or m+1. To streamline notation, we include two boundary columns: C0=(0,0,0) and Cm+1=(0,0,α) with α{0,1}, resulting in m+2 columns in total: Cm+1,Cm,,C0 (see Figure 6). Each internal column Ci (1im) consists of a triple (ci1,ci2,ci3), where ci1 and ci2 are the digits to be added, and ci3 is the corresponding digit of the sum.

Figure 5: Basic layout of an arithmetical restoration for addition.
Figure 6: Formal structure of the addition puzzle.

Let x1,,xk be the variables in X+. For an assignment s{0,,n1}k, let X+(s) denote the resulting table after substitution. An assignment s is a solution if X+(s) satisfies the addition rule with proper carry propagation. Evaluation proceeds from the least significant digit (rightmost column) to the most significant digit, propagating carries according to:

Carry(Ci(s)):={0if ci1+ci2+Carry(Ci1(s))<n1otherwise.

4.2 Cryptarithms

Cryptarithms are puzzles in which digits are replaced by letters. The goal is to assign distinct digits to letters so that the resulting arithmetic expression is valid. We focus on multiplication; other operations follow analogous definitions. An instance Y× consists of:

  1. 1.

    a multiplicand S1 of length p,

  2. 2.

    a multiplier S2 of length q,

  3. 3.

    q partial products Si of length i with 3iq+2, where 1ip+1, and

  4. 4.

    a final product Sq+3 of length 1q+3pq+1.

Let S be the set of letters used in Y×. A digit assignment s:S{0,,n1} induces a concrete puzzle Y×(s) via substitution. An assignment s is a solution if:

  1. 1.

    all arithmetic operations in Y×(s) are correct in base n, and

  2. 2.

    all digits assigned are pairwise distinct.

Figure 7: Structure of a multiplication cryptarithm.

5 Arithmetic Puzzles: Hardness

5.1 Parsimonious Reductions Across Arithmetic Operations

We now show that arithmetical restoration and cryptarithm puzzles involving subtraction, multiplication, and division are all ASP-complete.

Lemma 12 (ASP-completeness across operations).

Arithmetical restorations with multiplication or division are ASP-complete. Cryptarithms with subtraction, multiplication, or division are also ASP-complete. Thus the corresponding counting problems are #P-complete.

To prove Lemma 12, we systematically construct parsimonious reductions between puzzle types and operations. These reductions preserve the number of solutions, allowing us to transfer the known hardness of addition and multiplication to subtraction and division. We divide the proof into four parts, each showing a parsimonious reduction between two operations.

Reduction from Multiplication to Division in Restorations.

Matsui [6] showed that the arithmetical restoration problem with multiplication is ASP-complete via a reduction from Monotone 1-in-3SAT. The instance X× consists of digit sequences SA, SB, SC, and S1,,Sq arranged to represent a multiplication table.

Figure 8 illustrates the structure of X×.

Figure 8: Multiplication instance X× reduced from Monotone 1-in-3SAT [6].
Figure 9: Division instance X÷ constructed from the multiplication instance X×.

To reduce to division, we construct a new instance X÷ that reuses these sequences in a division layout. We add auxiliary rows S1,,Sq to account for intermediate subtractions. Each subtraction step in the division corresponds to a row in the multiplication layout, preserving the structure of the solution.

Fixing the divisor and quotient uniquely determines all subtraction steps, so the number of solutions is preserved. Thus, the reduction is parsimonious.

Reduction from Addition to Subtraction in Cryptarithms.

Let Y+(ϕ) be the cryptarithm with addition derived from a Positive 1-in-3SAT instance. It consists of three rows:G1+G2=G3.

We construct Y(ϕ) by rearranging the rows as G3G2=G1 and changing the operator to subtraction. This transformation preserves the solution space, due to the symmetry between carry and borrow behavior in digit gadgets.

(a)
(b)
(c)
(d)
Figure 10: Carry-borrow symmetry in digit gadgets under row-swapping.

Reduction from Addition to Multiplication in Cryptarithms.

We embed the structure of Y+(ϕ) into a multiplication layout to form Y×(ϕ). Fixed digits c0=0 and c1=1 are introduced to maintain constant semantics. The region corresponding to G1+G2=G3 is preserved within the multiplicative table layout.

Figure 11: Reduction from cryptarithm addition Y+(ϕ) to multiplication Y×(ϕ).
Figure 12: Reduction from cryptarithm subtraction Y(ϕ) to division Y÷(ϕ).

This transformation embeds the original constraint structure without ambiguity, ensuring a one-to-one correspondence of solutions.

Reduction from Subtraction to Division in Cryptarithms.

Finally we reduce cryptarithm subtraction to division by embedding the instance Y(ϕ) into a division layout. We reuse the row configuration G3G2=G1 to form a long division table Y÷(ϕ), fixing c0=0 and c1=1 as constants.

The core structure is preserved inside a designated region, and all auxiliary digits are placed disjointly to avoid interference. The transformation is again parsimonious.

This completes the proof of Lemma 12.

5.2 Meta-Level Complexity

We now complete the classification of meta-level puzzles by proving Theorem 1 and Theorem 3, which concern the complexity of multiplicative meta-restorations and meta-cryptarithms, respectively.

We accomplish this by applying the results of Section 2.2 to the preceding parsimonious reductions, allowing us to obtain reductions between the meta-level versions of the problems. Indeed, from the structure of the reductions it is clear that every variable of the input instance corresponds to a single variable of the output instance, so the reductions are in fact locally parsimonious. The same is true for the reductions of [4, 6, 1] used to show ASP-completeness of arithmetical restorations with multiplication and cryptarithms with addition. By Theorems 10 and 11, these reductions show that the preceding problems are ΣkP-hard. We can also represent arithmetic restoration and cryptarithms with SAT formulae in a locally parsimonious way, showing containment in ΣkP.

Therefore, the meta-restoration and meta-cryptarithm problems are ΣkP-complete for all k2.

6 Arithmetic Puzzles: Algorithms

6.1 Polynomial-Time Algorithms for Arithmetical Restorations with Addition and Subtraction

We prove the following result, which provides a polynomial-time decision algorithm for restorations with addition and subtraction:

Lemma 13 (Additive restorations).

Determining whether a given arithmetical restoration puzzle with addition and subtraction admits a unique solution is in P.

The basic idea is a dynamic programming approach that focuses on the carry-over values between columns. We first define the corresponding subproblem.

Definition 14 (Extended column feasibility).

Given a column Ci and two carry values (β,α), we say that Ci is feasible with carries (β,α) if there exists an assignment to the variables in Ci that is consistent with incoming carry β and outgoing carry α.

Lemma 15.

An arithmetical restoration X+ has a solution if and only if there exists a sequence l{0,1}m+1 such that, for each i{1,2,,m}, the column Ci is feasible with carries (li1,li).

Proof.

()

Suppose X+ has a solution s. Let l=(l0,,lm) be the carry sequence induced by s, where li1 is the carry entering column Ci and li the carry leaving it. For each i, the restriction wi of s to Ci makes the column feasible with (li1,li). Hence the condition holds.

()

Conversely, suppose there exists l such that each column Ci admits an assignment wi consistent with (li1,li). Since the wi concern disjoint sets of variables, their union s:=i=1mwi forms a global assignment. By construction, every column constraint is satisfied with the designated carries l, so s is a solution of X+.

We now develop a column-wise feasibility check for given carry-in and carry-out values, which forms the basis of our algorithm.

Lemma 16.

For a column Ci and carry values (β,α){0,1}2, we can determine in O(n) time whether Ci is feasible with carries (β,α).

Proof.

Fix a column i. For each entry cij in row j{1,2,3}, define

(xj,yj):={(cij,0)if cij is type 0,(0,cij)if cij is type 1.

From the carry definition, we require: y1+y2y3=x3x1x2+αnβ. The left-hand side is a linear expression in at most three variables ranging over {0,1,,n1}, and the right-hand side is constant. The number of variable entries is at most three, and we can compute the range of the left-hand side in constant time by bounding it between θ3(n1)and(θ1+θ2)(n1), where θj=1 if cij is a variable and 0 otherwise. A feasible assignment exists if and only if the right-hand side lies within this range.

Using this feasibility check, we now describe a polynomial-time algorithm that verifies the existence of a consistent carry sequence across all columns. We construct a directed graph representing feasible carry transitions:

  1. 1.

    For each i{0,1,,m+1} and each b{0,1}, define a vertex vi,b.

  2. 2.

    Add an edge from vi1,β to vi,α if column Ci admits a feasible assignment with carry-in β and carry-out α, as determined by Lemma 16.

Figure 13: Graph structure representing feasible carry transitions.

The total number of vertices is 2(m+2) and the number of edges is at most 4(m+1), since each transition layer has at most 4 feasible carry transitions. Each feasibility check runs in O(n) time, and the overall graph construction takes O(nm) time. Finally, we perform a reachability test from v0,0 and v0,1 to vm+1,0 or vm+1,1. This can be done in O(nm) time. Thus, the entire algorithm runs in O(nm) time, proving Lemma 13.

6.2 Polynomial-Time Algorithm for Level-2 Additive Restorations

We now establish Theorem 2 by presenting a polynomial-time algorithm for solving level-2 meta-restorations involving addition or subtraction.

The core idea is to extend the level-1 restoration algorithm, which checks the consistency of a partially erased addition table, to also verify uniqueness – a requirement at level 2. To this end, we construct a directed graph that captures all valid and unique carry-over transitions across columns.

Specifically, let each vertex vi,b represent the carry value b{0,1} at column index i (from right to left). We add an edge vi1,bvi,b if there exists an assignment to the type-2 entries of column Ci such that there exists a unique way to fill in the type-1 entries of column Ci such that:

  1. 1.

    the incoming carry is b and the outgoing carry is b,

  2. 2.

    the assignment respects the roles of the cells (type-0: fixed, type-1: blank at level 1, type-2: blank at level 2), and

  3. 3.

    the assignment is consistent with addition modulo n.

We can then decide solvability by checking whether this graph contains a valid path from the leftmost vertex (typically v0,0) to the rightmost vertex (typically v,0, where is the number of columns).

The following lemma underpins the tractability of the edge construction step:

Lemma 17.

Fix a column Ci with given carry-in β and carry-out α. We can determine in O(n) time whether there exists an assignment to the type-2 variables in Ci (if any) such that the values of all type-1 variables in Ci are uniquely determined and the column is consistent.

Proof.

Fix a column Ci with carry-in β and carry-out α.

Let ci1,ci2,ci3 denote the three entries of column Ci. Each cij is interpreted as follows: if it is of type 0, then cij is the fixed digit given in the puzzle; if it is of type 1 or type 2, then cij denotes the corresponding variable to be assigned. For each row j{1,2,3}, define:

(xj,yj,zj):={(cij,0,0)if cij is type 0,(0,cij,0)if cij is type 1,(0,0,cij)if cij is type 2.

From the semantics of additive restoration with carries, we require:

z1+z2z3=x3+y3x1x2y1y2+αnβ.

Let C:=x1+x2x3αn+β, which is fully determined by type-0 entries and carry values.

We distinguish cases according to the presence/absence of type-1 and type-2 entries in the column:

  1. (1)

    All of ci𝟏,ci𝟐,ci𝟑 are not type-2. In this case, it suffices to check whether the type-1 variables admit a unique assignment, which can be done by a straightforward extension of Lemma 16.

  2. (2)

    All of ci𝟏,ci𝟐,ci𝟑 are not type-1. In this case, there are no type-1 variables, so uniqueness holds vacuously. We only need to check whether there exists an assignment to the type-2 variables that makes the column consistent. This can be done by treating all type-2 variables as type-1 variables and applying Lemma 16.

  3. (3)

    Exactly one of ci𝟏,ci𝟐,ci𝟑 is a type-1 variable. In this case, equation (6.2) becomes C+z1+z2z3=y3y1y2. The right-hand side can only take a restricted range of values: if y3 is the type-1 variable, then it ranges over [0,n1]; if y1 or y2 is the type-1 variable, then it ranges over [(n1),0]. Thus the feasibility reduces to checking whether one can assign values to at most two type-2 variables among z1,z2,z3 so that the left-hand side falls into the corresponding range. This can be decided in polynomial time by the same idea as in Lemma 16.

  4. (4)

    Exactly two of ci𝟏,ci𝟐,ci𝟑 are type-1 variables. In this case, equation (6.2) becomes C+z1+z2z3=y3y1y2. There are two subcases:

    1. (i)

      y3=0 and both y1,y2 are type-1. Then the equation reduces to C+z1+z2z3=(y1+y2). The pair (y1,y2) is uniquely determined only if the right-hand side is 0 or 2(n1), yielding (y1,y2)=(0,0) or (n1,n1).

    2. (ii)

      y1=0 (without loss of generality) and y2,y3 are type-1. Then the equation becomes C+z1+z2z3=y3y2. The pair (y2,y3) is uniquely determined only if the right-hand side is n1 or (n1), which forces (y2,y3)=(0,n1) or (y2,y3)=(n1,0).

    Thus the decision reduces to checking whether the unique type-2 variable among z1,z2,z3 can be assigned so that the left-hand side matches one of these special values. This check can be performed in polynomial time by the same idea as in Lemma 16.

By applying Lemma 17 to each candidate edge, we can construct the graph in polynomial time. Reachability in this graph determines whether a globally consistent and unique assignment exists, completing the algorithm for level-2 restorations.

7 Open Questions

We conclude with some open questions.

  1. 1.

    In this paper we explored the complexity of formulae involving nested !x quantifiers. What can be said about other similar types of quantifiers? For instance, we could consider quantifiers such as “there exist exactly two x satisfying P(x)” and “exactly half of all x satisfy P(x)”.

  2. 2.

    Are there natural examples of parsimonious reductions that are not locally parsimonious?

  3. 3.

    Regarding the hardness of meta-level additive restorations: While we have shown that level-2 additive restorations admit a polynomial-time algorithm, the computational complexity of level-k additive or subtractive restorations for k>2 remains open. Do such problems climb higher in the polynomial hierarchy, or can they still be solved efficiently?

References

  • [1] Michael de Bondt. On the ASP-completeness of cryptarithms. Technical Report 0419, Department of Mathematics, Radboud University, Nijmegen, Netherlands, November 2004. URL: https://hdl.handle.net/2066/60283.
  • [2] David Eppstein. On the NP-completeness of cryptarithms. ACM SIGACT News, 18(3):38–40, 1987. doi:10.1145/24658.24662.
  • [3] Kozaburo Fujimura. Puzzles and Problems (in Japanese). Diamond Sha Co., Ltd., 1969.
  • [4] Harry B. Hunt, Madhav V. Marathe, Venkatesh Radhakrishnan, and Richard E. Stearns. The complexity of planar counting problems. SIAM Journal on Computing, 27(4):1142–1167, 1998. doi:10.1137/S0097539793304601.
  • [5] Yousuke Ikeda. X post on July 28, 2024. https://x.com/ikeikey/status/1817448938322202776. Accessed: 2024-09-21.
  • [6] Tomomi Matsui. NP-completeness of arithmetical restorations. Journal of Information Processing, 21(3):402–404, July 2013. doi:10.2197/IPSJJIP.21.402.
  • [7] Ryuhei Uehara. Computational complexity of puzzles and related topics. Interdisciplinary Information Sciences, 29(2):1–23, 2023. doi:10.4036/iis.2022.R.06.
  • [8] Ryuhei Uehara. Algorithms for Puzzles (in Japanese). Nippon Hyoron Sha Co., Ltd., 2024.
  • [9] Takayuki Yato and Takahiro Seta. Complexity and completeness of finding another solution and its application to puzzles. IEICE Transactions on Fundamentals of Electronics, Communications, and Computer Sciences, E86-A(5):1052–1060, 2003. Also IPSJ SIG Notes 2002-AL-87-2, 2002. URL: http://ci.nii.ac.jp/naid/110003221178/en/.