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! π
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 Ο΅"