Skip to main content

The Picat-SAT Compiler

  • Conference paper
  • First Online:

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 9585))

Abstract

SAT has become the backbone of many software systems. In order to make full use of the power of SAT solvers, a SAT compiler must encode domain variables and constraints into an efficient SAT formula. Despite many proposals for SAT encodings, there are few working SAT compilers. This paper presents Picat-SAT, the SAT compiler in the Picat system. Picat-SAT employs the sign-and-magnitude log encoding for domain variables. Log-encoding for constraints resembles the binary representation of numbers used in computer hardware, and many algorithms and optimization opportunities have been exploited by hardware design systems. This paper gives the encoding algorithms for constraints, and attempts to experimentally justify the choices of the algorithms for the addition and multiplication constraints. This paper also presents preliminary, but quite encouraging, experimental results.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   34.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   44.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Notes

  1. 1.

    The FznTini compiler is not maintained.

  2. 2.

    Picat supports the dot-notation for chaining function calls. The function call Board.vars() is the same as vars(Board).

  3. 3.

    The operators div and mod can be expressed by using the multiplication operator \(\times \). In the implemented version of Picat-SAT, Pseudo-Boolean constraints are treated in the same way as other linear constraints, except for the special case \(\varSigma _{i}^nB_i\ r\ c\) (c = 1 or 2).

  4. 4.

    Booth’s algorithm has not yet been implemented in Picat-SAT.

  5. 5.

    Efforts were also made to compare Picat-SAT with FznTini [15], a log-encoding based SAT compiler, and with meSAT [29], which supports the hybrid of order and sparse encodings. FznTini is for an old version of FlatZinc, and the default setting of meSAT did not perform better than Sugar on the benchmarks.

  6. 6.

    The CPU time does not include the compile time for any of the SAT compilers.

  7. 7.

    Picat-SAT scored 0 on project-planning because mzn2fzn failed to specialize the element constraint, which prevented Picat’s FlatZinc interpreter from functioning. It was understood that mzn2fzn would specialize generic global constraints into specific ones once the types of the arguments are known.

  8. 8.

    Note that the code size sometimes decreases with N because of the domain constraints.

