DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Introduction To Git
  • Which Is Better for IoT: Azure RTOS or FreeRTOS?
  • What ChatGPT Needs Is Context
  • What Is JHipster?

Trending

  • Introduction To Git
  • Which Is Better for IoT: Azure RTOS or FreeRTOS?
  • What ChatGPT Needs Is Context
  • What Is JHipster?
  1. DZone
  2. Coding
  3. Languages
  4. Mathematical Notation for Python Developers (Part 1)

Mathematical Notation for Python Developers (Part 1)

Learn the amazing and remarkable world of Mathematical Notation Jargon the human way with basic Python scripts.

Aderito Xavier user avatar by
Aderito Xavier
·
Jun. 16, 20 · Tutorial
Like (11)
Save
Tweet
Share
6.28K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

As a self-taught developer, I struggled most of the time reading whitepapers, or going through data science courses that contain incredible amounts of mathematical jargon (mostly weird and magic symbols).

This tutorial is going to be focused on translating mathematical notation to Python.

NOTE: Python 3.6 is what I will be using throughout this tutorial series.

FYI: I will avoid using any libraries whenever I can so that anyone can easily understand what is going on underneath the notation.

My thanks to Edward R. Scheinerman for the book Mathematical Notation: A Guide for Engineers and Scientists which was my biggest help at the start.

If you are struggling as I did I strongly advice you to buy it, here is a link if you feel inclined to https://www.amazon.co.uk/Mathematical-Notation-Engineers-Scientists-Scheinerman/dp/B00E321MU8.



Let's Get Started

SETS

A set is a collection of items where repetition is forbidden.

Example: {1, 2, 3, 4}

Reinforced note: A set with repetition like {1,2,3,4,4} will be equal to {1,2,3,4} again, because repetition is non-existent within a set.

Set Declaration in Python:

Java
 




x


 
1
# Declare the set
2
my_set = {1, 2, 3, 4, 4}
3
# Will output {1, 2, 3, 4}
4

          
5
# FUN NOTE: Strings can also be added to sets in Python like        # {"Banana", "Apple"}


Set and Element Membership

Memberships between Sets and elements are defined with the following symbols:

For easy readability, I will add the symbol followed by it’s meaning.

∈ (element exists in), 1 ∈ {1, 2, 3}

∋ (set contains element), {1, 2, 3} ∋ 1

Java
 




xxxxxxxxxx
1


 
1
# Declare the set
2
my_set = {1, 2, 3}
3

          
4
print(1 in my_set) # Equivalent to 1 ∈ {1, 2, 3} or {1, 2, 3} ∋ 1
5
>> True


∉ (element does not exist in), 1 ∉ {2, 5, 6}

∌ (set does not contain element), {2, 5, 6} ∌ 1

Java
 




xxxxxxxxxx
1


 
1
# Declare the set
2
my_set = {1, 2, 3}
3

          
4
(1 not in my_set) # Equivalent to 1 ∉ {2, 5, 6} or {2, 5, 6} ∌ 1
5
>> True


Dealing With Large Sets

Let’s say you want to create a set that goes from 1 to 100, you do not want to write everything on paper, instead, you can show some of the elements that convey the pattern and fills the rest with ellipses (…).

Example: {1, 2, 3, 4, 5, …, 100}

You can also take the following approach:

{x ∈ ℤ: 1 ≤ x ≤ 100}

NOTES:

  • ℤ = {-∞, …, -2,-1,0,1,2….∞} = the set of all integers.

  • x represents a dummy variable used for each iteration.

x ∈ ℤ = x iteration is part of the ℤ set, in other words, x is gonna be an integer in each iteration.

1 ≤ x ≤ 100 = Each x iteration is going to be (greater or equal to 1) and (less or equal to 100).

Java
 




xxxxxxxxxx
1
18


 
1
# In case you are wondering about why the range goes to 101, that is 
2
# because, the last argument is where it stops, meaning it will only 
3
# reach the previous iteration
4
# (100).
5
# For more information check:   
6
# https://www.geeksforgeeks.org/python-range-function/
7

          
8
our_set = {x for x in range(1, 101)}
9
print(our_set)
10
>> {1, 2, 3, 4,..., 100}
11

          
12
# or the easiest approach for newcomers.
13

          
14
our_set = set()
15
for x in range(1, 101):    
16
    our_set.add(x)
17
print(our_set)
18
>> {1, 2, 3, 4,..., 100}


Set to Set Membership

Set Equality

A = {1, 2, 3, 4, 5} and B = {1, 2, 3, 4, 5} then we can say that A = B because the elements found in both variables are the same.

Subsets

A = {1, 2, 3} and B = {1, 2, 3, 4, 5}

We can see that every element in A can be found in B as well, meaning A is a subset of B or A ⊆ B = {1, 2, 3} ⊆ {1, 2, 3, 4, 5}

⊆ equivalent to“subset of”.

Java
 




xxxxxxxxxx
1
19


 
1
# For more info check:
2
# https://www.programiz.com/python-programming/methods/set/issubset
3

          
4
A = {1, 2, 3}
5
B = {1, 2, 3, 4, 5}
6
C = {1, 2, 4, 5}
7

          
8
# Returns True
9
print(A.issubset(B))
10

          
11
# Returns False
12
# B is not subset of A
13
print(B.issubset(A))
14

          
15
# Returns False
16
print(A.issubset(C))
17

          
18
# Returns True
19
print(C.issubset(B))


Supersets

A superset is taken by the opposite order of a subset, since here we are defining that set A has all *the elements of | is a superset of B in which we could also say that B is a subset of A.*

A ⊇ B = B ⊆ A

A = {1, 2, 3, 4, 5} and B = {1, 2, 3}

A ⊇ B = {1, 2, 3, 4, 5} ⊆ {1, 2, 3}

⊇ equivalent to “superset of”.

Java
 




xxxxxxxxxx
1
17


 
1
"""
2
For more information check:
3
https://www.programiz.com/python-programming/methods/set/issuperset
4
"""
5

          
6
A = {1, 2, 3, 4, 5}
7
B = {1, 2, 3}
8
C = {1, 2, 3}
9

          
10
# Returns True
11
print(A.issuperset(B))
12

          
13
# Returns False
14
print(B.issuperset(A))
15

          
16
# Returns True
17
print(C.issuperset(B))


Python (language) dev

Published at DZone with permission of Aderito Xavier. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Introduction To Git
  • Which Is Better for IoT: Azure RTOS or FreeRTOS?
  • What ChatGPT Needs Is Context
  • What Is JHipster?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: