SICP
I decided to go back to my work on SICP. SICP is the book Structure and Interpretation of Computer Programs, which is here.
I had taken a detour from my SICP work to make another website on which to post my SICP answers. I ended up making a website with GitHub Pages, which until then had seemed too scary and complicated for me to try. I did successfully make that website and make some formatting modifications. It is here. I put answers to Exercises 2.40, 2.41 and 2.42 there.
Then I wanted to learn more about html and css and liquid in order to better understand how websites are made. I learned a little about those. But I’ve decided I’d rather be working on SICP for now, although I want to know more about those other things eventually.
My plan for SICP is to go back to the beginning and redo my earlier exercise answers in order to post them to my new website. I’m curious how much I’ll remember of what I did before and if I’ll understand some things better the second time around.
As before, my SICP work is mostly to understand the concepts they’re teaching in the book. But it’s also to practice putting things on a website and to practice writing clearly.
——
https://aelanteno.github.io/sicp-exercises/
In the tree diagram I posted on March 26, I added a connecting arrow from "attitude" to "SICP Project". I gained some confidence by successfully making these formatting changes that seemed too hard a few weeks ago. One of my goals with the Computers Project is to feel less intimidated by computers.
Credit
I want to change my procedure and its name in Exercise 1.3 to give credit to Firebench. How about something like “Thanks to Firebench for some readability suggestions.”? I can’t share a link to this thread because only members can see it.
Breaking down procedures
I don't like how some are bold and some aren't. And I don't like how similar the blue and the teal are.
The new colors look like this:
These colors fit in better with the other colors on the site.
I chose the black and the indigo, which are close to each other, for special forms and procedures that are already defined in scheme. Then the teal, which is sort of close to those, is for user-defined procedures. I'm not sure what to call the category that comes out orange, since it included both my variables and the already-defined "nil".
If you follow my link in the previous comment to Exercise 1.3, you can see that the syntax highlighting made the procedure names "min" and "max" indigo, even though they are not pre-defined in my version of Scheme. Maybe the parsing isn't perfect, maybe due to different versions of Scheme, or maybe there's something I'm not understanding.
(Note: I say "orange" because it looks orange to me on my screens, but it's actually called "coral".)
Comments welcome about colors and syntax highlighting.
I make these judgments intuitively. I guess my approach is along the lines of "if the code is hard to comprehend then refactor (e.g. extract methods) until it's easy to comprehend". That is, I can read it and "know" it's going to work. Sometimes extracting methods results in code that is harder to comprehend because there's more of it—more boilerplate, more named concepts to hold onto etc.
Other reasons to extract methods are to make it easier to test parts of the logic on their own, and to enable reuse. For example, the "min" and "max" procedures seem to me like they could be useful in many situations, whereas "second-largest-of-three-numbers" seems to be more narrowly reuseful.
The upshot is that with big numbers, the square of the best guess may not be within the required accuracy (0.001).
My guess is that the result of each arithmetic operation is rounded to a representable value. And when you string several arithmetic operations together, rounding errors will accumulate, thus reducing the chance that the final figure will match the radicand's representable value.
Are you able to single-step through the code during its execution to see what's happening?
Here are partial results for two very large numbers.
This one terminates and these are the last few entries:
This one gets stuck. These are the last few entries that change and the first few that don't change:
Well, I see why if the square of x is different from x, it'll always be further from it than 0.001. The computer doesn't go to that many decimal places with such large numbers. But I don't see why it doesn't round to x.
Maybe this is too hard for me to figure out now? I can leave it as an unanswered question for now.
Coupled with the fact that the multiplication operation for square rounds up, so 1e+25 squared doesn't produce 99999999999999999999999999999999999999999999999999, but 1.0000000000000003e+50, even though the former is representable and would be much closer to the right answer.
I started a document for myself of Unanswered Questions about SICP. I'm hoping this will help me keep track of them better.
I wondered what a tree for using this procedure would look like. I came up with a series of trees for the simple example of (A 2 2).
Any thoughts on other ways to represent this kind of thing?