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

Anand Kumpatla

Sr Data Scientist @ Doubleslash Software Solutions Pvt Ltd
linkedin profile url

ProjectPro is a unique platform and helps many people in the industry to solve real-life problems with a step-by-step walkthrough of projects. A platform with some fantastic resources to gain... Read More

Relevant Projects

Credit Card Fraud Detection as a Classification Problem
In this data science project, we will predict the credit card fraud in the transactional dataset using some of the predictive models.

Forecasting Business KPI's with Tensorflow and Python
In this machine learning project, you will use the video clip of an IPL match played between CSK and RCB to forecast key performance indicators like the number of appearances of a brand logo, the frames, and the shortest and longest area percentage in the video.

Natural language processing Chatbot application using NLTK for text classification
In this NLP AI application, we build the core conversational engine for a chatbot. We use the popular NLTK text classification library to achieve this.

Build an optimal End-to-End MLOps Pipeline and Deploy on GCP
Learn how to build and deploy an end-to-end optimal MLOps Pipeline for Loan Eligibility Prediction Model in Python on GCP

Build Deep Autoencoders Model for Anomaly Detection in Python
In this deep learning project , you will build and deploy a deep autoencoders model using Flask.

Image Segmentation using Mask R-CNN with Tensorflow
In this Deep Learning Project on Image Segmentation Python, you will learn how to implement the Mask R-CNN model for early fire detection.

Machine Learning project for Retail Price Optimization
In this machine learning pricing project, we implement a retail price optimization algorithm using regression trees. This is one of the first steps to building a dynamic pricing model.

Build an End-to-End AWS SageMaker Classification Model
MLOps on AWS SageMaker -Learn to Build an End-to-End Classification Model on SageMaker to predict a patient’s cause of death.

AWS MLOps Project for ARCH and GARCH Time Series Models
Build and deploy ARCH and GARCH time series forecasting models in Python on AWS .

Isolation Forest Model and LOF for Anomaly Detection in Python
Credit Card Fraud Detection Project - Build an Isolation Forest Model and Local Outlier Factor (LOF) in Python to identify fraudulent credit card transactions.