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

Savvy Sahai

Data Science Intern, Capgemini
linkedin profile url

As a student looking to break into the field of data engineering and data science, one can get really confused as to which path to take. Very few ways to do it are Google, YouTube, etc. I was one of... Read More

Relevant Projects

Learn to Build Generative Models Using PyTorch Autoencoders
In this deep learning project, you will learn how to build a Generative Model using Autoencoders in PyTorch

Build a Churn Prediction Model using Ensemble Learning
Learn how to build ensemble machine learning models like Random Forest, Adaboost, and Gradient Boosting for Customer Churn Prediction using Python

Time Series Project to Build a Multiple Linear Regression Model
Learn to build a Multiple linear regression model in Python on Time Series Data

Azure Text Analytics for Medical Search Engine Deployment
Microsoft Azure Project - Use Azure text analytics cognitive service to deploy a machine learning model into Azure Databricks

Build a Graph Based Recommendation System in Python-Part 2
In this Graph Based Recommender System Project, you will build a recommender system project for eCommerce platforms and learn to use FAISS for efficient similarity search.

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.

Text Classification with Transformers-RoBERTa and XLNet Model
In this machine learning project, you will learn how to load, fine tune and evaluate various transformer models for text classification tasks.

Build an Image Segmentation Model using Amazon SageMaker
In this Machine Learning Project, you will learn to implement the UNet Architecture and build an Image Segmentation Model using Amazon SageMaker

Topic modelling using Kmeans clustering to group customer reviews
In this Kmeans clustering machine learning project, you will perform topic modelling in order to group customer reviews based on recurring patterns.

BERT Text Classification using DistilBERT and ALBERT Models
This Project Explains how to perform Text Classification using ALBERT and DistilBERT