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

Sets


The Sets SymPy module enables users to perform set theory computations. It has classes, or submodules, for representing various types of sets, such as a finite set (a finite set of discrete numbers) and an interval (represents a real interval as a set), a singleton set, a universal set, naturals (sets of natural numbers), and others. It also has submodules for performing various operations on compound sets, such as union, intersection, product set, complement, and others.

The following program demonstrates the creation of an interval set and a finite set. It also demonstrates the start and end attributes of the interval set and left open and right open interval sets. At the end, the program also uses the option of checking the existence of a specific element in a finite set:

from sympy import Symbol, Interval
from sympy import FiniteSet

Interval(1, 10)
Interval(1, 10, False, True)
a = Symbol('a', real=True)
Interval(1, a)
Interval(1, 100).end
from sympy import Interval
Interval(0, 1...