Introducing Bauhaus: Simplifying Propositional Logic Encodings in Python
Are you looking to simplify the process of creating propositional logic encodings using Python? Look no further! In this article, we introduce Bauhaus, a Python package that allows you to spin up propositional logic encodings from object-oriented Python code. With its intuitive features and capabilities, Bauhaus makes it easier than ever to build and compile SAT encoding constraints. So, let’s dive in and explore this powerful tool.
Features
Bauhaus offers a range of features designed to streamline the creation of propositional logic encodings. Some of its notable features include:
- Creation of propositional variables from Python classes
- Building naive SAT encoding constraints:
- At most one
- At least one
- Exactly one
- At most K
- Implies all
- Compilation of constraints into a theory in conjunctive or negation normal form
- Seamless integration with
python-nnf
for theory submission to a SAT solver - Theory introspection for a deeper understanding of constraint origins
Installation
Getting started with Bauhaus is a breeze. Simply install the package using pip:
bash
pip install bauhaus
How is it Used?
To efficiently work with Bauhaus, you’ll need to create an Encoding object to store your model’s propositional variables and constraints. For example:
“`python
from bauhaus import Encoding, proposition, constraint
e = Encoding()
“`
Next, you can create propositional variables by decorating class definitions with the @proposition
decorator. Here’s an example:
python
@proposition(e) # Each instance of A is stored as a proposition
class A(object):
pass
Constraints can be created in various ways, such as decorating classes, methods, or using the constraint methods directly. Take a look at this example:
“`python
@constraint.implies_all(e, right=[‘hello’])
@constraint.at_most_k(e, 2)
@proposition(e)
class A(object):
def __init__(self, val):
self.val = val
def __repr__(self):
return f"A.{self.val}"
@constraint.implies_all(e)
def method(self):
return self.val
constraint.add_at_most_one(e, A, A.method, Var(‘B’))
“`
Once your theory is ready, you can compile it into conjunctive or negation normal form using the compile()
method. Here’s a snippet:
python
objects = [A(val) for val in range(1, 4)]
theory = e.compile()
In addition to the theory compilation, Bauhaus allows for insightful introspection to understand the origin of each constraint. This introspection feature provides valuable information for debugging and analysis.
Contribute and Support
If you’re interested in contributing to the development of Bauhaus, head over to their GitHub repository. Make sure to read their code of conduct to get started. You can also explore the architecture design and documentation to gain a deeper understanding of the library.
If you encounter any issues or have questions, don’t hesitate to reach out to the Bauhaus team. You can create a GitHub issue or contact them via email at karishma.daga@queensu.ca.
License and Citing This Work
Bauhaus is licensed under the MIT license and was created by Karishma Daga under the mentorship of Christian Muise at Queen’s University, Kingston. If you use Bauhaus in your work, consider citing it to acknowledge the contributors and support further research and development.
We hope this introduction to Bauhaus has sparked your interest in leveraging propositional logic encodings in Python. With its powerful features and straightforward usage, Bauhaus offers immense value for developers and researchers alike. Start exploring the world of propositional logic encodings with Bauhaus today!
What are your thoughts on Bauhaus? How do you envision leveraging propositional logic encodings in your projects? We’d love to hear from you! Share your insights and experiences in the comments below.
Category: Software Development
Tags: Python, Propositional Logic, SAT Encodings, Object-Oriented Programming
Leave a Reply