How to simplify an algebraic expression in Sympy

This recipe helps you simplify an algebraic expression in Sympy

Recipe Objective - How to simplify an algebraic expression in Sympy?

Sympy provides the simplify() function, which can change the given algebraic expression into a simpler form.

For more related projects -

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

Example:

# Example 1:

# Importing libraries
from sympy import pprint, simplify, cot, sec
from sympy.abc import p

# Defining some expression
expression = 1 / cot(p)
print("Normal expression => ")
pprint(expression)

print('-----------------------')

print("Simplified expression => ")
simplified_expression = simplify(expression)
pprint(simplified_expression)

Output - 
Normal expression => 
  1   
──────
cot(p)
-----------------------
Simplified expression => 
tan(p)

# Example 2:

# Importing libraries
from sympy import pprint, simplify, sin, cos
from sympy.abc import p

# Defining some expression
expression = (sin(p)**2) + (cos(p)**2)
print("Normal expression => ")
pprint(expression)

print('-----------------------')

print("Simplified expression => ")
simplified_expression = simplify(expression)
pprint(simplified_expression)

Output - 
Normal expression => 
   2         2   
sin (p) + cos (p)
-----------------------
Simplified expression => 
1

In this way, we can simplify the algebraic expression in sympy.

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

PyCaret Project to Build and Deploy an ML App using Streamlit
In this PyCaret Project, you will build a customer segmentation model with PyCaret and deploy the machine learning application using Streamlit.

OpenCV Project to Master Advanced Computer Vision Concepts
In this OpenCV project, you will learn to implement advanced computer vision concepts and algorithms in OpenCV library using Python.

NLP and Deep Learning For Fake News Classification in Python
In this project you will use Python to implement various machine learning methods( RNN, LSTM, GRU) for fake news classification.

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

Locality Sensitive Hashing Python Code for Look-Alike Modelling
In this deep learning project, you will find similar images (lookalikes) using deep learning and locality sensitive hashing to find customers who are most likely to click on an ad.

A/B Testing Approach for Comparing Performance of ML Models
The objective of this project is to compare the performance of BERT and DistilBERT models for building an efficient Question and Answering system. Using A/B testing approach, we explore the effectiveness and efficiency of both models and determine which one is better suited for Q&A tasks.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

House Price Prediction Project using Machine Learning in Python
Use the Zillow Zestimate Dataset to build a machine learning model for house price prediction.

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.

Medical Image Segmentation Deep Learning Project
In this deep learning project, you will learn to implement Unet++ models for medical image segmentation to detect and classify colorectal polyps.