Stratified Context Unification Is NP-Complete

  • Jordi Levy
  • Manfred Schmidt-Schauß
  • Mateu Villaret
Part of the Lecture Notes in Computer Science book series (LNCS, volume 4130)


Context Unification is the problem to decide for a given set of second-order equations E where all second-order variables are unary, whether there exists a unifier, such that for every second-order variable X, the abstraction λx. r instantiated for X has exactly one occurrence of the bound variable x in r. Stratified Context Unification is a specialization where the nesting of second-order variables in E is restricted.

It is already known that Stratified Context Unification is decidable, NP-hard, and in PSPACE, whereas the decidability and the complexity of Context Unification is unknown. We prove that Stratified Context Unification is in NP by proving that a size-minimal solution can be represented in a singleton tree grammar of polynomial size, and then applying a generalization of Plandowski’s polynomial algorithm that compares compacted terms in polynomial time. This also demonstrates the high potential of singleton tree grammars for optimizing programs maintaining large terms.

A corollary of our result is that solvability of rewrite constraints is NP-complete.


Context Variable Function Symbol Decision Algorithm Surface Equation Main Path 


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. [And86]
    Andrews, P.: An introduction to mathematical logic and type theory: to truth through proof. Academic Press, London (1986)MATHGoogle Scholar
  2. [BLM05]
    Busatto, G., Lohrey, M., Maneth, S.: Efficient memory representation of XML documents. In: Bierman, G., Koch, C. (eds.) DBPL 2005. LNCS, vol. 3774, pp. 199–216. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  3. [CDG+97]
    Comon, H., Dauchet, M., Gilleron, R., Jacquemard, F., Lugiez, D., Tison, S., Tommasi, M.: Tree automata techniques and applications (1997) (release, October 1, 2002), available on
  4. [Dow01]
    Dowek, G.: Higher-order unification and matching. In: Robinson, A., Voronkov, A. (eds.) Handbook of Automated Reasoning, ch. 16, vol. II, pp. 1009–1062. Elsevier Science, Amsterdam (2001)CrossRefGoogle Scholar
  5. [EN00]
    Erk, K., Niehren, J.: Parallelism constraints. In: Bachmair, L. (ed.) RTA 2000. LNCS, vol. 1833, pp. 110–126. Springer, Heidelberg (2000)CrossRefGoogle Scholar
  6. [Far91]
    Farmer, W.M.: Simple second-order languages for wich unification is undecidable. Theoretical Computer Science 87, 173–214 (1991)CrossRefMathSciNetGoogle Scholar
  7. [Gol81]
    Goldfarb, W.D.: The undecidability of the second-order unification problem. Theoretical Computer Science 13, 225–230 (1981)MATHCrossRefMathSciNetGoogle Scholar
  8. [Hue75]
    Huet, G.: A unification algorithm for typed λ-calculus. Theoretical Computer Science 1, 27–57 (1975)CrossRefMathSciNetGoogle Scholar
  9. [KNT98]
    Koller, A., Niehren, J., Treinen, R.: Dominance constraints: Algorithms and complexity. In: Moortgat, M. (ed.) LACL 1998. LNCS (LNAI), vol. 2014, pp. 106–125. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  10. [KP96]
    Kościelski, A., Pacholski, L.: Complexity of Makanin’s algorithm. Journal of the ACM 43(4), 670–684 (1996)MATHCrossRefMathSciNetGoogle Scholar
  11. [Lev96]
    Levy, J.: Linear second order unification. In: Ganzinger, H. (ed.) RTA 1996. LNCS, vol. 1103, pp. 332–346. Springer, Heidelberg (1996)Google Scholar
  12. [LNV05]
    Levy, J., Niehren, J., Villaret, M.: Well-nested context unification. In: Nieuwenhuis, R. (ed.) CADE 2005. LNCS (LNAI), vol. 3632, pp. 149–163. Springer, Heidelberg (2005)CrossRefGoogle Scholar
  13. [LSSV04]
    Levy, J., Schmidt-Schauß, M., Villaret, M.: Monadic second-order unification is NP-complete. In: van Oostrom, V. (ed.) RTA 2004. LNCS, vol. 3091, pp. 55–69. Springer, Heidelberg (2004)CrossRefGoogle Scholar
  14. [LSSV06]
    Levy, J., Schmidt-Schauß, M., Villaret, M.: Bounded second-order unification is NP-complete. In: Pfenning, F. (ed.) RTA 2006. LNCS, vol. 4098, Springer, Heidelberg (2006)CrossRefGoogle Scholar
  15. [LV00]
    Levy, J., Veanes, M.: On the undecidability of second-order unification. Information and Computation 159, 125–150 (2000)MATHCrossRefMathSciNetGoogle Scholar
  16. [LV02]
    Levy, J., Villaret, M.: Currying second-order unification problems. In: Tison, S. (ed.) RTA 2002. LNCS, vol. 2378, pp. 326–339. Springer, Heidelberg (2002)CrossRefGoogle Scholar
  17. [Mak77]
    Makanin, G.S.: The problem of solvability of equations in a free semigroup. Math. USSR Sbornik 32(2), 129–198 (1977)MATHCrossRefGoogle Scholar
  18. [NK01]
    Niehren, J., Koller, A.: Dominance constraints in context unification. In: Moortgat, M. (ed.) LACL 1998. LNCS (LNAI), vol. 2014, pp. 199–218. Springer, Heidelberg (2001)CrossRefGoogle Scholar
  19. [NPR97a]
    Niehren, J., Pinkal, M., Ruhrberg, P.: On equality up-to constraints over finite trees, context unification, and one-step rewriting. In: McCune, W. (ed.) CADE 1997. LNCS, vol. 1249, pp. 34–48. Springer, Heidelberg (1997)Google Scholar
  20. [NPR97b]
    Niehren, J., Pinkal, M., Ruhrberg, P.: A uniform approach to underspecification and parallelism. In: 35th ACL 1997, Madrid, pp. 410–417 (1997)Google Scholar
  21. [NTT00]
    Niehren, J., Tison, S., Treinen, R.: On rewrite constraints and context unification. Information Processing Letters 74, 35–40 (2000)MATHCrossRefMathSciNetGoogle Scholar
  22. [Pau94]
    Paulson, L.C.: Isabelle. LNCS, vol. 828. Springer, Heidelberg (1994)MATHCrossRefGoogle Scholar
  23. [Pla94]
    Plandowski, W.: Testing equivalence of morphisms in context-free languages. In: van Leeuwen, J. (ed.) ESA 1994. LNCS, vol. 855, pp. 460–470. Springer, Heidelberg (1994)CrossRefGoogle Scholar
  24. [Pla95]
    Plandowski, W.: The Complexity of the Morphism Equivalence Problem for Context-Free Languages. PhD thesis, Dept. of Mathematics, Informatics and Mechanics, Warsaw University (1995)Google Scholar
  25. [Pla04]
    Plandowski, W.: Satisfiability of word equations with constants is in PSPACE. Journal of the ACM 51(3), 483–496 (2004)MATHCrossRefMathSciNetGoogle Scholar
  26. [PS99]
    Pfenning, F., Schürmann, C.: System description: Twelf - a meta-logical framework for deductive systems. In: Ganzinger, H. (ed.) CADE 1999. LNCS (LNAI), vol. 1632, pp. 202–206. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  27. [SAT06] (2006)Google Scholar
  28. [SS98]
    Schmidt-Schauß, M.: A decision algorithm for distributive unification. TCS 208, 111–148 (1998)MATHCrossRefGoogle Scholar
  29. [SS02]
    Schmidt-Schauß, M.: A decision algorithm for stratified context unification. Journal of Logic and Computation 12(6), 929–953 (2002)MATHCrossRefMathSciNetGoogle Scholar
  30. [SS05]
    Schmidt-Schauß, M.: Polynomial equality testing for terms with shared substructures. Frank report 21, Institut für Informatik. FB Informatik und Mathematik. J. W. Goethe-Universität Frankfurt am Main (November 2005)Google Scholar
  31. [SSS98]
    Schmidt-Schauß, M., Schulz, K.U.: On the exponent of periodicity of minimal solutions of context equations. In: Nipkow, T. (ed.) RTA 1998. LNCS, vol. 1379, pp. 61–75. Springer, Heidelberg (1998)CrossRefGoogle Scholar
  32. [SSS04]
    Schmidt-Schauß, M., Stuber, J.: On the complexity of linear and stratified context matching problems. Theory of Computing Systems 37, 717–740 (2004)MATHCrossRefMathSciNetGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2006

Authors and Affiliations

  • Jordi Levy
    • 1
  • Manfred Schmidt-Schauß
    • 2
  • Mateu Villaret
    • 3
  1. 1.IIIA, CSICBarcelonaSpain
  2. 2.Institut für Informatik, FB Informatik und MathematikJohann Wolfgang Goethe-UniversitätFrankfurtGermany
  3. 3.IMA, UdGGironaSpain

Personalised recommendations