What are the Logical Expressions in Sympy

This recipe explains what are the Logical Expressions in Sympy

Recipe Objective - What are the Logical Expressions in Sympy?

Boolean functions are defined in the sympy.basic.booleanarg module. It is possible to express Boolean expressions using the standard Python operators & (AND), | . to create (or), ~ (not) as well as >> and & <<. Boolean expressions inherit from the Basic class, which is defined in the main SymPy module.

Learn to use RNN for Text Classification with Source Code 

For more related projects -

https://www.projectpro.io/projects/data-science-projects/deep-learning-projects
https://www.projectpro.io/projects/data-science-projects/neural-network-projects

Example:

# Importing libraries
from sympy.abc import p,q
from sympy import sympify,pprint
from sympy.logic.boolalg import And,Or

p=sympify(True)
print("P => ",p)
q=sympify(False)
print("Q => ",q)


# AND (OPTION 1)
ans = And(p,q)
print("And between P & Q (OPTION 1) => ",ans)

# AND (OPTION 2)
ans = p & q
print("And between P & Q (OPTION 2) => ",ans)


# OR (OPTION 1)
ans = Or(p,q)
print("OR between P & Q (OPTION 1) => ",ans)

# OR (OPTION 2)
ans = p | q
print("OR between P & Q (OPTION 2) => ",ans)

Output - 
P =>  True
Q =>  False
And between P & Q (OPTION 1) =>  False
And between P & Q (OPTION 2) =>  False
OR between P & Q (OPTION 1) =>  True
OR between P & Q (OPTION 2) =>  True

Similarly, we can perform the other logical expressions as well.

What Users are saying..

profile image

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

Skip Gram Model Python Implementation for Word Embeddings
Skip-Gram Model word2vec Example -Learn how to implement the skip gram algorithm in NLP for word embeddings on a set of documents.

Abstractive Text Summarization using Transformers-BART Model
Deep Learning Project to implement an Abstractive Text Summarizer using Google's Transformers-BART Model to generate news article headlines.

Predictive Analytics Project for Working Capital Optimization
In this Predictive Analytics Project, you will build a model to accurately forecast the timing of customer and supplier payments for optimizing working capital.

Build a Multi Class Image Classification Model Python using CNN
This project explains How to build a Sequential Model that can perform Multi Class Image Classification in Python using CNN

MLOps Project to Deploy Resume Parser Model on Paperspace
In this MLOps project, you will learn how to deploy a Resume Parser Streamlit Application on Paperspace Private Cloud.

Credit Card Default Prediction using Machine learning techniques
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

Detectron2 Object Detection and Segmentation Example Python
Object Detection using Detectron2 - Build a Dectectron2 model to detect the zones and inhibitions in antibiogram images.

Build CNN for Image Colorization using Deep Transfer Learning
Image Processing Project -Train a model for colorization to make grayscale images colorful using convolutional autoencoders.

Recommender System Machine Learning Project for Beginners-3
Content Based Recommender System Project - Building a Content-Based Product Recommender App with Streamlit

Recommender System Machine Learning Project for Beginners-4
Collaborative Filtering Recommender System Project - Comparison of different model based and memory based methods to build recommendation system using collaborative filtering.