CS373 Fall 2021: Week 3

Ethan Tan
3 min readSep 12, 2021

Week 3

What did you do this past week?

There were assignments due for each of my classes, so I was very busy this week. I got started on the collatz assignment this weekend and managed to turn it in this morning.

What’s in your way?

There’s not too much in my way, besides more of the same business I have going on with my other classes.

What will you do next week?

Next week is a bit lighter in terms of workload, but I’ll need to get started on projects so that the following week is more manageable.

If you read it, what did you think of the Paper #3: Continuous Integration?

I’m pretty sure I read the same paper last semester, but reading it again was still very useful. Since I had some experience using a CI pipeline, much of the paper made more sense than when I read it the first time — it’s very clear what the benefits of CI are once you’ve started using it. My only problem with CI in this course is that the repository we are given seems not to be the best for this — the pipeline passes even if tests fail, which to me limits the usefulness of the pipeline. I ended up changing the makefile and CI script last semester and I plan on customizing it for our projects this semester as well, which I expect we’ll have to do regardless.

What was your experience of IsPrime and Collatz optimizations?

It was fun. It wasn’t new to me, since I took object-oriented programming last semester where we did the same thing, but since Python is a bit more flexible than C++, you can do some cool things with it.

As part of my experimentation, I played around with creating a callable class that cached any recursive function, expressed as an input to the fixpoint operator — meaning the function takes itself as an argument, and calls it to express recursion, and fix simply applies the function to itself. If instead of fix, we used some cached fix that passed a function that would cache values to the recursive function, we could add caching to any recursive function expressed this way. It was a fun idea and I’m happy I got it to work, although it was not practical for the assignment, since recursion isn’t well-suited for the problem and Python doesn’t do tail-call optimization.

I did end up using a callable class that would cache functions that accepted ranges though. I made it sufficiently generic that I could cache max_cycle_length in intervals of 10, and 100, and 1000, and so on, create functions that cached other functions by simply building an instance of the object. Doing this about 5 times gave me an ad-hoc segment tree that was definitely not necessary but also quite funny, because I ended up with a function called cached_cached_cached_cached_cached_mcl (which I unfortunately got rid of since I don’t need intermediate functions as globals).

What made you happy this week?

I got a lot of stuff done! It felt rather productive.

What’s your pick-of-the-week or tip-of-the-week?

Take advantage of documentation. I’m pretty new to python, so it was very useful to me to look up packages and use print(function.__doc__) in order to know how to use things properly and write code such that I understood what was happening. docs.python.org/3/ is very clear and informative.

--

--