main
Jurij Podgoršek 2024-06-12 19:35:40 +02:00
parent b66834ae2b
commit 90ce6643b1
1 changed files with 230 additions and 52 deletions

View File

@ -3,7 +3,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2024-05-29 sre 21:56 -->
<!-- 2024-06-12 sre 19:35 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Zapiski #3 srečanja programerskega bralnega krožka SICP</title>
@ -198,51 +198,51 @@
<div id="content" class="content">
<h1 class="title">Zapiski #3 srečanja programerskega bralnega krožka SICP</h1>
<div id="outline-container-org3870a64" class="outline-2">
<h2 id="org3870a64">Teme</h2>
<div class="outline-text-2" id="text-org3870a64">
<div id="outline-container-org5e882c4" class="outline-2">
<h2 id="org5e882c4">Teme</h2>
<div class="outline-text-2" id="text-org5e882c4">
</div>
<div id="outline-container-orga631c9e" class="outline-3">
<h3 id="orga631c9e">Funkcije višjega reda</h3>
<div id="outline-container-orgdaeae88" class="outline-3">
<h3 id="orgdaeae88">Funkcije višjega reda</h3>
</div>
</div>
<div id="outline-container-org9304723" class="outline-2">
<h2 id="org9304723">Vaje</h2>
<div class="outline-text-2" id="text-org9304723">
<div id="outline-container-org401da87" class="outline-2">
<h2 id="org401da87">Vaje</h2>
<div class="outline-text-2" id="text-org401da87">
</div>
<div id="outline-container-org5904c5a" class="outline-3">
<h3 id="org5904c5a">1.29 Simpsonovo pravilo</h3>
<div class="outline-text-3" id="text-org5904c5a">
<div id="outline-container-org91ad66e" class="outline-3">
<h3 id="org91ad66e">1.29 Simpsonovo pravilo</h3>
<div class="outline-text-3" id="text-org91ad66e">
<div class="org-src-container">
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #9d0006;">define</span><span style="color: #b16286;">(</span><span style="color: #b57614;">cube</span> x<span style="color: #b16286;">)</span>
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #fb4933;">define</span><span style="color: #b16286;">(</span><span style="color: #fabd2f;">cube</span> x<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>* x x x<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #9d0006;">define</span><span style="color: #b16286;">(</span><span style="color: #b57614;">sum-integers</span> a b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #9d0006;">if</span> <span style="color: #8ec07c;">(</span> &gt; a b<span style="color: #8ec07c;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span><span style="color: #b16286;">(</span><span style="color: #fabd2f;">sum-integers</span> a b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">if</span> <span style="color: #8ec07c;">(</span> &gt; a b<span style="color: #8ec07c;">)</span>
0
<span style="color: #8ec07c;">(</span>+ a <span style="color: #d65d0e;">(</span>sum-integers <span style="color: #458588;">(</span>+ a 1<span style="color: #458588;">)</span> b<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #9d0006;">define</span><span style="color: #b16286;">(</span><span style="color: #b57614;">sum-cubes</span> a b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #9d0006;">if</span> <span style="color: #8ec07c;">(</span>&gt; a b<span style="color: #8ec07c;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span><span style="color: #b16286;">(</span><span style="color: #fabd2f;">sum-cubes</span> a b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">if</span> <span style="color: #8ec07c;">(</span>&gt; a b<span style="color: #8ec07c;">)</span>
0
<span style="color: #8ec07c;">(</span>+ <span style="color: #d65d0e;">(</span>cube a<span style="color: #d65d0e;">)</span> <span style="color: #d65d0e;">(</span>sum-cubes<span style="color: #458588;">(</span>+ a 1<span style="color: #458588;">)</span> b<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b16286;">(</span><span style="color: #b57614;">sum</span> term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #9d0006;">if</span> <span style="color: #8ec07c;">(</span>&gt; a b<span style="color: #8ec07c;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">sum</span> term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">if</span> <span style="color: #8ec07c;">(</span>&gt; a b<span style="color: #8ec07c;">)</span>
0
<span style="color: #8ec07c;">(</span>+ <span style="color: #d65d0e;">(</span>term a<span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>sum term <span style="color: #458588;">(</span>next a<span style="color: #458588;">)</span> next b<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b16286;">(</span><span style="color: #b57614;">integral</span> f a b dx<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #9d0006;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #b57614;">add-dx</span> x<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span>+ x dx<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">integral</span> f a b dx<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #fabd2f;">add-dx</span> x<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span>+ x dx<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>* <span style="color: #8ec07c;">(</span>sum f <span style="color: #d65d0e;">(</span>+ a <span style="color: #458588;">(</span>/ dx 2.0<span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span> add-dx b<span style="color: #8ec07c;">)</span>
dx<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b16286;">(</span><span style="color: #b57614;">simpson</span> f a b n<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b57614;">h</span> <span style="color: #8ec07c;">(</span>/ <span style="color: #d65d0e;">(</span>- b a<span style="color: #d65d0e;">)</span> n<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #9d0006;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #b57614;">add-hh</span> a<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span>+ a h h<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">simpson</span> f a b n<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">h</span> <span style="color: #8ec07c;">(</span>/ <span style="color: #d65d0e;">(</span>- b a<span style="color: #d65d0e;">)</span> n<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #fabd2f;">add-hh</span> a<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span>+ a h h<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>* <span style="color: #8ec07c;">(</span>+ <span style="color: #d65d0e;">(</span>- <span style="color: #458588;">(</span>f a<span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>* 2 <span style="color: #458588;">(</span>sum f a add-hh b<span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>* 4 <span style="color: #458588;">(</span>sum f <span style="color: #b16286;">(</span>+ a h<span style="color: #b16286;">)</span> add-hh b<span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span>
@ -273,23 +273,23 @@
</div>
</div>
<div id="outline-container-org55533ea" class="outline-3">
<h3 id="org55533ea">1.30 linearen sum</h3>
<div class="outline-text-3" id="text-org55533ea">
<div id="outline-container-org710ddb9" class="outline-3">
<h3 id="org710ddb9">1.30 linearen sum</h3>
<div class="outline-text-3" id="text-org710ddb9">
<p>
Rekurzivne procedure:
</p>
<div class="org-src-container">
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b16286;">(</span><span style="color: #b57614;">sum</span> term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #9d0006;">if</span> <span style="color: #8ec07c;">(</span>&gt; a b<span style="color: #8ec07c;">)</span>
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">sum</span> term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">if</span> <span style="color: #8ec07c;">(</span>&gt; a b<span style="color: #8ec07c;">)</span>
0
<span style="color: #8ec07c;">(</span>+ <span style="color: #d65d0e;">(</span>term a<span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>sum term <span style="color: #458588;">(</span>next a<span style="color: #458588;">)</span> next b<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b16286;">(</span><span style="color: #b57614;">cube</span> n<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* n n n<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b16286;">(</span><span style="color: #b57614;">inc</span> n<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>+ n 1<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">cube</span> n<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* n n n<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">inc</span> n<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>+ n 1<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b16286;">(</span><span style="color: #b57614;">sum-cubes</span> a b<span style="color: #b16286;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">sum-cubes</span> a b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>sum cube a inc b<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span>sum-cubes 1 10<span style="color: #458588;">)</span>
@ -305,17 +305,17 @@ Rekurzivne procedure:
Iterativne procedure:
</p>
<div class="org-src-container">
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b16286;">(</span><span style="color: #b57614;">sum-iter</span> term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #9d0006;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #b57614;">iter</span> a result<span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span><span style="color: #9d0006;">if</span> <span style="color: #d65d0e;">(</span>&gt; a b<span style="color: #d65d0e;">)</span>
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">sum-iter</span> term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #fabd2f;">iter</span> a result<span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span><span style="color: #fb4933;">if</span> <span style="color: #d65d0e;">(</span>&gt; a b<span style="color: #d65d0e;">)</span>
result
<span style="color: #d65d0e;">(</span>iter <span style="color: #458588;">(</span>next a<span style="color: #458588;">)</span> <span style="color: #458588;">(</span>+ result <span style="color: #b16286;">(</span>term a<span style="color: #b16286;">)</span><span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>iter a 0<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b16286;">(</span><span style="color: #b57614;">cube</span> n<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* n n n<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b16286;">(</span><span style="color: #b57614;">inc</span> n<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>+ n 1<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">cube</span> n<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* n n n<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">inc</span> n<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>+ n 1<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b16286;">(</span><span style="color: #b57614;">sum-cubes-iter</span> a b<span style="color: #b16286;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">sum-cubes-iter</span> a b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>sum-iter cube a inc b<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span>sum-cubes-iter 1 10<span style="color: #458588;">)</span>
@ -328,39 +328,217 @@ Iterativne procedure:
</div>
</div>
<div id="outline-container-orgf8c5fef" class="outline-3">
<h3 id="orgf8c5fef">1.31 Produkt višjega reda</h3>
<div class="outline-text-3" id="text-orgf8c5fef">
<div id="outline-container-org7e0d0cf" class="outline-3">
<h3 id="org7e0d0cf">1.31 Produkt višjega reda</h3>
<div class="outline-text-3" id="text-org7e0d0cf">
<div class="org-src-container">
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b16286;">(</span><span style="color: #b57614;">prod-iter</span> term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #9d0006;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #b57614;">iter</span> a result<span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span><span style="color: #9d0006;">if</span> <span style="color: #d65d0e;">(</span>&gt; a b<span style="color: #d65d0e;">)</span>
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">prod-iter</span> term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #fabd2f;">iter</span> a result<span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span><span style="color: #fb4933;">if</span> <span style="color: #d65d0e;">(</span>&gt; a b<span style="color: #d65d0e;">)</span>
result
<span style="color: #d65d0e;">(</span>iter <span style="color: #458588;">(</span>next a<span style="color: #458588;">)</span> <span style="color: #458588;">(</span>* result <span style="color: #b16286;">(</span>term a<span style="color: #b16286;">)</span><span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>iter a 0<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #b16286;">(</span>iter a 1<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #9d0006;">define</span> <span style="color: #b16286;">(</span><span style="color: #b57614;">piblizek</span> n<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #9d0006;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #b57614;">stevec</span> n<span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span>+ n 2<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>* 4 <span style="color: #8ec07c;">(</span>/ <span style="color: #d65d0e;">(</span>prod-iter <span style="color: #458588;">(</span><span style="color: #9d0006;">lambda</span> <span style="color: #b16286;">(</span>n<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* <span style="color: #8ec07c;">(</span>- n 1<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span>+ n 1<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">piblizek</span> n<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #fabd2f;">stevec</span> m<span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span>+ m 2<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>* 4 <span style="color: #8ec07c;">(</span>/ <span style="color: #d65d0e;">(</span>prod-iter <span style="color: #458588;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #b16286;">(</span>a<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* <span style="color: #8ec07c;">(</span>- a 1<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span>+ a 1<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
3
stevec
n<span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>prod-iter <span style="color: #458588;">(</span><span style="color: #9d0006;">lambda</span> <span style="color: #b16286;">(</span>n<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* n n<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #d65d0e;">(</span>prod-iter <span style="color: #458588;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #b16286;">(</span>b<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* b b<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
3
stevec
n<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span>piblizek 10<span style="color: #458588;">)</span>
<span style="color: #458588;">(</span>+ <span style="color: #b16286;">(</span>piblizek 10000<span style="color: #b16286;">)</span> 0.0<span style="color: #458588;">)</span>
</pre>
</div>
<pre class="example">
3.1417497371492673
</pre>
</div>
</div>
<div id="outline-container-orgd135cab" class="outline-3">
<h3 id="orgd135cab">1.32 Akumulator (reduce funkcija)</h3>
<div class="outline-text-3" id="text-orgd135cab">
<div class="org-src-container">
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">accumulate</span> combiner null-value term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">if</span> <span style="color: #8ec07c;">(</span>&gt; a b<span style="color: #8ec07c;">)</span>
null-value
<span style="color: #8ec07c;">(</span>combiner <span style="color: #d65d0e;">(</span>term a<span style="color: #d65d0e;">)</span> <span style="color: #d65d0e;">(</span>accumulate combiner null-value term <span style="color: #458588;">(</span>next a<span style="color: #458588;">)</span> next b<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">sum</span> term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>accumulate + 0 term a next b<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">cube</span> n<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* n n n<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">sum-cubes</span> a b<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>sum cube a <span style="color: #8ec07c;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #d65d0e;">(</span>n<span style="color: #d65d0e;">)</span> <span style="color: #d65d0e;">(</span>+ n 1<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span> b<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">prod</span> term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>accumulate * 1 term a next b<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">piblizek</span> n<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #fabd2f;">stevec</span> m<span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span>+ m 2<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>* 4 <span style="color: #8ec07c;">(</span>/ <span style="color: #d65d0e;">(</span>prod <span style="color: #458588;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #b16286;">(</span>a<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* <span style="color: #8ec07c;">(</span>- a 1<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span>+ a 1<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
3
stevec
n<span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>prod <span style="color: #458588;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #b16286;">(</span>b<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* b b<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
3
stevec
n<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span>list <span style="color: #b16286;">(</span>sum-cubes 1 10<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>+ <span style="color: #8ec07c;">(</span>piblizek 10000<span style="color: #8ec07c;">)</span> 0.0<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
</pre>
</div>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-right" />
<col class="org-right" />
</colgroup>
<tbody>
<tr>
<td class="org-right">3025</td>
<td class="org-right">3.1417497371492673</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-orgacc9e22" class="outline-3">
<h3 id="orgacc9e22">1.32b Akumulator iterativno (reduce funkcija)</h3>
<div class="outline-text-3" id="text-orgacc9e22">
<div class="org-src-container">
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">accumulate-iter</span> combiner null-value term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #fabd2f;">combine</span> a combination<span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span><span style="color: #fb4933;">if</span> <span style="color: #d65d0e;">(</span>&gt; a b<span style="color: #d65d0e;">)</span>
combination
<span style="color: #d65d0e;">(</span>combine <span style="color: #458588;">(</span>next a<span style="color: #458588;">)</span> <span style="color: #458588;">(</span>combiner combination <span style="color: #b16286;">(</span>term a<span style="color: #b16286;">)</span><span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>combine a null-value<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">sum</span> term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>accumulate-iter + 0 term a next b<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">cube</span> n<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* n n n<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">sum-cubes</span> a b<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>sum cube a <span style="color: #8ec07c;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #d65d0e;">(</span>n<span style="color: #d65d0e;">)</span> <span style="color: #d65d0e;">(</span>+ n 1<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span> b<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">prod</span> term a next b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>accumulate-iter * 1 term a next b<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">piblizek</span> n<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #fabd2f;">stevec</span> m<span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span>+ m 2<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>* 4 <span style="color: #8ec07c;">(</span>/ <span style="color: #d65d0e;">(</span>prod <span style="color: #458588;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #b16286;">(</span>a<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* <span style="color: #8ec07c;">(</span>- a 1<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span>+ a 1<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
3
stevec
n<span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>prod <span style="color: #458588;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #b16286;">(</span>b<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>* b b<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
3
stevec
n<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span>list <span style="color: #b16286;">(</span>sum-cubes 1 10<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>+ <span style="color: #8ec07c;">(</span>piblizek 10000<span style="color: #8ec07c;">)</span> 0.0<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
</pre>
</div>
<table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-right" />
<col class="org-right" />
</colgroup>
<tbody>
<tr>
<td class="org-right">3025</td>
<td class="org-right">3.1417497371492673</td>
</tr>
</tbody>
</table>
</div>
</div>
<div id="outline-container-org8780c88" class="outline-3">
<h3 id="org8780c88">1.33 filtriran akumulator</h3>
<div class="outline-text-3" id="text-org8780c88">
</div>
<div id="outline-container-orgd3eb7fb" class="outline-4">
<h4 id="orgd3eb7fb">a) vsota kvadratov praštevil med a in b</h4>
<div class="outline-text-4" id="text-orgd3eb7fb">
<div class="org-src-container">
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">accumulate-filter</span> combiner null-value term a next b predikat?<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">if</span> <span style="color: #8ec07c;">(</span>&gt; a b<span style="color: #8ec07c;">)</span>
null-value
<span style="color: #8ec07c;">(</span><span style="color: #fb4933;">if</span> <span style="color: #d65d0e;">(</span>predikat? a<span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>combiner <span style="color: #458588;">(</span>term a<span style="color: #458588;">)</span> <span style="color: #458588;">(</span>accumulate-filter combiner null-value term <span style="color: #b16286;">(</span>next a<span style="color: #b16286;">)</span> next b predikat?<span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>accumulate-filter combiner null-value term <span style="color: #458588;">(</span>next a<span style="color: #458588;">)</span> next b predikat?<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">je-prastevilo?</span> a<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">define</span> <span style="color: #8ec07c;">(</span><span style="color: #fabd2f;">preveri-prastevilo?</span> x a<span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span><span style="color: #fb4933;">if</span> <span style="color: #d65d0e;">(</span>&gt; x <span style="color: #458588;">(</span>/ a 2<span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span>
#t
<span style="color: #d65d0e;">(</span><span style="color: #fb4933;">and</span> <span style="color: #458588;">(</span>not <span style="color: #b16286;">(</span>integer? <span style="color: #8ec07c;">(</span>/ a x<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span>preveri-prastevilo? <span style="color: #b16286;">(</span>+ x 1<span style="color: #b16286;">)</span> a<span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>preveri-prastevilo? 2 a<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #7c6f64;">;; </span><span style="color: #7c6f64;">(vsota kvadratov pra&#353;tevil med 1 in 12 je 209)</span>
<span style="color: #458588;">(</span>= <span style="color: #b16286;">(</span>accumulate-filter + 0 <span style="color: #8ec07c;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #d65d0e;">(</span>n<span style="color: #d65d0e;">)</span> <span style="color: #d65d0e;">(</span>* n n<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span> 1 <span style="color: #8ec07c;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #d65d0e;">(</span>n<span style="color: #d65d0e;">)</span> <span style="color: #d65d0e;">(</span>+ n 1<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span> 12 je-prastevilo?<span style="color: #b16286;">)</span>
209<span style="color: #458588;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orga117f13" class="outline-4">
<h4 id="orga117f13">a) produkt vseh naravnih števil manjših od n ki so "relativno pra-n" (torej si z n ne delijo skupnega delitelja razen n)</h4>
<div class="outline-text-4" id="text-orga117f13">
<div class="org-src-container">
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">accumulate-filter</span> combiner null-value term a next b predikat?<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">if</span> <span style="color: #8ec07c;">(</span>&gt; a b<span style="color: #8ec07c;">)</span>
null-value
<span style="color: #8ec07c;">(</span><span style="color: #fb4933;">if</span> <span style="color: #d65d0e;">(</span>predikat? a<span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>combiner <span style="color: #458588;">(</span>term a<span style="color: #458588;">)</span> <span style="color: #458588;">(</span>accumulate-filter combiner null-value term <span style="color: #b16286;">(</span>next a<span style="color: #b16286;">)</span> next b predikat?<span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>accumulate-filter combiner null-value term <span style="color: #458588;">(</span>next a<span style="color: #458588;">)</span> next b predikat?<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">id</span> a<span style="color: #b16286;">)</span> a<span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">inc</span> a<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>+ a 1<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">IN</span> a b<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span><span style="color: #fb4933;">and</span> a b<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">relativni-prastevili?</span> a b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>accumulate-filter IN #t <span style="color: #8ec07c;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #d65d0e;">(</span>x<span style="color: #d65d0e;">)</span> <span style="color: #d65d0e;">(</span><span style="color: #fb4933;">and</span> <span style="color: #458588;">(</span>not <span style="color: #b16286;">(</span>integer? <span style="color: #8ec07c;">(</span>/ a x<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span>not <span style="color: #b16286;">(</span>integer? <span style="color: #8ec07c;">(</span>/ b x<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span>
2 inc a id<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">produkt-relativnih-prastevil</span> n<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>accumulate-filter * 1 id 1 inc n <span style="color: #8ec07c;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #d65d0e;">(</span>x<span style="color: #d65d0e;">)</span> <span style="color: #d65d0e;">(</span>relativni-prastevili? x n<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span>produkt-relativnih-prastevil 9<span style="color: #458588;">)</span>
</pre>
</div>
<p>
TODO popravi!
TODO popravi!! ^
</p>
</div>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: Jurij</p>
<p class="date">Created: 2024-06-12 sre 19:35</p>
<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
</html>