diff --git a/zapiski/sicp-lio.html b/zapiski/sicp-lio.html index 0daf13d..cbcb081 100644 --- a/zapiski/sicp-lio.html +++ b/zapiski/sicp-lio.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Structure and Interpretation of Computer Programs @@ -201,36 +201,46 @@

Table of Contents

-
-

1. Foreword and Preface

+
+

1. Foreword and Preface

@@ -272,12 +282,12 @@ ukvarjanje s pojmovanjem "kako".

-
-

2. 1. Grajenje abstrakcij s procedurami

+
+

2. 1. Grajenje abstrakcij s procedurami

-
-

2.1. Elementi programiranja

+
+

2.1. Elementi programiranja

Primitivni izrazi
predstavtljajo najpreprostejše gradnike (entitete) @@ -290,8 +300,8 @@ omogočajo upravljanje z njimii kot enotami
-
-

2.2. Izvajanje kombinacij(e)

+
+

2.2. Izvajanje kombinacij(e)

Postopek za izvajanje kombinacij: @@ -333,8 +343,8 @@ oblika.

-
-

2.3. 1.1.4 Sestavljene procedure

+
+

2.3. 1.1.4 Sestavljene procedure

  • Številke in aritmetične operacije so primitivni podatki in procedure.
  • @@ -353,8 +363,8 @@ abstrakcije.
-
-

2.4. 1.1.5 Substitucijski model za izvajanje procedur

+
+

2.4. 1.1.5 Substitucijski model za izvajanje procedur

Za izvajanje sestavljenih procedur z argumenti, izvedeš telo procedure z vsakim @@ -383,8 +393,8 @@ izraza, ki vsebuje zgolj primitivne izraze in potem izvedi (vso) evalvacijo. -

-

2.5. meta

+
+

2.5. meta

Linki: @@ -400,8 +410,8 @@ Kako nastavit spacemacs, in malo o guile-u.

-
-

2.5.1. video lekcije

+
+

2.5.1. video lekcije

https://yewtu.be/channel/UCEBb1b_L6zDS3xTUrIALZOw (6.001 SICP: Structure and Interpretation of Computer Programs (2004)) @@ -411,16 +421,16 @@ Kako nastavit spacemacs, in malo o guile-u.

-
-

2.6. vaje

+
+

2.6. vaje

-
-

2.6.1. 1.3

+
+

