• 2 Posts
  • 345 Comments
Joined 1 year ago
cake
Cake day: July 2nd, 2023

help-circle


  • affiliate@lemmy.worldto196@lemmy.blahaj.zoneRule
    link
    fedilink
    arrow-up
    23
    arrow-down
    1
    ·
    4 days ago

    a wise programmer knows to always ask the question “can i solve this problem in python using metaprogramming?” in this instance, the answer is yes:

    def is_even(n: int):
        s = "def is_even_helper(number: int):\n"
        b = True
        for i in range(0, abs(n)+2):
            s += f"\tif (abs(number) == {i}): return {b}\n"
            b = not b
        exec(s)
        return locals().get("is_even_helper")(n)
    





  • whether or not i is a scalar depends entirely on the context.

    every vector space has an associated field of coefficients. in practice, this field is typically the real numbers. but you can have lots of other kinds of vector spaces as well, and they can be useful for certain things.

    anyways, if you have a vector space over the complex numbers, then i is a scalar, because it is a complex number. if you have a vector space over the real numbers, then i is not a scalar, because it’s not a real number.

    its worth mentioning that you can view the complex numbers as a vector space over itself. this is just a fancy way of saying that you can add complex numbers together, and you can multiply a complex number by a complex number. (one of those numbers is playing the role of scalar, and the other is playing the role of vector.) but you can also view the complex numbers as a vector space over the real numbers. and this is just a fancy way of saying that you can add complex numbers, and you can multiply a complex number by a real number.