• 21 Posts
  • 9 Comments
Joined 1 year ago
cake
Cake day: June 11th, 2023

help-circle


  • You can always combine integer operations in smaller chunks to simulate something that’s too big to fit in a register. Python even does this transparently for you, so your integers can be as big as you want.

    The fundamental problem that led to requiring 64-bit was when we needed to start addressing more than 4 GB of RAM. It’s kind of similar to the problem of the Internet, where 4 billion unique IP addresses falls rather short of what we need. IPv6 has a host of improvements, but the massively improved address space is what gets talked about the most since that’s what is desperately needed.

    Going back to RAM though, it’s sort of interesting that at the lowest levels of accessing memory, it is done in chunks that are larger than 8 bits, and that’s been the case for a long time now. CPUs have to provide the illusion that an 8-bit byte is the smallest addressible unit of memory since software would break badly were this not the case, but it’s somewhat amusing to me that we still shouldn’t really need more than 32 bits to address RAM at the lowest levels even with the 16 GB I have in my laptop right now. I’ve worked with 32-bit microcontrollers where the byte size is > 8 bits, and yeah, you can have plenty of addressible memory in there if you wanted.





  • Can you use it to initialize vars outside the scope of the lambda?

    No, that’s not what it’s for. It lets you define a temporary local variable within an expression. This is useful in situations where you might want to use the same value more than once within the expression. In a regular function, you would just define a variable first and then use it as many times as you want. But until the walrus operator came along, you couldn’t define a variable within a lambda expression.

    Can you give an example?

    Ok, I’m trying to think of a simple example. Let’s say you had a database that maps student IDs to records contain their names. To keep things simple, I’ll just make it plain old dict. And then you have a list of student IDs. You want to sort these IDs using the student names in the form “last, first” as the key. So you could go:

    >>> student_recs = {1261456: {"first": "Harry", "last": "Potter"}, 532153: {"first": "Ron", "last": "Weasley"}, 632453: {"first": "Hermione", "last": "Granger"}}
    >>> student_ids = [1261456, 532153, 632453]
    >>> sorted(student_ids, key = lambda i: (rec := student_recs[i])['last'] + ', ' +  rec['first'])
    [632453, 1261456, 532153]
    

    The problem here is that student_ids doesn’t contain the student names. You need use the ID to look up the record that contains those. So let’s say the first ID i is 1261456. That would mean:

    rec := student_recs[i]
    

    evaluates to:

    {"first": "Harry", "last": "Potter"}
    

    Then we are effectively going:

     rec['last'] + ', ' + rec['first']
    

    which should give us:

     'Potter, Harry'
    

    Without the := you would either have to perform 2 student_recs[i] look-ups to get each name which would be wasteful or replace the lambda with a regular function where you can write rec = student_recs[i] on its own line and then use it.

    Am I making any sense?





  • While it would probably be a good idea to look at their sources more carefully, this is the kind of analysis I’d like to see more of.

    It’s true that with almost every type of emissions reduction, there is a point of diminishing returns where it becomes prohibitive to address those last few percent. From a policymaker’s standpoint, they have to decide how much society is willing to pay and then attempt to optimize the allocation of resources within that framework. That’s where you get your cap-and-trade and so forth.

    This article suggests the lower up-front cost of renewables like wind and solar show a windfall up to 57%, but are still cost-competitive even up to 90%. This is encouraging. They mention the remaining 10% includes hard-to-decarbonize sectors like aviation. I think even in general electrical production though, there are diminishing returns.

    If you consider that to overcome the challenge of variability in supply with wind and solar, you need to invest in grid storage, there is the question of just how much storage you need? A day’s worth? A week’s worth? A month’s worth? The more storage you have, the more edge cases you will cover, but your costs go up exponentially and may never reach 100%. If you reach say 99%, that’s still around 3 days out of the year when you have to fire up some backup generators. Is that an acceptable compromise?


  • I was astonished by the Great Green Wall Initiative in Africa. The plan is to create a continent-spanning wall of vegetation to prevent the Sahara Desert from expanding southward. It is nothing if not ambitious.

    Apparently, the first phase is to create huge number of these tiny plots shaped in a special way to prevent rainwater from running off and planting drought-hardy native species in them, some of which can be harvested as a food source. Eventually, once the soil has recovered sufficiently, they can plant trees.

    The initiative is high-tech in the sense of applying state-of-the-art knowledge on land management but low-tech in the sense that it will involve a whole lot of manual labour with simple implements.

    But the scope of it is insane with 22 countries having signed on. It gives me hope that collective action in the face of climate change is possible anywhere in the world.