How do I connect mathematical terminology (e.g., mapping, function, number, sequence, and set), to the implementation of Python programs that declare and call functions and declare and manipulate variables?
Let’s learn more about how the use of precise mathematical terms and concepts helps to effectively communicate and perform Python programming tasks! 🚀
# declare multiple variables
hello = "hello"
world = "world"
space = " "
value = .50
message = world + space + hello
print(f"The message is: {message}")
print(f"The value is: {value}")
Can you predict the output of this program?
What is the purpose of f"The message is: {message}"
?
mapper
with a Sequencedef square(value: int):
return value * value
def mapper(f, sequence):
result = ( )
for element in sequence:
result += ( f(element), )
return result
squared_range = mappper(square, range(10))
print(squared_range)
A monoid is an ordered pair (S,⊗) for a set S and any binary operator ⊗ that satisfies the following conditions:
Type Preservation: ∀s1,s2∈S, s1⊗s2∈S
Associative Property: ∀s1,s2,s3∈S, (s1⊗s2)⊗s3=s1⊗(s2⊗s3)
Identity Element: ∃ϵ∈S, such that ∀s∈S,ϵ⊗s=s and s⊗ϵ=s
We often say that S is a monoid under ⊗ with identity ϵ
If this is confusing, a monoid is a generalization of strings and integers!
If you know how strings behave in Python or Java then you understand the monoid — monoid describes string-like
structures!
O=((o1,…,on))
S=oi∈O∑oi
A=∣O∣S
What is the meaning of oi∈O?
Where does this exist in Python code?
Explore the use of the sum
function in Python!
O=((o1,…,on))
S=oi∈O∑oi
A=∣O∣S
What is the meaning of oi∈O?
Where does this exist in Python code?
Explore the use of the sum
function in Python!
Abstraction Jumping
What is the connection between the discrete mathematical structures and the Python programs?
Connections between discrete mathematics and Python
Generic file: a sequence of sequences
Names in the file: a set of strings
Emails in the file: a set of ordered pairs forming a relation
Temperatures in the file: a multiset of integers
When might the emails in the file be a mapping? When might the temperatures in the file be a sequence?
Item 1
Item 2
Item 3
Item 4
We often say that "S is a monoid under ⊗ with identity ϵ"