Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from AlexeyShobanov/exercises
add exercises 3_5-3_8
- Loading branch information
Showing
12 changed files
with
397 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'Monte Carlo integration', | ||
'description1' => | ||
'Monte Carlo integration is a method of estimating definite integrals by means of Monte Carlo simulation. ' . | ||
'Consider computing the area of a region of space described by a predicate ', | ||
'description2' => | ||
' that is true for points ', | ||
'description3' => | ||
' in the region and false for points not in the region. For example, ' . | ||
'the region contained within a circle of radius ', | ||
'description4' => | ||
' centered at ', | ||
'description5' => | ||
' is described by the predicate that tests whether ', | ||
'description6' => | ||
'. To estimate the area of the region described by such a predicate, begin by choosing a rectangle that contains the region. ' . | ||
'For example, a rectangle with diagonally opposite corners at ', | ||
'description7' => | ||
' and ', | ||
'description8' => | ||
' contains the circle above. ' . | ||
'The desired integral is the area of that portion of the rectangle that lies in the region. ' . | ||
'We can estimate the integral by picking, at random, points ', | ||
'description9' => | ||
' that lie in the rectangle, and testing ', | ||
'description10' => | ||
' for each point to determine whether the point lies in the region. ' . | ||
'If we try this with many points, then the fraction of points that fall in the region should give an estimate of the proportion of the rectangle that lies in the region. ' . | ||
'Hence, multiplying this fraction by the area of the entire rectangle should produce an estimate of the integral.', | ||
'description11' => | ||
'Implement Monte Carlo integration as a procedure ', | ||
'description12' => | ||
' that takes as arguments a predicate ', | ||
'description13' => | ||
', upper and lower bounds ', | ||
'description14' => | ||
' and ', | ||
'description15' => | ||
' for the rectangle, and the number of trials to perform in order to produce the estimate. ' . | ||
'Your procedure should use the same ', | ||
'description16' => | ||
' procedure that was used above to estimate ', | ||
'description17' => | ||
'. Use your ', | ||
'description18' => | ||
' to produce an estimate of ', | ||
'description19' => | ||
' by measuring the area of a unit circle.', | ||
'description20' => | ||
'You will find it useful to have a procedure that returns a number chosen at random from a given range. ' . | ||
'The following ', | ||
'description21' => | ||
'procedure implements this in terms of the ', | ||
'description22' => | ||
' procedure used in section ', | ||
'description23' => | ||
', which returns a nonnegative number less than its input.' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'Advanced random number generator', | ||
'description1' => | ||
'It is useful to be able to reset a random-number generator to produce a sequence starting from a given value. ' . | ||
'Design a new ', | ||
'description2' => | ||
' procedure that is called with an argument that is either the symbol ', | ||
'description3' => | ||
' or the symbol ', | ||
'description4' => | ||
' and behaves as follows: ', | ||
'description5' => | ||
' produces a new random number; ', | ||
'description6' => | ||
' resets the internal state variable to the designated ', | ||
'description7' => | ||
'. Thus, by resetting the state, one can generate repeatable sequences. ' . | ||
'These are very handy to have when testing and debugging programs that use random numbers.', | ||
'description8' => | ||
'new-value' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'Joint accounts', | ||
'description1' => | ||
'Consider the bank account objects created by ', | ||
'description2' => | ||
', with the password modification described in exercise ', | ||
'description3' => | ||
'. Suppose that our banking system requires the ability to make joint accounts. Define a procedure ', | ||
'description4' => | ||
' that accomplishes this. ', | ||
'description5' => | ||
' should take three arguments. The first is a password-protected account. ' . | ||
'The second argument must match the password with which the account was defined in order for the ', | ||
'description6' => | ||
' operation to proceed. The third argument is a new password. ', | ||
'description7' => | ||
' is to create an additional access to the original account using the new password. For example, if ', | ||
'description8' => | ||
' is a bank account with password ', | ||
'description9' => | ||
', then', | ||
'description10' => | ||
'will allow one to make transactions on ', | ||
'description11' => | ||
' using the name ', | ||
'description12' => | ||
' and the password ', | ||
'description13' => | ||
'. You may wish to modify your solution to exercise ', | ||
'description14' => | ||
' to accommodate this new feature.' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'Order for evaluating subexpressions', | ||
'description1' => | ||
'When we defined the evaluation model in section ', | ||
'description2' => | ||
', we said that the first step in evaluating an expression is to evaluate its subexpressions. ' . | ||
'But we never specified the order in which the subexpressions should be evaluated ' . | ||
'(e.g., left to right or right to left). When we introduce assignment, ' . | ||
'the order in which the arguments to a procedure are evaluated can make a difference to the result. ' . | ||
'Define a simple procedure ', | ||
'description3' => | ||
' such that evaluating ', | ||
'description4' => | ||
' will return ', | ||
'description5' => | ||
' if the arguments to ', | ||
'description6' => | ||
' are evaluated from left to right but will return ', | ||
'description7' => | ||
' if the arguments are evaluated from right to left.' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'Интегрирование методом Монте-Карло', | ||
'description1' => | ||
'Интегрирование методом Монте-Карло (Monte Carlo integration) — ' . | ||
'способ приближенного вычисления определенных интегралов при помощи моделирования методом Монте-Карло. ' . | ||
'Рассмотрим задачу вычисления площади фигуры, описываемой предикатом ', | ||
'description2' => | ||
', который истинен для точек ', | ||
'description3' => | ||
', принадлежащих фигуре, и ложен для точек вне фигуры. ' . | ||
'Например, область, содержащаяся в круге с радиусом ', | ||
'description4' => | ||
' и центром в точке ', | ||
'description5' => | ||
', описывается предикатом, проверяющим ', | ||
'description6' => | ||
'. Чтобы оценить площадь фигуры, описываемой таким предикатом, для начала выберем прямоугольник, ' . | ||
'который содержит нашу фигуру. Например, прямоугольник с углами ', | ||
'description7' => | ||
' и ', | ||
'description8' => | ||
', расположенными по диагонали, содержит вышеописанный круг. ' . | ||
'Нужный нам интеграл — площадь той части прямоугольника, которая лежит внутри фигуры. ' . | ||
'Мы можем оценить интеграл, случайным образом выбирая точки ', | ||
'description9' => | ||
', лежащие внутри прямоугольника, и проверяя для каждой точки ', | ||
'description10' => | ||
', чтобы определить, лежит ли точка внутри фигуры. ' . | ||
'Если мы проверим много точек, доля тех, которые окажутся внутри области, даст нам приближенное значение отношения площадей фигуры и прямоугольника. ' . | ||
'Таким образом, домножив это значение на площадь прямоугольника, мы получим приближенное значение интеграла.', | ||
'description11' => | ||
'Реализуйте интегрирование методом Монте-Карло в виде процедуры ', | ||
'description12' => | ||
', которая в качестве аргументов принимает предикат ', | ||
'description13' => | ||
', верхнюю и нижнюю границы прямоугольника ', | ||
'description14' => | ||
' и ', | ||
'description15' => | ||
', а также число проверок, которые мы должны осуществить, чтобы оценить отношение площадей. ' . | ||
'Ваша процедура должна использовать ту же самую процедуру ', | ||
'description16' => | ||
', которая выше использовалась для оценки значения ', | ||
'description17' => | ||
'. Оцените ', | ||
'description18' => | ||
' при помощи ', | ||
'description19' => | ||
' измерив площадь единичного круга.', | ||
'description20' => | ||
'Вам может пригодиться процедура, которая выдает число, случайно выбранное внутри данного отрезка. ' . | ||
'Нижеприведенная процедура ', | ||
'description21' => | ||
' решает эту задачу, используя процедуру ', | ||
'description22' => | ||
', введенную в разделе ', | ||
'description23' => | ||
', которая возвращает неотрицательное число меньше своего аргумента.' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'Усовершенствованный генератор случайных чисел', | ||
'description1' => | ||
'Полезно иметь возможность сбросить генератор случайных чисел, чтобы получить последовательность, которая начинается с некоторого числа. ' . | ||
'Постройте новую процедуру ', | ||
'description2' => | ||
', которая вызывается с аргументом. Этот аргумент должен быть либо символом ', | ||
'description3' => | ||
', либо символом ', | ||
'description4' => | ||
'. Процедура работает так: ', | ||
'description5' => | ||
' порождает новое случайное число; ', | ||
'description6' => | ||
' сбрасывает внутреннюю переменную состояния в указанное ', | ||
'description7' => | ||
'. Таким образом, сбрасывая значения, можно получать повторяющиеся последовательности. ' . | ||
'Эта возможность очень полезна при тестировании и отладке программ, использующих случайные числа.', | ||
'description8' => | ||
'новое-значение' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'Совместные счета', | ||
'description1' => | ||
'Рассмотрим объекты-банковские счета, создаваемые процедурой ', | ||
'description2' => | ||
', и снабженные паролями, как это описано в упражнении ', | ||
'description3' => | ||
'. Предположим, что наша банковская система требует от нас умения порождать совместные счета. ' . | ||
'Напишите процедуру ', | ||
'description4' => | ||
', которая это делает. ', | ||
'description5' => | ||
' должна принимать три аргумента. Первый из них — защищенный паролем счет. ' . | ||
'Второй обязан совпадать с паролем, с которым этот счет был создан, иначе', | ||
'description6' => | ||
'откажется работать. ' . | ||
' Третий аргумент — новый пароль. ', | ||
'description7' => | ||
' открывает дополнительный доступ к счету, с использованием нового пароля. Например, если банковский счет ', | ||
'description8' => | ||
' был создан с паролем ', | ||
'description9' => | ||
', то', | ||
'description10' => | ||
'позволит нам проводить операции с ', | ||
'description11' => | ||
', используя имя ', | ||
'description12' => | ||
' и пароль ', | ||
'description13' => | ||
'. Вам может потребоваться переработать решение упражнения ', | ||
'description14' => | ||
', чтобы добавить эту новую возможность.' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
return [ | ||
'title' => 'Порядок вычисления подвыражений', | ||
'description1' => | ||
'Когда в разделе ', | ||
'description2' => | ||
' мы определяли модель вычислений, мы сказали, что первым шагом при вычислении выражения является вычисление его подвыражений. ' . | ||
'Однако мы нигде не указали порядок, в котором проходит вычисление подвыражений (слева направо или справа налево). ' . | ||
'Когда мы вводим присваивание, порядок, в котором вычисляются аргументы процедуры, может повлиять на результат. ' . | ||
'Определите простую процедуру ', | ||
'description3' => | ||
', так, чтобы вычисление ', | ||
'description4' => | ||
' возвращало ', | ||
'description5' => | ||
', если аргументы ', | ||
'description6' => | ||
' вычисляются слева направо, и ', | ||
'description7' => | ||
', если они вычисляются справа налево.' | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<p> | ||
{{ __('exercises/3_5.description1') }} | ||
<code>P(x, y)</code> | ||
{{ __('exercises/3_5.description2') }} | ||
<code>(x, y)</code> | ||
{{ __('exercises/3_5.description3') }} | ||
<code>3</code> | ||
{{ __('exercises/3_5.description4') }} | ||
<code>(5, 7)</code> | ||
{{ __('exercises/3_5.description5') }} | ||
<code>(x - 5)² + (y - 7)² ≤ 3²</code> | ||
{{ __('exercises/3_5.description6') }} | ||
<code>(2, 4)</code> | ||
{{ __('exercises/3_5.description7') }} | ||
<code>(8, 10)</code> | ||
{{ __('exercises/3_5.description8') }} | ||
<code>(x,y)</code> | ||
{{ __('exercises/3_5.description9') }} | ||
<code>P(x, y)</code> | ||
{{ __('exercises/3_5.description10') }} | ||
</p> | ||
<p> | ||
{{ __('exercises/3_5.description11') }} | ||
<code>estimate-integral</code> | ||
{{ __('exercises/3_5.description12') }} | ||
<code>P</code> | ||
{{ __('exercises/3_5.description13') }} | ||
<code>x1, x2, y1</code> | ||
{{ __('exercises/3_5.description14') }} | ||
<code>y2</code> | ||
{{ __('exercises/3_5.description15') }} | ||
<code>monte-carlo</code> | ||
{{ __('exercises/3_5.description16') }} | ||
<code>π</code> | ||
{{ __('exercises/3_5.description17') }} | ||
<code>estimate-integral</code> | ||
{{ __('exercises/3_5.description18') }} | ||
<code>π</code> | ||
{{ __('exercises/3_5.description19') }} | ||
</p> | ||
<p> | ||
{{ __('exercises/3_5.description20') }} | ||
<code>random-in-range</code> | ||
{{ __('exercises/3_5.description21') }} | ||
<code>random</code> | ||
{{ __('exercises/3_5.description22') }} | ||
<a href="https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-11.html#%_sec_1.2.6">1.2.6</a> | ||
{{ __('exercises/3_5.description23') }} | ||
</p> | ||
<pre><code>(define (random-in-range low high) | ||
(let ((range (- high low))) | ||
(+ low (random range))))</code></pre> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<p> | ||
{{ __('exercises/3_6.description1') }} | ||
<code>rand</code> | ||
{{ __('exercises/3_6.description2') }} | ||
<code>generate</code> | ||
{{ __('exercises/3_6.description3') }} | ||
<code>reset</code> | ||
{{ __('exercises/3_6.description4') }} | ||
<code>(rand 'generate)</code> | ||
{{ __('exercises/3_6.description5') }} | ||
<code>((rand 'reset) <{{ __('exercises/3_6.description8') }}>)</code> | ||
{{ __('exercises/3_6.description6') }} | ||
<code><{{ __('exercises/3_6.description8') }}></code> | ||
{{ __('exercises/3_6.description7') }} | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<p> | ||
{{ __('exercises/3_7.description1') }} | ||
<code>make-account</code> | ||
{{ __('exercises/3_7.description2') }} | ||
<a title="3.3" href="{{ route('exercises.show', ($exercise->id - 4)) }}">3.3</a> | ||
{{ __('exercises/3_7.description3') }} | ||
<code>make-joint</code> | ||
{{ __('exercises/3_7.description4') }} | ||
<code>Make-joint</code> | ||
{{ __('exercises/3_7.description5') }} | ||
<code>make-joint</code> | ||
{{ __('exercises/3_7.description6') }} | ||
<code>Make-joint</code> | ||
{{ __('exercises/3_7.description7') }} | ||
<code>peter-acc</code> | ||
{{ __('exercises/3_7.description8') }} | ||
<code>open-sesame</code> | ||
{{ __('exercises/3_7.description9') }} | ||
</p> | ||
<pre><code>(define paul-acc | ||
(make-joint peter-acc 'open-sesame 'rosebud))</code></pre> | ||
<p> | ||
{{ __('exercises/3_7.description10') }} | ||
<code>peter-acc</code> | ||
{{ __('exercises/3_7.description11') }} | ||
<code>paul-acc</code> | ||
{{ __('exercises/3_7.description12') }} | ||
<code>rosebud</code> | ||
{{ __('exercises/3_7.description13') }} | ||
<a title="3.3" href="{{ route('exercises.show', ($exercise->id - 4)) }}">3.3</a> | ||
{{ __('exercises/3_7.description14') }} | ||
</p> |
Oops, something went wrong.