Consider the following Source program:
Use the substitution model on runes demonstrated during Lecture L2 in order to manually evaluate the expression f1(square, 3, heart)
. The evaluation proceeds as demonstrated in L2. For the primitive rune square
, you should draw a solid box ⬛ and for the primitive rune blank
, you should draw an empty box ⬜.
Of course as the computation proceeds according to the substitution model, the pictures within your expressions will become more complex. Try to get the proportions right and draw the pictures as large as necessary.
Consider the following Source program:
Use the substitution model on runes demonstrated during Lecture L2 in order to manually evaluate the expression f2(heart, 3)
. The evaluation proceeds as demonstrated in L2. For the primitive rune square
, you should draw a solid box ⬛ and for the primitive rune blank
, you should draw an empty box ⬜.
Of course as the computation proceeds according to the substitution model, the pictures within your expressions will become more complex. Try to get the proportions right and draw the pictures as large as necessary.
The goal of this in-class exercise is to write a function moony
that takes a parameter n
and produces a rune with n
circles on the steps of a staircase.
Begin by writing a function moony_1
that takes an argument bottom_right
and produces a rune as shown in this picture.
The picture is the result of show(moony_1(ribbon))
.
Now that we have one circle, we need to produce n − 1
more. Use recursion in a function moony_2
to insert n − 1
other circles in the approximately correct location.
The picture is the result of show(moony_2(5))
.
Use the available primitive combinations on runes to even out the rows and columns, one axis at a time. You may call your final version moony
.
The picture on the left show the result of evening out the rows but not yet the columns, and the picture on the right shows the result of show(moony(5))
.
Can you explain how your moony manages to even out both rows and columns?
Do your solutions give rise to recursive or iterative processes?
Characterize the resource consumption of your function moony
using the orders of growth notation introduced in Brief B2.
In your description, be clear about what you consider the "size" of the given problem.
What assumptions are you making on the resource consumption of primitive runes and of primitive operations on runes? To answer this question, review question "Do all primitive operations considered to take the same time?" in the recording of Brief B2 (1:14:22).
Consider the following function:
Does power give rise to an iterative or recursive process?
Use the notation to characterize the time and space consumption of expt
as the argument n
grows.
Use the notation to characterize the time and space consumption of expt as the argument b
grows.
Consider the following relationship
fast_expt
which computes for any natural number in time