References

  1. Biere, A., Heule, M., van Maaren, H., Walsh, T. (eds.): Handbook of Satisfiability. IOS Press, Amsterdam (2009)

    MATH  Google Scholar 

  2. Bjork, M.: Successful SAT encoding techniques. JSAT Addendum (2009)

    Google Scholar 

  3. Booth, A.D.: A signed binary multiplication technique. Q. J. Mech. Appl. Math. IV, 236–240 (1951)

    Article  MathSciNet  MATH  Google Scholar 

  4. Bordeaux, L., Hamadi, Y., Zhang, L.: Propositional satisfiability and constraint programming: a comparative survey. ACM Comput. Surv. 38(4), 1–54 (2006)

    Article  Google Scholar 

  5. Brayton, R.K., Hachtel, G.D., McMullen, C.T., Sangiovanni-Vincentelli, A.L.: Logic Minimization Algorithms for VLSI Synthesis. Kluwer Academic Publishers, Boston (1984)

    Book  MATH  Google Scholar 

  6. Brewka, G., Eiter, T., Truszczyński, M.: Answer set programming at a glance. Commun. ACM 54(12), 92–103 (2011)

    Article  Google Scholar 

  7. Chen, J.: A new SAT encoding of the at-most-one constraint. In: Proceeding of the 9th International Workshop of Constraint Modeling and Reformulation (2010)

    Google Scholar 

  8. Crawford, J.M., Baker, A.B.: Experimental results on the application of satisfiability algorithms to scheduling problems. In: AAAI, pp. 1092–1097 (1994)

    Google Scholar 

  9. Boulanger, J.L. (ed.): Formal Methods Applied to Industrial Complex Systems: Implementation of the B Method. Wiley, New York (2014)

    Google Scholar 

  10. Francis, K.G., Stuckey, P.J.: Explaining circuit propagation. Constraints 19(1), 1–29 (2014)

    Article  MathSciNet  MATH  Google Scholar 

  11. Gavanelli, M.: The log-support encoding of CSP into SAT. In: CP, pp. 815–822 (2007)

    Google Scholar 

  12. Gebser, M., Kaufmann, B., Neumann, A., Schaub, T.: Conflict-driven answer set solving. In: IJCAI, pp. 386–392 (2007)

    Google Scholar 

  13. Ian Gent, P.: Arc consistency in SAT. In: ECAI, pp. 121–125 (2002)

    Google Scholar 

  14. Van Hentenryck, P.: Constraint and integer programming in OPL. INFORMS J. Comput. 14, 345–372 (2002)

    Article  MathSciNet  MATH  Google Scholar 

  15. Huang, J.: Universal Booleanization of constraint models. In: CP, pp. 144–158 (2008)

    Google Scholar 

  16. Iwama, K., Miyazaki, S.: SAT-varible complexity of hard combinatorial problems. IFIP Congress 1, 253–258 (1994)

    MathSciNet  Google Scholar 

  17. Jackson, D.: Software Abstractions: Logic, Language, and Analysis. MIT Press, Cambridge (2012)

    Google Scholar 

  18. Jackson, E.K.: A module system for domain-specific languages. Theory Pract. Logic Program. 14(4–5), 771–785 (2014)

    Article  MATH  Google Scholar 

  19. Jeavons, P., Petke, J.: Local consistency and SAT-solvers. JAIR 43, 329–351 (2012)

    MathSciNet  MATH  Google Scholar 

  20. Karatsuba, A., Ofman, Y.: Multiplication of many-digital numbers by automatic computers. In: Proceeding the USSR Academy of Sciences, vol. 145 pp. 293–294 (1962)

    Google Scholar 

  21. Kautz, H.A., Selman, B.: Planning as satisfiability. In: ECAI, pp. 359–363 (1992)

    Google Scholar 

  22. Lamport, L.: Specifying Systems: The TLA+ Language and Tools for Hardware and Software Engineers. Addison-Wesley (2004)

    Google Scholar 

  23. Malik, S., Zhang, L.: Boolean satisfiability: from theoretical hardness to practical success. Commun. ACM 52(8), 76–82 (2009)

    Article  Google Scholar 

  24. Marriott, K., Stuckey, P.J., De Koninck, L., Samulowitz, H.: A MiniZinc tutorial. http://www.minizinc.org/downloads/doc-latest/minizinc-tute.pdf

  25. Metodi, A., Codish, M.: Compiling finite domain constraints to SAT with BEE. Theory Pract. Logic Program. 12(4–5), 465–483 (2012)

    Article  MATH  Google Scholar 

  26. Nethercote, N., Stuckey, P.J., Becket, R., Brand, S., Duck, G.J., Tack, G.R.: MiniZinc: towards a standard CP modelling language. In: Bessière, C. (ed.) CP 2007. LNCS, vol. 4741, pp. 529–543. Springer, Heidelberg (2007)

    Chapter  Google Scholar 

  27. Rintanen, J.: Planning as satisfiability: heuristics. Artif. Intell. 193, 45–86 (2012)

    Article  MathSciNet  MATH  Google Scholar 

  28. Drechsler, R., Eggersglüß, S.: High Quality Test Pattern Generation and Boolean Satisfiability. Springer, New York (2012)

    MATH  Google Scholar 

  29. Stojadinovic, M., Maric, F.: meSAT: multiple encodings of CSP to SAT. Constraints 19(4), 380–403 (2014)

    Article  MathSciNet  MATH  Google Scholar 

  30. Sugar. bach.istc.kobe-u.ac.jp/sugar/

  31. Tamura, N., Taga, A., Kitagawa, S., Banbara, M.: Compiling finite linear CSP into SAT. Constraints 14(2), 254–272 (2009)

    Article  MathSciNet  MATH  Google Scholar 

  32. Tanjo, T., Tamura, N., Banbara, M.: Azucar: a SAT-based CSP solver using compact order encoding. In: Cimatti, A., Sebastiani, R. (eds.) SAT 2012. LNCS, vol. 7317, pp. 456–462. Springer, Heidelberg (2012)

    Chapter  Google Scholar 

  33. Walsh, T.: SAT \(v\) CSP. In: Dechter, R. (ed.) CP 2000. LNCS, vol. 1894, p. 441. Springer, Heidelberg (2000)

    Chapter  Google Scholar 

  34. Zhou, N.-F., Fruhman, J.: A User’s Guide to Picat. http://picat-lang.org

  35. Zhou, N.-F., Kjellerstrand, H., Fruhman, J.: Constraint Solving and Planning with Picat. Springer, Heidelberg (2015)

    Book  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Neng-Fa Zhou .

Editor information

Editors and Affiliations

Appendices

A The Transformation Algorithm for \(X + Y = Z\)