2.6.1. 1.3

    -
  1. najprej narobe
    +
  2. najprej narobe

    Define a procedure that takes three numbers as arguments and returns the sum of @@ -428,45 +438,45 @@ the squares of the two larger numbers.

    -
    (define (sum-of-large x y z)
    -  (+
    -   (if (> x y) (* x x) (* y y))
    -   (if (> y z) (* y y) (* z z))
    -   )
    -  )
    -(sum-of-large 3 8 5)
    +
    (define (sum-of-large x y z)
    +  (+
    +   (if (> x y) (* x x) (* y y))
    +   (if (> y z) (* y y) (* z z))
    +   )
    +  )
    +(sum-of-large 3 8 5)
     
    -
    (define (sum-of-larger x y z) (let*
    -                                ((s (lambda (a) (* a a)))
    -                                 (sl (lambda (b c) (if (> b c) (s b) (s c))))
    +
    (define (sum-of-larger x y z) (let*
    +                                ((s (lambda (a) (* a a)))
    +                                 (sl (lambda (b c) (if (> b c) (s b) (s c))))
                                      )
                                   (+ (sl x y) (sl y z))
    -                              ))
    -(sum-of-larger 3 8 5)
    +                              ))
    +(sum-of-larger 3 8 5)
     
  3. -
  4. pravilno
    +
  5. pravilno
    -
    (define (sum-squares-of-larger x y z)
    -  (if (> x y)
    -      (if (> y z)
    +
    (define (sum-squares-of-larger x y z)
    +  (if (> x y)
    +      (if (> y z)
               (+ (* x x) (* y y))
               (+ (* x x) (* z z))
               )
    -      (if (> x z)
    +      (if (> x z)
               (+ (* y y) (* x x))
               (+ (* y y) (* z z))
               )
    -      )
    -  )
    -(sum-squares-of-larger 9 10 8)
    +      )
    +  )
    +(sum-squares-of-larger 9 10 8)
     
    @@ -474,8 +484,8 @@ the squares of the two larger numbers.
-
-

2.6.2. 1.5

+
+

2.6.2. 1.5

Aplikativni vrstni red: pade takoj v neskoncno zanko. @@ -484,8 +494,8 @@ Normalni vrstni red: izvrsi test in pride v if, ki ne izvrsi drugega dela.

-
-

2.6.3. 1.6

+
+

2.6.3. 1.6

sqrt-newton.scm @@ -493,8 +503,8 @@ Normalni vrstni red: izvrsi test in pride v if, ki ne izvrsi drugega dela.

-
-

2.6.4. 1.7

+
+

2.6.4. 1.7

  • good-enough? ni vredu za iskanje korenov majhnih stevil.
  • @@ -509,8 +519,8 @@ dovolj majhne in takrat prekini funkcijo.
-
-

2.6.5. 1.8

+
+

2.6.5. 1.8

// Glej v sqrt-newton.sqm @@ -519,8 +529,8 @@ dovolj majhne in takrat prekini funkcijo.

-
-

2.7. 1.1.8 Procedure kot crne skatle abstrakcij

+
+

2.7. 1.1.8 Procedure kot crne skatle abstrakcij

  • block structure
  • @@ -528,6 +538,124 @@ dovolj majhne in takrat prekini funkcijo.
+ +
+

2.8. 1.2.2 Drevesna rekurzija

+
+ +
+

2.9. 1.2.3 Redi rasti

+
+ +
+

2.10. 1.2.4 Eksponentna funkcija

+
+ +
+

2.11. 1.2.5 Najvecji skupni deljitel

+
+ +
+

2.12. 1.2.6 Primer: Iskanje prastevil

+
+ +
+

2.13. 1.3 Sestavljanje abstrakcij s procedurami visjega reda

+
+ +
+

2.14. 1.3.1 Procedure kot argumenti

+
+

+//exercise 1.29 +#name: simpson +

+
+
(define (sum term a next b)
+  (if (> a b)
+      0
+      (+ (term a)
+         (sum term (next a) next b)
+         )
+      )
+  )
+
+(define (integral f a b dx)
+  (define (add-dx x) (+ x dx))
+  (* (sum f (+ a (/ dx 2.0)) add-dx b) dx)
+  )
+
+(define (sum-s term a next b fact)
+  ;; fact is altering between 4 and 2
+  (define (check-fact fact) (if (= fact 4) 2 4))
+  (if (> a b)
+      0
+      (+ (* fact (term a))
+      (sum-s term (next a) next b (check-fact fact))
+      )
+  )
+  )
+
+(define (simpson f a b dx)
+  (define (add-dx x) (+ x dx))
+  (* (+ (f a) (f b) (sum-s f (add-dx a) add-dx (- b dx) 4) ) (/ dx 3.0))
+  )
+
+(define (simpson-gizmo f a b dx)
+  (define (add-dxdx x) (+ x dx dx))
+  (* (+
+   (* 4 (sum f (+ a dx) add-dxdx b))
+   (* 2 (sum f a add-dxdx b))
+   (- (f a))
+   (- (f b))
+   ) (/ dx 3.0))
+  )
+
+(define (cube x) (* x x x))
+
+(list
+ (integral cube 1 2 0.01)
+ (integral cube 1 2 0.001)
+
+ (simpson cube 1 2 0.01)
+ (simpson cube 1 2 0.001)
+ (simpson cube 1 2 (/ 1 1000))
+ (simpson-gizmo cube 1 2 0.01)
+ (simpson-gizmo cube 1 2 (/ 1 10000))
+ (simpson-gizmo cube 1 2 0.00001)
+)
+
+
+ +

+// exercise 1.30 +

+
+
(define (sum-i term a next b)
+  (define (iter a result)
+    (if (> a b)
+        result
+        (iter (next a) (+ result (term a)))
+        )
+    )
+  (iter a 0)
+  )
+
+
+
+
+ +
+

2.15. 1.3.2 Sestavljanje procedur z Lambda

+
+ +
+

2.16. 1.3.3 Procedure kot splosne metode

+
+ +
+

2.17. 1.3.4 Procedure kot vrnjene vrednosti

+
diff --git a/zapiski/sicp-lio.org b/zapiski/sicp-lio.org index 3594ee0..d3a6c98 100644 --- a/zapiski/sicp-lio.org +++ b/zapiski/sicp-lio.org @@ -195,3 +195,97 @@ Normalni vrstni red: izvrsi test in pride v if, ki ne izvrsi drugega dela. - block structure - lexical scoping + +** 1.2.2 Drevesna rekurzija + +** 1.2.3 Redi rasti + +** 1.2.4 Eksponentna funkcija + +** 1.2.5 Najvecji skupni deljitel + +** 1.2.6 Primer: Iskanje prastevil + +** 1.3 Sestavljanje abstrakcij s procedurami visjega reda + +** 1.3.1 Procedure kot argumenti + +//exercise 1.29 +#name: simpson +#+begin_src scheme + (define (sum term a next b) + (if (> a b) + 0 + (+ (term a) + (sum term (next a) next b) + ) + ) + ) + + (define (integral f a b dx) + (define (add-dx x) (+ x dx)) + (* (sum f (+ a (/ dx 2.0)) add-dx b) dx) + ) + + (define (sum-s term a next b fact) + ;; fact is altering between 4 and 2 + (define (check-fact fact) (if (= fact 4) 2 4)) + (if (> a b) + 0 + (+ (* fact (term a)) + (sum-s term (next a) next b (check-fact fact)) + ) + ) + ) + + (define (simpson f a b dx) + (define (add-dx x) (+ x dx)) + (* (+ (f a) (f b) (sum-s f (add-dx a) add-dx (- b dx) 4) ) (/ dx 3.0)) + ) + + (define (simpson-gizmo f a b dx) + (define (add-dxdx x) (+ x dx dx)) + (* (+ + (* 4 (sum f (+ a dx) add-dxdx b)) + (* 2 (sum f a add-dxdx b)) + (- (f a)) + (- (f b)) + ) (/ dx 3.0)) + ) + + (define (cube x) (* x x x)) + + (list + (integral cube 1 2 0.01) + (integral cube 1 2 0.001) + + (simpson cube 1 2 0.01) + (simpson cube 1 2 0.001) + (simpson cube 1 2 (/ 1 1000)) + (simpson-gizmo cube 1 2 0.01) + (simpson-gizmo cube 1 2 (/ 1 10000)) + (simpson-gizmo cube 1 2 0.00001) + ) +#+end_src + +#+RESULTS: +| 3.7499625000000045 | 3.7499996249995324 | 3.644925346666673 | 3.7499999999995324 | 3.749893334961112 | + +// exercise 1.30 +#+begin_src scheme + (define (sum-i term a next b) + (define (iter a result) + (if (> a b) + result + (iter (next a) (+ result (term a))) + ) + ) + (iter a 0) + ) +#+end_src + +** 1.3.2 Sestavljanje procedur z Lambda + +** 1.3.3 Procedure kot splosne metode + +** 1.3.4 Procedure kot vrnjene vrednosti