Logic Module
===============

.. module:: sympy.logic

Introduction
------------

The logic module for SymPy allows to form and manipulate logic expressions
using symbolic and boolean values.

Forming logical expressions
---------------------------

You can build boolean expressions with the standard python operators ``&``
(:class:`And`), ``|`` (:class:`Or`), ``~`` (:class:`Not`)::

    >>> from sympy import *
    >>> x, y = symbols('x,y')
    >>> y | (x & y)
    Or(And(x, y), y)
    >>> x | y
    Or(x, y)
    >>> ~x
    Not(x)

You can also form implications with ``>>`` and ``<<``::

    >>> x >> y
    Implies(x, y)
    >>> x << y
    Implies(y, x)

Like most types in SymPy, Boolean expressions inherit from :class:`Basic`::

    >>> (y & x).subs({x: True, y: True})
    True
    >>> (x | y).atoms()
    set([x, y])

Boolean functions
-----------------------

.. autofunction:: sympy.logic.boolalg.to_cnf

.. autoclass:: sympy.logic.boolalg.And

.. autoclass:: sympy.logic.boolalg.Or

.. autoclass:: sympy.logic.boolalg.Not

.. autoclass:: sympy.logic.boolalg.Xor

.. autoclass:: sympy.logic.boolalg.Nand

.. autoclass:: sympy.logic.boolalg.Nor

.. autoclass:: sympy.logic.boolalg.Implies

.. autoclass:: sympy.logic.boolalg.Equivalent

.. autoclass:: sympy.logic.boolalg.ITE

Inference
---------

.. module: sympy.logic.inference

This module implements some inference routines in propositional logic.

The function satisfiable will test that a given boolean expression is satisfiable,
that is, you can assign values to the variables to make the sentence True.

For example, the expression x & ~x is not satisfiable, since there are no values
for x that make this sentence True. On the other hand, (x | y) & (x | ~y) & (~x | y)
is satisfiable with both x and y being True.

    >>> from sympy.logic.inference import satisfiable
    >>> from sympy import Symbol
    >>> x = Symbol('x')
    >>> y = Symbol('y')
    >>> satisfiable(x & ~x)
    False
    >>> satisfiable((x | y) & (x | ~y) & (~x | y))
    {x: True, y: True}

As you see, when a sentence is satisfiable, it returns a model that makes that
sentence True. If it is not satisfiable it will return False

.. autofunction:: sympy.logic.inference.satisfiable

.. TODO: write about CNF file format