The transformation algorithm replaces negative domain values by non-negative domain values in the addition constraint. For the constraint \(X+Y = Z\), if any of the operands has a domain with negative values, this method finds the smallest integer k such that abs \((X) < 2^{k-1}\)/, abs \((Y) < 2^{k-1}\), and abs \((Z) < 2^k\), and transforms the original addition constraint to \(Z' = X'+Y'\), where \(X' = X+2^{k-1}\), \(Y' = Y+2^{k-1}\), and \(Z' = Z+2^k\). The newly introduced variables \(X'\), \(Y'\), and \(Z'\) are guaranteed not to include negative values in their domains, and therefore the constraint \(X'+Y' = Z'\) can be Booleanized as \(X'\) .m+\(Y'\) .m = \(Z'\) .m.

The question is how to Booleanize the newly introduced constraints. Consider the constraint \(X' = X+2^{k-1}\). Let X .m = \(X_{k-1}\ldots X_nX_{n-1}\ldots X_1X_0\), and \(X'\) .m = \(X'_{k-1}\ldots X'_1X'_0\) (\(k > n\), \(X_i\) = 0 for \(i = k-1, \ldots , n\)). Note that 0 s are added in the high end of X .m in order for it to have the same length as \(X'\) .m. The constraint \(X' = X+2^{k-1}\) can be translated to a conjunction of the following two conditional constraints:

figure q

Note the unsigned addition X .m + \(X'\) .m = \(2^{k-1}\) can be Booleanized using a much simpler logic than for the general addition. In particular, no new variables are necessary for carries in the addition. In order for the constraint to hold, the following formula must hold:

figure r

The two Boolean variables at the lowest end, \(X_0\) and \(X'_0\), must be equal. Otherwise, the lowest bit of the sum cannot be 0. The intuition of the logic of the for loop is that if there is an 1 at some position, then there must be exactly one 1 at each of the higher positions in order for the sum to be equal to \(2^{k-1}\). Since no negative zero is allowed, at least one of \(X_i\)s is 1. In order for the sum to be equal to \(2^{k-1}\), \(X'_{k-1}\) must be 0.

The idea of removing negative domain values through transformation is well known in linear programming. Unlike in linear programming, however, the transformation is only performed locally on negative-domain variables in addition constraints, and all other constraints, such as abs( X ) = Y, are not affected.

For a negative-domain variable X that occurs in multiple addition constraints, an optimization can be employed to avoid introducing new variables unnecessarily. The compiler memorizes the transformation \(X' = X+2^{k-1}\) in a table. In case the same transformation is required by another addition constraint, then the compiler fetches \(X'\) from the table, rather than introducing new variables.

Table 4 compares the enumeration (enum) and transformation (trans) algorithms, using the constraint \(Z = X+Y\), where X and Y are in \(-N..N\). The code size is not informative on which encoding is better: the enum encoding uses fewer variables but more clauses than the trans encoding.Footnote 8 The time shows that the enum encoding is favorable. This result led to the adoption the enum encoding by Picat-SAT for addition constraints.

Table 4. A comparison of two encodings for \(Z = X+Y\)

B Karatsuba’s Divide and Conquer Algorithm for \(X \times Y = Z\)

Karatsuba’s algorithm [20] is a well-known algorithm for multiplying big integers. It can be applied to numbers in any base. The basic idea of the algorithm is to divide and conquer, splitting large numbers into smaller numbers, until the numbers are small enough.

Let X and Y be two N-digit binary strings. If N is small enough, then the multiplication constraint is Booleanized using shift-and-add. If N is big, then this algorithm selects an integer M (\(1 \le M \le N-1\) ) and splits both X and Y into two parts as follows:

figure s

where \(X_l\) and \(Y_l\) are less than \(2^M\). The product \(X\times Y\) is then

figure t

where

figure u

The resulting formulas require three multiplications, plus some additions, subtractions, and shifts.

Table 5 compares the shift-and-add (saa) and Karatsuba (kara) algorithms, using the constraint \(Z = X\times Y\), where X and Y are in \(-N..N\). The base-case size for the Karatsuba algorithm is set to 3 (i.e., X .m \(\le \) 7 or Y .m \(\le \) 7).

Two observations can be made about the results: first, the code sizes only grow slightly with N no matter which algorithm is used; and second, kara uses more variables and generates more clauses than saa. The Karatsuba algorithm is well used for multiplying big integers and its advantage cannot be witnessed unless the operands are really big. Nevertheless, big domains rarely occur in CSPs. This experimental comparison naturally resulted in the adoption of the shift-and-add algorithm by Picat-SAT for multiplication constraints.

Table 5. A comparison of two encodings for \(Z = X\times Y\)

Rights and permissions

Reprints and permissions

Copyright information

© 2016 Springer International Publishing Switzerland

About this paper

Cite this paper

Zhou, NF., Kjellerstrand, H. (2016). The Picat-SAT Compiler. In: Gavanelli, M., Reppy, J. (eds) Practical Aspects of Declarative Languages. PADL 2016. Lecture Notes in Computer Science(), vol 9585. Springer, Cham. https://doi.org/10.1007/978-3-319-28228-2_4

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-28228-2_4

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-28227-5

  • Online ISBN: 978-3-319-28228-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics