Dodelana vaja 2.9

main
Jurij Podgoršek 2024-09-04 19:25:19 +02:00
parent 3f9a8632a4
commit 6656ded5ba
2 changed files with 187 additions and 67 deletions

View File

@ -3,7 +3,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head> <head>
<!-- 2024-07-24 sre 22:18 --> <!-- 2024-09-04 sre 19:25 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Zapiski in vaje #6 srečanja programerskega bralnega krožka SICP</title> <title>Zapiski in vaje #6 srečanja programerskega bralnega krožka SICP</title>
@ -197,13 +197,13 @@
<body> <body>
<div id="content" class="content"> <div id="content" class="content">
<h1 class="title">Zapiski in vaje #6 srečanja programerskega bralnega krožka SICP</h1> <h1 class="title">Zapiski in vaje #6 srečanja programerskega bralnega krožka SICP</h1>
<div id="outline-container-orgaa918c3" class="outline-2"> <div id="outline-container-org19a71b6" class="outline-2">
<h2 id="orgaa918c3">Teme</h2> <h2 id="org19a71b6">Teme</h2>
<div class="outline-text-2" id="text-orgaa918c3"> <div class="outline-text-2" id="text-org19a71b6">
</div> </div>
<div id="outline-container-org2a69a4f" class="outline-3"> <div id="outline-container-orgaca5b02" class="outline-3">
<h3 id="org2a69a4f">Grajenje abstrakcij s podatki</h3> <h3 id="orgaca5b02">Grajenje abstrakcij s podatki</h3>
<div class="outline-text-3" id="text-org2a69a4f"> <div class="outline-text-3" id="text-orgaca5b02">
<p> <p>
Prvo poglavje, v katerem smo operirali s preprostimi števili, drugo poglavje nadgrajuje s podatkovnimi struktura oz. kombiniranjem podatkovnih objektov v sestavljene podatkovne modele. Prvo poglavje, v katerem smo operirali s preprostimi števili, drugo poglavje nadgrajuje s podatkovnimi struktura oz. kombiniranjem podatkovnih objektov v sestavljene podatkovne modele.
</p> </p>
@ -253,13 +253,13 @@ Uporabimo funkcijo za najvecji skupni imenovlec, da poenostavimo recimo 6/3 v 2/
</div> </div>
</div> </div>
</div> </div>
<div id="outline-container-org0c8d9f6" class="outline-2"> <div id="outline-container-org8206e7f" class="outline-2">
<h2 id="org0c8d9f6">vaje</h2> <h2 id="org8206e7f">vaje</h2>
<div class="outline-text-2" id="text-org0c8d9f6"> <div class="outline-text-2" id="text-org8206e7f">
</div> </div>
<div id="outline-container-orgff5527e" class="outline-3"> <div id="outline-container-org6ec3c99" class="outline-3">
<h3 id="orgff5527e">2.1 bolji ustvari-rac</h3> <h3 id="org6ec3c99">2.1 bolji ustvari-rac</h3>
<div class="outline-text-3" id="text-orgff5527e"> <div class="outline-text-3" id="text-org6ec3c99">
<div class="org-src-container"> <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;">ustvari-rac</span> s i<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;">ustvari-rac</span> s i<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>cons <span style="color: #b16286;">(</span>cons
@ -271,9 +271,9 @@ Uporabimo funkcijo za najvecji skupni imenovlec, da poenostavimo recimo 6/3 v 2/
</div> </div>
</div> </div>
</div> </div>
<div id="outline-container-orgc271da6" class="outline-3"> <div id="outline-container-org80d30fc" class="outline-3">
<h3 id="orgc271da6">2.2 polovica daljice</h3> <h3 id="org80d30fc">2.2 polovica daljice</h3>
<div class="outline-text-3" id="text-orgc271da6"> <div class="outline-text-3" id="text-org80d30fc">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">make-point</span> cons<span style="color: #458588;">)</span> <pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">make-point</span> cons<span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">x-point</span> car<span style="color: #458588;">)</span> <span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">x-point</span> car<span style="color: #458588;">)</span>
@ -303,9 +303,13 @@ Uporabimo funkcijo za najvecji skupni imenovlec, da poenostavimo recimo 6/3 v 2/
</div> </div>
</div> </div>
</div> </div>
<div id="outline-container-org791e50c" class="outline-3"> <div id="outline-container-orgf6d22ce" class="outline-3">
<h3 id="org791e50c">2.3 obseg in ploscina kvadra</h3> <h3 id="orgf6d22ce">2.3 obseg in ploščina pravokotnik</h3>
<div class="outline-text-3" id="text-org791e50c"> <div class="outline-text-3" id="text-orgf6d22ce">
<p>
Najprej super simpl imeplemntacija - imamo samo dolžino in širino, ni res v koordinatnem sistemu. Plod lenobe, na katerega in na katero sem ponosen.
</p>
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-scheme"><span style="color: #7c6f64;">;; </span><span style="color: #7c6f64;">Dolzina in sirina</span> <pre class="src src-scheme"><span style="color: #7c6f64;">;; </span><span style="color: #7c6f64;">Dolzina in sirina</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">ploscina-kvadra</span> k<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;">ploscina-kvadra</span> k<span style="color: #b16286;">)</span>
@ -317,11 +321,45 @@ Uporabimo funkcijo za najvecji skupni imenovlec, da poenostavimo recimo 6/3 v 2/
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">make-kvader</span> cons<span style="color: #458588;">)</span> <span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">make-kvader</span> cons<span style="color: #458588;">)</span>
</pre> </pre>
</div> </div>
<p>
Pa še primer v koordinatnem sistemu. Dejmo reč da je kvader vektor s širino; točka od in točka do daljice dolžine ter širina, ki se zgodi desno od daljice dolžine.
</p>
<div class="org-src-container">
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">make-point</span> cons<span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">make-segment</span> cons<span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">x-point</span> car<span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">y-point</span> cdr<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;">print-point</span> p<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>newline<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>display <span style="color: #b8bb26;">"("</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>display <span style="color: #8ec07c;">(</span>x-point p<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>display <span style="color: #b8bb26;">","</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>display <span style="color: #8ec07c;">(</span>y-point p<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>display <span style="color: #b8bb26;">")"</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;">daljica</span> pravokotnik<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>car pravokotnik<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;">sirina</span> pravokotnik<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>cdr pravokotnik<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;">make-pravokotnik</span> daljica sirina<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>cons daljica sirina<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;">tocke-pravokotnika</span> pravokotnik<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>print-point <span style="color: #8ec07c;">(</span>start-segment <span style="color: #d65d0e;">(</span>daljica pravokotnik<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>print-point <span style="color: #8ec07c;">(</span>end-segment pravokotnik <span style="color: #d65d0e;">(</span>daljica pravokotnik<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>print-point <span style="color: #8ec07c;">(</span>+ <span style="color: #d65d0e;">(</span>x-point <span style="color: #458588;">(</span>daljica pravokotnik<span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #7c6f64;">;; </span><span style="color: #7c6f64;">TODO cetrta tocka</span>
<span style="color: #458588;">)</span>
</pre>
</div> </div>
</div> </div>
<div id="outline-container-orgf1adee4" class="outline-3"> </div>
<h3 id="orgf1adee4">2.4 Proceduralna reprezantacija parov</h3> <div id="outline-container-org165756d" class="outline-3">
<div class="outline-text-3" id="text-orgf1adee4"> <h3 id="org165756d">2.4 Proceduralna reprezantacija parov</h3>
<div class="outline-text-3" id="text-org165756d">
<div class="org-src-container"> <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;">cons</span> x y<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;">cons</span> x y<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #8ec07c;">(</span>m<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span>m x y<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span> <span style="color: #b16286;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #8ec07c;">(</span>m<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span>m x y<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
@ -341,9 +379,9 @@ Uporabimo funkcijo za najvecji skupni imenovlec, da poenostavimo recimo 6/3 v 2/
</div> </div>
</div> </div>
</div> </div>
<div id="outline-container-orgcf7a90a" class="outline-3"> <div id="outline-container-org265a0b2" class="outline-3">
<h3 id="orgcf7a90a">2.5 aritmeticni par v stevilu</h3> <h3 id="org265a0b2">2.5 aritmeticni par v stevilu</h3>
<div class="outline-text-3" id="text-orgcf7a90a"> <div class="outline-text-3" id="text-org265a0b2">
<div class="org-src-container"> <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;">cons</span> a b<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;">cons</span> a b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>* <span style="color: #8ec07c;">(</span>expt 2 a<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span>expt 3 b<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span> <span style="color: #b16286;">(</span>* <span style="color: #8ec07c;">(</span>expt 2 a<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span>expt 3 b<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
@ -366,9 +404,9 @@ Uporabimo funkcijo za najvecji skupni imenovlec, da poenostavimo recimo 6/3 v 2/
</div> </div>
</div> </div>
</div> </div>
<div id="outline-container-org3389c10" class="outline-3"> <div id="outline-container-orgc00d6df" class="outline-3">
<h3 id="org3389c10">2.6 churchova števila</h3> <h3 id="orgc00d6df">2.6 churchova števila</h3>
<div class="outline-text-3" id="text-org3389c10"> <div class="outline-text-3" id="text-orgc00d6df">
<div class="org-src-container"> <div class="org-src-container">
<pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">zero</span> <span style="color: #b16286;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #8ec07c;">(</span>f<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #d65d0e;">(</span>x<span style="color: #d65d0e;">)</span> x<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span> <pre class="src src-scheme"><span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">zero</span> <span style="color: #b16286;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #8ec07c;">(</span>f<span style="color: #8ec07c;">)</span> <span style="color: #8ec07c;">(</span><span style="color: #fb4933;">lambda</span> <span style="color: #d65d0e;">(</span>x<span style="color: #d65d0e;">)</span> x<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
@ -395,9 +433,9 @@ Uporabimo funkcijo za najvecji skupni imenovlec, da poenostavimo recimo 6/3 v 2/
</div> </div>
</div> </div>
</div> </div>
<div id="outline-container-orgc045649" class="outline-3"> <div id="outline-container-org7b1892d" class="outline-3">
<h3 id="orgc045649">2.7 Racunanje z intervali (z napako)</h3> <h3 id="org7b1892d">2.7 Racunanje z intervali (z napako)</h3>
<div class="outline-text-3" id="text-orgc045649"> <div class="outline-text-3" id="text-org7b1892d">
<div class="org-src-container"> <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;">add-interval</span> x y<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;">add-interval</span> x y<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>make-interval <span style="color: #8ec07c;">(</span>+ <span style="color: #d65d0e;">(</span>lower-bound x<span style="color: #d65d0e;">)</span> <span style="color: #d65d0e;">(</span>lower-bound y<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span> <span style="color: #b16286;">(</span>make-interval <span style="color: #8ec07c;">(</span>+ <span style="color: #d65d0e;">(</span>lower-bound x<span style="color: #d65d0e;">)</span> <span style="color: #d65d0e;">(</span>lower-bound y<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span>
@ -422,21 +460,33 @@ Uporabimo funkcijo za najvecji skupni imenovlec, da poenostavimo recimo 6/3 v 2/
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">lower-bound</span> car<span style="color: #458588;">)</span> <span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">lower-bound</span> car<span style="color: #458588;">)</span>
<span style="color: #458588;">(</span>list <span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">izpisi-interval</span> a<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>add-interval <span style="color: #b16286;">(</span>string-append <span style="color: #8ec07c;">(</span>lower-bound a<span style="color: #8ec07c;">)</span> <span style="color: #b8bb26;">"&#8212;"</span> <span style="color: #8ec07c;">(</span>upper-bound a<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #8ec07c;">(</span>make-interval 3 4<span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span>make-interval 5 8<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>mul-interval
<span style="color: #8ec07c;">(</span>make-interval 5 6<span style="color: #8ec07c;">)</span> <span style="color: #458588;">(</span>list
<span style="color: #8ec07c;">(</span>make-interval 8 10<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span> <span style="color: #b8bb26;">"3&#8212;4 + 5&#8212;8"</span>
<span style="color: #b16286;">(</span>izpisi-interval
<span style="color: #8ec07c;">(</span>add-interval
<span style="color: #d65d0e;">(</span>make-interval 3 4<span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>make-interval 5 8<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b8bb26;">"5&#8212;6 &#215; 8&#8212;10"</span>
<span style="color: #b16286;">(</span>izpisi-interval
<span style="color: #8ec07c;">(</span>mul-interval
<span style="color: #d65d0e;">(</span>make-interval 5 6<span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>make-interval 8 10<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
</pre> </pre>
</div> </div>
</div> </div>
</div> </div>
<div id="outline-container-org9363d2f" class="outline-3"> <div id="outline-container-orgdbb464f" class="outline-3">
<h3 id="org9363d2f">2.8 odstevanje intervala</h3> <h3 id="orgdbb464f">2.8 odstevanje intervala</h3>
<div class="outline-text-3" id="text-org9363d2f"> <div class="outline-text-3" id="text-orgdbb464f">
<p>
Pri odštevanju intervala moramo pazit, da od zgornje meje prvega intervala odštejemo spodnjo mejo drugega!
</p>
<div class="org-src-container"> <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;">make-interval</span> a b<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>cons a b<span style="color: #b16286;">)</span><span style="color: #458588;">)</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;">make-interval</span> a b<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>cons a b<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
@ -456,15 +506,16 @@ Uporabimo funkcijo za najvecji skupni imenovlec, da poenostavimo recimo 6/3 v 2/
</div> </div>
</div> </div>
</div> </div>
<div id="outline-container-org8140af8" class="outline-3"> <div id="outline-container-orgb6310f8" class="outline-3">
<h3 id="org8140af8">2.9 srednja vrednost in napaka</h3> <h3 id="orgb6310f8">2.9 srednja vrednost in napaka</h3>
<div class="outline-text-3" id="text-org8140af8"> <div class="outline-text-3" id="text-orgb6310f8">
<p> <p>
Sestevanje in odstevanje je isto pri intervalu od-do kot srednja-vrednost napaka Seštevanje je isto pri intervalu od-do kot srednja-vrednost in napaka. Odštevanje je podobno, le da napaki preprosto seštejemo (kar je malo bolj "intuitivno" kot pri intervalu, vsaj meni).
</p> </p>
<div class="org-src-container"> <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;">make-priblizek</span> vrednost napaka<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>cons vrednost napaka<span style="color: #b16286;">)</span><span style="color: #458588;">)</span> <pre class="src src-scheme"><span style="color: #7c6f64;">;; </span><span style="color: #7c6f64;">"napaka" je "width" intervala</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">make-priblizek</span> vrednost napaka<span style="color: #b16286;">)</span> <span style="color: #b16286;">(</span>cons vrednost napaka<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">vrednost</span> car<span style="color: #458588;">)</span> <span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #fabd2f;">vrednost</span> car<span style="color: #458588;">)</span>
@ -480,18 +531,31 @@ Sestevanje in odstevanje je isto pri intervalu od-do kot srednja-vrednost napaka
<span style="color: #458588;">(</span><span style="color: #fb4933;">define</span> <span style="color: #b16286;">(</span><span style="color: #fabd2f;">mul-priblizek</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;">mul-priblizek</span> a b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>make-priblizek <span style="color: #8ec07c;">(</span>* <span style="color: #d65d0e;">(</span>vrednost a<span style="color: #d65d0e;">)</span> <span style="color: #d65d0e;">(</span>vrednost b<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span> <span style="color: #b16286;">(</span>make-priblizek <span style="color: #8ec07c;">(</span>* <span style="color: #d65d0e;">(</span>vrednost a<span style="color: #d65d0e;">)</span> <span style="color: #d65d0e;">(</span>vrednost b<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">()</span><span style="color: #b16286;">)</span><span style="color: #458588;">)</span> <span style="color: #8ec07c;">(</span>+ <span style="color: #d65d0e;">(</span>* <span style="color: #458588;">(</span>vrednost a<span style="color: #458588;">)</span> <span style="color: #458588;">(</span>napaka b<span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>* <span style="color: #458588;">(</span>vrednost b<span style="color: #458588;">)</span> <span style="color: #458588;">(</span>napaka a<span style="color: #458588;">)</span><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;">div-priblizek</span> a b<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>make-priblizek <span style="color: #8ec07c;">(</span>* <span style="color: #d65d0e;">(</span>vrednost a<span style="color: #d65d0e;">)</span> <span style="color: #d65d0e;">(</span>vrednost b<span style="color: #d65d0e;">)</span><span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span>+ <span style="color: #d65d0e;">(</span>* <span style="color: #458588;">(</span>vrednost a<span style="color: #458588;">)</span> <span style="color: #458588;">(</span>napaka b<span style="color: #458588;">)</span><span style="color: #d65d0e;">)</span>
<span style="color: #d65d0e;">(</span>* <span style="color: #458588;">(</span>vrednost b<span style="color: #458588;">)</span> <span style="color: #458588;">(</span>napaka a<span style="color: #458588;">)</span><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: #458588;">(</span>list
<span style="color: #b8bb26;">"vsota in razlika je preprosta"</span> <span style="color: #b8bb26;">"vsota in razlika sta preprosti"</span>
<span style="color: #b8bb26;">"8&#177;3 + 4&#177;1 = 12&#177;4 (8&#8212;16)"</span>
<span style="color: #b16286;">(</span>add-priblizek <span style="color: #8ec07c;">(</span>make-priblizek 8 3<span style="color: #8ec07c;">)</span> <span style="color: #b16286;">(</span>add-priblizek <span style="color: #8ec07c;">(</span>make-priblizek 8 3<span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span>make-priblizek 4 1<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span> <span style="color: #8ec07c;">(</span>make-priblizek 4 1<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b8bb26;">"8&#177;3 - 4&#177;1 = 4&#177;4 (6&#8212;8)"</span>
<span style="color: #b16286;">(</span>sub-priblizek <span style="color: #8ec07c;">(</span>make-priblizek 8 3<span style="color: #8ec07c;">)</span> <span style="color: #b16286;">(</span>sub-priblizek <span style="color: #8ec07c;">(</span>make-priblizek 8 3<span style="color: #8ec07c;">)</span>
<span style="color: #8ec07c;">(</span>make-priblizek 4 1<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span> <span style="color: #8ec07c;">(</span>make-priblizek 4 1<span style="color: #8ec07c;">)</span><span style="color: #b16286;">)</span>
<span style="color: #b8bb26;">"pri mnozenju in deljenju pa je \"sirina\" (napaka) odvisna tudi od vrednosti"</span><span style="color: #458588;">)</span> <span style="color: #b8bb26;">"pri mnozenju in deljenju pa je \"sirina\" (napaka) odvisna tudi od vrednosti"</span><span style="color: #458588;">)</span>
<span style="color: #7c6f64;">;; </span><span style="color: #7c6f64;">TODO napisi funkcije za mnozenje in deljenje</span> <span style="color: #b8bb26;">"8&#177;3 &#215; 4&#177;1 = 35&#177;20 (8&#215;4 + 3&#215;1) &#177; (1&#215;8 + 3&#215;4) (15&#8212;55)"</span>
<span style="color: #458588;">(</span>mul-priblizek <span style="color: #b16286;">(</span>make-priblizek 8 3<span style="color: #b16286;">)</span>
<span style="color: #b16286;">(</span>make-priblizek 4 1<span style="color: #b16286;">)</span><span style="color: #458588;">)</span>
<span style="color: #b8bb26;">"8&#177;3 &#247; 4&#177;1 = ?"</span>
<span style="color: #7c6f64;">;; </span><span style="color: #7c6f64;">TODO</span>
<span style="color: #7c6f64;">;</span><span style="color: #7c6f64;">(div-priblizek (make-priblizek 8 3)</span>
<span style="color: #7c6f64;">; </span><span style="color: #7c6f64;">(make-priblizek 4 1))</span>
<span style="color: #7c6f64;">;; </span><span style="color: #7c6f64;">TODO napisi funkcije za deljenje</span>
</pre> </pre>
</div> </div>
</div> </div>
@ -500,7 +564,7 @@ Sestevanje in odstevanje je isto pri intervalu od-do kot srednja-vrednost napaka
</div> </div>
<div id="postamble" class="status"> <div id="postamble" class="status">
<p class="author">Author: Jurij</p> <p class="author">Author: Jurij</p>
<p class="date">Created: 2024-07-24 sre 22:18</p> <p class="date">Created: 2024-09-04 sre 19:25</p>
<p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p> <p class="validation"><a href="https://validator.w3.org/check?uri=referer">Validate</a></p>
</div> </div>
</body> </body>

View File

@ -87,7 +87,9 @@ Uporabimo funkcijo za najvecji skupni imenovlec, da poenostavimo recimo 6/3 v 2/
(avg (y-point start) (y-point end))))) (avg (y-point start) (y-point end)))))
#+end_src #+end_src
** 2.3 obseg in ploscina kvadra ** 2.3 obseg in ploščina pravokotnik
Najprej super simpl imeplemntacija - imamo samo dolžino in širino, ni res v koordinatnem sistemu. Plod lenobe, na katerega in na katero sem ponosen.
#+begin_src scheme #+begin_src scheme
;; Dolzina in sirina ;; Dolzina in sirina
@ -100,6 +102,38 @@ Uporabimo funkcijo za najvecji skupni imenovlec, da poenostavimo recimo 6/3 v 2/
(define make-kvader cons) (define make-kvader cons)
#+end_src #+end_src
Pa še primer v koordinatnem sistemu. Dejmo reč da je kvader vektor s širino; točka od in točka do daljice dolžine ter širina, ki se zgodi desno od daljice dolžine.
#+begin_src scheme
(define make-point cons)
(define make-segment cons)
(define x-point car)
(define y-point cdr)
(define (print-point p)
(newline)
(display "(")
(display (x-point p))
(display ",")
(display (y-point p))
(display ")"))
(define (daljica pravokotnik) (car pravokotnik))
(define (sirina pravokotnik) (cdr pravokotnik))
(define (make-pravokotnik daljica sirina)
(cons daljica sirina))
(define (tocke-pravokotnika pravokotnik)
(print-point (start-segment (daljica pravokotnik)))
(print-point (end-segment pravokotnik (daljica pravokotnik)))
(print-point (+ (x-point (daljica pravokotnik))))
;; TODO cetrta tocka
)
#+end_src
** 2.4 Proceduralna reprezantacija parov ** 2.4 Proceduralna reprezantacija parov
#+begin_src scheme #+begin_src scheme
@ -198,20 +232,28 @@ Uporabimo funkcijo za najvecji skupni imenovlec, da poenostavimo recimo 6/3 v 2/
(define lower-bound car) (define lower-bound car)
(list (define (izpisi-interval a)
(add-interval (string-append (lower-bound a) "—" (upper-bound a)))
(make-interval 3 4)
(make-interval 5 8))
(mul-interval
(make-interval 5 6) (list
(make-interval 8 10))) "3—4 + 5—8"
(izpisi-interval
(add-interval
(make-interval 3 4)
(make-interval 5 8)))
"5—6 × 8—10"
(izpisi-interval
(mul-interval
(make-interval 5 6)
(make-interval 8 10))))
#+end_src #+end_src
#+RESULTS: #+RESULTS:
: ((8 . 12) (40 . 60))
** 2.8 odstevanje intervala ** 2.8 odstevanje intervala
Pri odštevanju intervala moramo pazit, da od zgornje meje prvega intervala odštejemo spodnjo mejo drugega!
#+begin_src scheme #+begin_src scheme
(define (make-interval a b) (cons a b)) (define (make-interval a b) (cons a b))
@ -235,9 +277,10 @@ Uporabimo funkcijo za najvecji skupni imenovlec, da poenostavimo recimo 6/3 v 2/
** 2.9 srednja vrednost in napaka ** 2.9 srednja vrednost in napaka
Sestevanje in odstevanje je isto pri intervalu od-do kot srednja-vrednost napaka Seštevanje je isto pri intervalu od-do kot srednja-vrednost in napaka. Odštevanje je podobno, le da napaki preprosto seštejemo (kar je malo bolj "intuitivno" kot pri intervalu, vsaj meni).
#+begin_src scheme #+begin_src scheme
;; "napaka" je "width" intervala
(define (make-priblizek vrednost napaka) (cons vrednost napaka)) (define (make-priblizek vrednost napaka) (cons vrednost napaka))
(define vrednost car) (define vrednost car)
@ -254,18 +297,31 @@ Sestevanje in odstevanje je isto pri intervalu od-do kot srednja-vrednost napaka
(define (mul-priblizek a b) (define (mul-priblizek a b)
(make-priblizek (* (vrednost a) (vrednost b)) (make-priblizek (* (vrednost a) (vrednost b))
())) (+ (* (vrednost a) (napaka b))
(* (vrednost b) (napaka a)))))
(define (div-priblizek a b)
(make-priblizek (* (vrednost a) (vrednost b))
(+ (* (vrednost a) (napaka b))
(* (vrednost b) (napaka a)))))
(list (list
"vsota in razlika je preprosta" "vsota in razlika sta preprosti"
"8±3 + 4±1 = 12±4 (8—16)"
(add-priblizek (make-priblizek 8 3) (add-priblizek (make-priblizek 8 3)
(make-priblizek 4 1)) (make-priblizek 4 1))
"8±3 - 4±1 = 4±4 (6—8)"
(sub-priblizek (make-priblizek 8 3) (sub-priblizek (make-priblizek 8 3)
(make-priblizek 4 1)) (make-priblizek 4 1))
"pri mnozenju in deljenju pa je \"sirina\" (napaka) odvisna tudi od vrednosti") "pri mnozenju in deljenju pa je \"sirina\" (napaka) odvisna tudi od vrednosti")
;; TODO napisi funkcije za mnozenje in deljenje "8±3 × 4±1 = 35±20 (8×4 + 3×1) ± (1×8 + 3×4) (15—55)"
(mul-priblizek (make-priblizek 8 3)
(make-priblizek 4 1))
"8±3 ÷ 4±1 = ?"
;; TODO
;(div-priblizek (make-priblizek 8 3)
; (make-priblizek 4 1))
;; TODO napisi funkcije za deljenje
#+end_src #+end_src
#+RESULTS: #+RESULTS: