Book Image

Mastering Python Scientific Computing

Book Image

Mastering Python Scientific Computing

Overview of this book

Table of Contents (17 chapters)
Mastering Python Scientific Computing
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The logic module


The logic module allows users to create and manipulate logic expressions using symbolic and Boolean values. The user can build a Boolean expression using Python operators such as & (logical AND), | (logical OR), and ~ (logical NOT). The user can also create implications using >> and << . The following program demonstrates the use of these operators:

from sympy.logic import *
a, b = symbols('a b')
a | (a & b)
a | b
~a

a >> b
a << b

This module also has a function for logical Xor, Nand, Nor, logical implication, and the equivalence relation. These functions are used in the following program to demonstrate their capability. All of these functions support their symbolic forms and computations on these operators. In symbolic form, the expression represented in the symbol form, they are not evaluated. This is demonstrated using the a and b symbols:

from sympy.logic.boolalg import Xor
from sympy import symbols
Xor(True, False)
Xor(True, True)
Xor(True...