Commits

shl...@cec68495-dca5-4e2b-845c-11fdaaa4f967  committed c83d152

Moved more stuff from vipe to t2 or to /dev/null.

  • Participants
  • Parent commits 859b242

Comments (0)

Files changed (11)

File t2/haskell/primes.zip

Binary file added.

File t2/lambda-calculus/add.scm

+(load "lc_prelude.scm")
+
+(define lc-bit->church 
+    (lambda (bit)
+        ((bit one) zero)
+    )
+)
+
+(define lc-full-adder-ret-make
+    (lambda (bit)
+        (lambda (carry)
+            ((lc_cons bit) carry)
+        )
+    )
+)
+
+(define lc-full-adder-ret-get-bit lc_car)
+(define lc-full-adder-ret-get-carry lc_cdr)
+
+(define lc_xor
+    (lambda (x)
+        (lambda (y)
+            ; If x then:
+            ((x 
+                ; If-part
+                ((y lc_false) lc_true)) 
+                ; Else-part
+                ((y lc_true) lc_false)
+            )
+        )
+    )
+)
+
+(define greater-or-equal
+    (lambda (x)
+            (lambda (y)
+                    (is-zero? ((subtract y) x))
+            )
+    )
+)
+
+
+(define lc-full-adder
+    (lambda (bit1)
+        (lambda (bit2)
+            (lambda (carry)
+                ((lambda (num-bits)
+                    ((lc-full-adder-ret-make
+                        ((lc_xor ((lc_xor bit1) bit2)) carry))
+                        ((greater-or-equal num-bits) two)
+                    )
+                )
+                    ((add 
+                        ((add 
+                            (lc-bit->church bit1)) 
+                            (lc-bit->church bit2)
+                        ))
+                        (lc-bit->church carry)
+                    )
+                )
+            )
+        )
+    )
+)
+
+(define (int->bit-vector num)
+    (define (get-num-bits num num-bits)
+        (if (= num 0)
+            num-bits
+            (get-num-bits (quotient num 2) (1+ num-bits))
+        )
+    )
+    (define (myconvert num num-bits-log2)
+        (if (= num-bits-log2 0)
+            ; Put a single bit
+            (if (= num 0) lc_false lc_true)
+            (let*
+                (
+                    (next-log2 (-1+ num-bits-log2))
+                    (exp2 (expt 2 (expt 2 next-log2)))
+                )
+                ((lc_cons 
+                    (myconvert (remainder num exp2) next-log2))
+                    (myconvert (quotient num exp2) next-log2)
+                    )
+            )
+        )
+    )
+    (let* 
+        (
+            (num-bits (get-num-bits num 0))
+            (num-bits-log2 (get-num-bits num-bits 0))
+        )
+        
+        (list (myconvert num num-bits-log2) num-bits-log2)
+    )
+)
+
+(define (bit-vector->int vec depth)
+    (if (= depth 0)
+        ; Get the numerical value of the bit
+        ((vec 1) 0)
+        ; int = int(car(vec)) | int(car(vec)) << (2**depth)
+        (+ 
+            (bit-vector->int (lc_car vec) (- depth 1))
+            (* 
+                (expt 2 (expt 2 (- depth 1)))
+                (bit-vector->int (lc_cdr vec) (- depth 1))
+            )
+        )
+    )
+)
+
+(define (bit-vector-lc->scheme vec depth)
+    (if (= depth 0)
+        ((vec 1) 0)
+        (cons 
+            (bit-vector-lc->scheme (lc_car vec) (-1+ depth))
+            (bit-vector-lc->scheme (lc_cdr vec) (-1+ depth))
+        )
+    )
+)
+
+(define (full-adder-ret->scheme fa-ret)
+    (list 
+        (((lc_car fa-ret) 1) 0)
+        (((lc_cdr fa-ret) 1) 0)
+    )
+)
+
+(define make-result-and-carry
+    (lambda (result)
+        (lambda (carry)
+            ((lc_cons result) carry)
+        )
+    )
+)
+
+(define r-c-result
+    (lambda (r-c)
+        (lc_car r-c)
+    )
+)
+
+(define r-c-carry
+    (lambda (r-c)
+        (lc_cdr r-c)    
+    )
+)
+
+(define make-lbva
+    (lambda (depth)
+        (lambda (vec1)
+            (lambda (vec2)
+                (lambda (carry)
+                    ((lc_cons ((lc_cons vec1) vec2)) ((lc_cons depth) carry))
+                )
+            )
+        )
+    )
+)
+
+(define lbva-depth
+    (lambda (lbva)
+        (lc_car (lc_cdr lbva))
+    )
+)
+
+(define lbva-vec1
+    (lambda (lbva)
+        (lc_car (lc_car lbva))
+    )
+)
+
+(define lbva-vec2
+    (lambda (lbva)
+        (lc_cdr (lc_car lbva))
+    )
+)
+
+(define lbva-carry
+    (lambda (lbva)
+        (lc_cdr (lc_cdr lbva))
+    )
+)
+    
+
+(define lc-bit-vector-add
+    (lambda (depth)
+        (lambda (vec1)
+            (lambda (vec2)
+                ((Y
+                    (lambda (f)
+                        (lambda (x)
+                            (begin
+                                ;(display "depth = ")
+                                ;(display (church->int (lbva-depth x)))
+                                ;(newline)
+                            
+                            ((((is-zero? (lbva-depth x))
+                                (lambda (no_use)
+                                    (((lc-full-adder 
+                                        (lbva-vec1 x))
+                                        (lbva-vec2 x))
+                                        (lbva-carry x)
+                                    )
+                                ))
+                                (lambda (no_use)
+                                    ((lambda (first-part-sum)
+                                        ((lambda (second-part-sum)
+                                            (begin
+                                                ;(display first-part-sum)
+                                                ;(newline)
+                                                ;(display second-part-sum)
+                                                ;(newline)
+                                            ((make-result-and-carry
+                                                ((lc_cons 
+                                                    (r-c-result first-part-sum))
+                                                    (r-c-result second-part-sum)))
+                                                (r-c-carry second-part-sum)
+                                            )
+                                            )
+                                        )
+                                        
+                                            (f ((((make-lbva
+                                                (pred (lbva-depth x)))
+                                                (lc_cdr (lbva-vec1 x)))
+                                                (lc_cdr (lbva-vec2 x)))
+                                                (r-c-carry first-part-sum)
+                                            ))
+                                        )
+                                   )
+                                        (f 
+                                            ((((make-lbva 
+                                                (pred (lbva-depth x))) 
+                                                (lc_car (lbva-vec1 x))) 
+                                                (lc_car (lbva-vec2 x))) 
+                                                (lbva-carry x)
+                                            )
+                                        )
+                                   )
+                                ))
+                                    ; Pass zero as no_use
+                                    zero
+                            ))
+                        )
+                    )
+                ) 
+                ; This is the bootstrap for the Y combinator
+                ((((make-lbva depth) vec1) vec2) lc_false)
+                )
+            )
+        )
+    )
+)
+
+(define a (int->bit-vector 189))
+(display a)
+(newline)
+(define b (bit-vector->int (car a) (cadr a)))
+(display b)
+(newline)
+(define a (((lc-full-adder lc_true) lc_true) lc_true))
+(define t (greater-or-equal 5))
+
+(define (bool->lc bool) (if bool lc_true lc_false))
+(define bools-list (list #f #t))
+
+(define (test-full-adder)
+    (for-each 
+        (lambda (bit1)
+            (for-each
+                (lambda (bit2)
+                    (for-each
+                        (lambda (carry)
+                            (display (list bit1 bit2 carry))
+                            (display "    ")
+                            (display (full-adder-ret->scheme (((lc-full-adder (bool->lc bit1)) (bool->lc bit2)) (bool->lc carry))))
+                            (newline)
+                        )
+                        bools-list
+                    )               
+                )
+                bools-list
+            )
+        )
+        bools-list
+    )
+)
+
+;(test-full-adder)
+
+(define a_int 2000)
+(define b_int 1500)
+(define a (int->bit-vector a_int))
+(define b (int->bit-vector b_int))
+(if (not (= (cadr a) (cadr b)))
+    (error "the depths of a and b are not equal")
+)
+(define sum (((lc-bit-vector-add (int->church (cadr a))) (car a)) (car b)))
+(for-each display (list a_int "+" b_int " = " (bit-vector->int (r-c-result sum) (cadr a))))
+(newline)
+

File t2/lambda-calculus/index.html

+<html>
+<head>
+<title>File listing for </title>
+</head>
+<body bgcolor="#FFFFFF">
+<h1>File listing for </h1>
+<a href="add.scm">add.scm</a><br>
+<a href="index.html">index.html</a><br>
+<a href="lc_prelude.scm">lc_prelude.scm</a><br>
+</body>
+</html>

File t2/lambda-calculus/lc_prelude.scm

+; Boolean constants in lambda calculus.
+; -------------------------------------
+
+; Traditonally true and false are:
+(define lc_true  (lambda (x) (lambda (y) x)))
+(define lc_false (lambda (x) (lambda (y) y)))
+
+(define lc_cons
+    (lambda (mycar)
+        (lambda (mycdr)
+            ; we return this lambda-expression:
+            (lambda (which)
+                ((which mycar) mycdr)
+            )
+        )
+    )
+)
+
+(define lc_car
+    (lambda (tuple)
+        (tuple lc_true)
+    )
+)
+
+(define lc_cdr
+    (lambda (tuple)
+        (tuple lc_false)
+    )
+)
+
+; Boolean Operations in Lambda Calculus
+; -------------------------------------
+
+; Not:
+; Think of not(a) as
+; if a == true
+;      return false
+; else
+;      return true
+; end
+; Thus in lc it would become:
+(define lc_not
+    (lambda (x)
+            ((x lc_false) lc_true)
+    )
+)
+
+; And(x,y):
+; again, think of and as:
+; if x == true
+;      if b == true
+;          return true
+;      else
+;           return false
+;      end
+; else
+;      return false
+; end
+
+(define lc_and
+    (lambda (x)
+            (lambda (y)
+                    ((x ((y lc_true) lc_false)) lc_false)
+            )
+    )
+)
+
+; Or(x,y):
+; if x == true
+;     return true
+; else
+;     if y == true
+;         return true
+;     else
+;         return false
+;     end
+; end
+
+(define lc_or
+    (lambda (x)
+            (lambda (y)
+                    ((x lc_true) ((y lc_true) lc_false))
+            )
+    )
+)
+
+
+; Note, as opposed to the && and || operators in C or the "and" and "or" 
+; statements in Scheme, those ands and ors always evaluate both expressions.
+
+; Church Numerals
+; ---------------
+
+; But how to represent numbers in lambda calculus? Alonso Church, the 
+; logician who invented lambda calculus suggested the following method:
+(define zero (lambda (f) (lambda (x) x)))
+(define one  (lambda (f) (lambda (x) (f x))))
+(define two  (lambda (f) (lambda (x) (f (f x)))))
+(define three  (lambda (f) (lambda (x) (f (f (f x))))))
+
+; We take f and execute it on x N times
+
+; Converting Church numerals to regular integers:
+
+(define (church->int church)
+	(
+        (church 
+            (lambda (a) (+ a 1))
+        ) 
+            0
+    )
+)
+
+; Finding the successor to a Church numeral:
+; Let's take f and execute it on n one more time:
+(define succ 
+    (lambda (n) 
+	    (lambda (f) 
+    		(lambda (x) 
+    			(f ((n f) x))
+    		)
+    	)
+    )
+)
+
+; Converting an integer to a Church numeral
+(define (int->church n)
+	(if (= n 0)
+		zero
+		(succ (int->church (- n 1)))
+	)
+)
+
+; Operations with Church Numerals
+; -------------------------------
+
+; We already saw how to get the number that follows a given number. Now
+; how to do addition, substraction, multiplication, etc.
+
+; Addition:
+; We can repeat succ on m for n times in order to add n to m:
+
+; We can evaluate it into:
+(define add
+    (lambda (m)
+        (lambda (n)
+            (lambda (f)
+                (lambda (x)
+                    ((m f) 
+                        ((n f) x)
+                    )
+                )
+            )
+        )
+    )
+)
+
+; Now let's try multiplication. Since a church numeral is basically about
+; repeating something n times, we can repeat the other multiplicand N times.
+
+(define mult
+    (lambda (m)
+        (lambda (n)
+            (lambda (f)
+                (m (n f))
+            )
+        )
+    )
+)
+
+; Power: we can repeat the LC's mult m times
+
+(define power
+    (lambda (m)
+        (lambda (n)
+            ((n (mult m)) (succ zero))
+        )
+    )
+)
+
+; This, in turn can be simplified into:
+
+(define power
+    (lambda (m)
+        (lambda (n)
+            (n m)
+        )
+    )
+)
+
+; Displays 1, which is another proof that 0^0 is 1.
+
+; Predecessor
+; -----------
+
+; Getting the predecessor in Church numerals is quite tricky. 
+; Let's consider the following method:
+;
+; Create a pair [0,0] and convert it into the pair [0,1]. (what
+; we do is take the cdr and put it in the car and set the cdr to it plus
+; 1).
+; 
+; Then into [1,2], [2,3], etc. Repeat this process N times and 
+; we'll get [N-1, N].
+;
+; Then we can return the first element of the final pair which is N-1.
+
+(define pred_next_tuple
+    (lambda (tuple)
+        ((lc_cons
+            (lc_cdr tuple))       
+            (succ (lc_cdr tuple)))
+    )
+)
+; Note that we base the next tuple on the second item of the original tuple.
+
+(define pred
+    (lambda (n)
+        (lc_car 
+            ((n pred_next_tuple) 
+                ; A tuple with two zeros.
+                ((lc_cons zero) zero)
+            )
+        )
+    )
+)
+
+; Note that the pred of zero is zero, because there isn't -1 in church numerals
+
+; Subtraction is simply repeating pred m times
+
+(define subtract
+    (lambda (n)
+        (lambda (m)
+            ((m pred) n)
+        )
+    )
+)
+
+
+; Now, how do we compare two Church numerals? We can subtract the
+; first one from the second one. If the result is equal to zero, then the 
+; second one is greater or equal to the first.
+
+(define is-zero?
+    (lambda (n)
+            ((n (lambda (x) lc_false)) lc_true)
+    )
+)
+
+(define less-or-equal
+    (lambda (x)
+            (lambda (y)
+                    (is-zero? ((subtract x) y))
+            )
+    )
+)
+
+; In a similiar way and by using not we can define all other comparison 
+; operators.
+
+
+; Division and modulo? For this we need the Y combinator.
+; Stay tuned...
+
+; Operations with Church Numerals
+; -------------------------------
+
+; We already saw how to get the number that follows a given number. Now
+; how to do addition, substraction, multiplication, etc.
+
+; Addition:
+; We can repeat succ on m for n times in order to add n to m:
+
+(define add
+    (lambda (n)
+        (lambda (m)
+            ((n succ) m)
+        )    
+    )
+)
+
+; We can evaluate it into:
+(define add
+    (lambda (m)
+        (lambda (n)
+            (lambda (f)
+                (lambda (x)
+                    ((m f) 
+                        ((n f) x)
+                    )
+                )
+            )
+        )
+    )
+)
+
+; Now let's try multiplication. Since a church numeral is basically about
+; repeating something n times, we can repeat the other multiplicand N times.
+
+(define mult
+    (lambda (m)
+        (lambda (n)
+            (lambda (f)
+                (m (n f))
+            )
+        )
+    )
+)
+
+; Power: we can repeat the LC's mult m times
+
+(define power
+    (lambda (m)
+        (lambda (n)
+            ((n (mult m)) (succ zero))
+        )
+    )
+)
+
+; This, in turn can be simplified into:
+
+(define power
+    (lambda (m)
+        (lambda (n)
+            (n m)
+        )
+    )
+)
+
+; Displays 1, which is another proof that 0^0 is 1.
+
+; Predecessor
+; -----------
+
+; Getting the predecessor in Church numerals is quite tricky. 
+; Let's consider the following method:
+;
+; Create a pair [0,0] and convert it into the pair [0,1]. (what
+; we do is take the cdr and put it in the car and set the cdr to it plus
+; 1).
+; 
+; Then into [1,2], [2,3], etc. Repeat this process N times and 
+; we'll get [N-1, N].
+;
+; Then we can return the first element of the final pair which is N-1.
+
+(define pred_next_tuple
+    (lambda (tuple)
+        ((lc_cons
+            (lc_cdr tuple))       
+            (succ (lc_cdr tuple)))
+    )
+)
+; Note that we base the next tuple on the second item of the original tuple.
+
+(define pred
+    (lambda (n)
+        (lc_car 
+            ((n pred_next_tuple) 
+                ; A tuple with two zeros.
+                ((lc_cons zero) zero)
+            )
+        )
+    )
+)
+
+; Note that the pred of zero is zero, because there isn't -1 in church numerals
+
+; Subtraction is simply repeating pred m times
+
+(define subtract
+    (lambda (n)
+        (lambda (m)
+            ((m pred) n)
+        )
+    )
+)
+
+
+; Now, how do we compare two Church numerals? We can subtract the
+; first one from the second one. If the result is equal to zero, then the 
+; second one is greater or equal to the first.
+
+(define is-zero?
+    (lambda (n)
+            ((n (lambda (x) lc_false)) lc_true)
+    )
+)
+
+(define less-or-equal
+    (lambda (x)
+            (lambda (y)
+                    (is-zero? ((subtract x) y))
+            )
+    )
+)
+
+; In a similiar way and by using not we can define all other comparison 
+; operators.
+
+
+; Division and modulo? For this we need the Y combinator.
+; Stay tuned...
+
+(define Y
+    (lambda (f)
+        (
+            (lambda (x)
+                    (f (lambda (y) ((x x) y)))
+            )
+            (lambda (x)
+                    (f (lambda (y) ((x x) y)))
+            )
+        )
+    )
+)
+
+
+

File t2/lame/lame.zip

Binary file added.

File vipe/haskell/index.html

-<html>
-<head>
-<title>Haskell Programs</title>
-</head>
-<body bgcolor="#FFFFFF">
-
-<h1>Shlomi Fish' Haskell Programs</h1>
-
-<p>
-<a href="primes.zip">primes.zip</a> - a case study I made for various
-algorithms for finding prime numbers. The code is the documentation for the
-while.
-</p>
-
-</body>
-</html>

File vipe/haskell/primes.zip

Binary file removed.

File vipe/lambda-calculus/add.scm

-(load "lc_prelude.scm")
-
-(define lc-bit->church 
-    (lambda (bit)
-        ((bit one) zero)
-    )
-)
-
-(define lc-full-adder-ret-make
-    (lambda (bit)
-        (lambda (carry)
-            ((lc_cons bit) carry)
-        )
-    )
-)
-
-(define lc-full-adder-ret-get-bit lc_car)
-(define lc-full-adder-ret-get-carry lc_cdr)
-
-(define lc_xor
-    (lambda (x)
-        (lambda (y)
-            ; If x then:
-            ((x 
-                ; If-part
-                ((y lc_false) lc_true)) 
-                ; Else-part
-                ((y lc_true) lc_false)
-            )
-        )
-    )
-)
-
-(define greater-or-equal
-    (lambda (x)
-            (lambda (y)
-                    (is-zero? ((subtract y) x))
-            )
-    )
-)
-
-
-(define lc-full-adder
-    (lambda (bit1)
-        (lambda (bit2)
-            (lambda (carry)
-                ((lambda (num-bits)
-                    ((lc-full-adder-ret-make
-                        ((lc_xor ((lc_xor bit1) bit2)) carry))
-                        ((greater-or-equal num-bits) two)
-                    )
-                )
-                    ((add 
-                        ((add 
-                            (lc-bit->church bit1)) 
-                            (lc-bit->church bit2)
-                        ))
-                        (lc-bit->church carry)
-                    )
-                )
-            )
-        )
-    )
-)
-
-(define (int->bit-vector num)
-    (define (get-num-bits num num-bits)
-        (if (= num 0)
-            num-bits
-            (get-num-bits (quotient num 2) (1+ num-bits))
-        )
-    )
-    (define (myconvert num num-bits-log2)
-        (if (= num-bits-log2 0)
-            ; Put a single bit
-            (if (= num 0) lc_false lc_true)
-            (let*
-                (
-                    (next-log2 (-1+ num-bits-log2))
-                    (exp2 (expt 2 (expt 2 next-log2)))
-                )
-                ((lc_cons 
-                    (myconvert (remainder num exp2) next-log2))
-                    (myconvert (quotient num exp2) next-log2)
-                    )
-            )
-        )
-    )
-    (let* 
-        (
-            (num-bits (get-num-bits num 0))
-            (num-bits-log2 (get-num-bits num-bits 0))
-        )
-        
-        (list (myconvert num num-bits-log2) num-bits-log2)
-    )
-)
-
-(define (bit-vector->int vec depth)
-    (if (= depth 0)
-        ; Get the numerical value of the bit
-        ((vec 1) 0)
-        ; int = int(car(vec)) | int(car(vec)) << (2**depth)
-        (+ 
-            (bit-vector->int (lc_car vec) (- depth 1))
-            (* 
-                (expt 2 (expt 2 (- depth 1)))
-                (bit-vector->int (lc_cdr vec) (- depth 1))
-            )
-        )
-    )
-)
-
-(define (bit-vector-lc->scheme vec depth)
-    (if (= depth 0)
-        ((vec 1) 0)
-        (cons 
-            (bit-vector-lc->scheme (lc_car vec) (-1+ depth))
-            (bit-vector-lc->scheme (lc_cdr vec) (-1+ depth))
-        )
-    )
-)
-
-(define (full-adder-ret->scheme fa-ret)
-    (list 
-        (((lc_car fa-ret) 1) 0)
-        (((lc_cdr fa-ret) 1) 0)
-    )
-)
-
-(define make-result-and-carry
-    (lambda (result)
-        (lambda (carry)
-            ((lc_cons result) carry)
-        )
-    )
-)
-
-(define r-c-result
-    (lambda (r-c)
-        (lc_car r-c)
-    )
-)
-
-(define r-c-carry
-    (lambda (r-c)
-        (lc_cdr r-c)    
-    )
-)
-
-(define make-lbva
-    (lambda (depth)
-        (lambda (vec1)
-            (lambda (vec2)
-                (lambda (carry)
-                    ((lc_cons ((lc_cons vec1) vec2)) ((lc_cons depth) carry))
-                )
-            )
-        )
-    )
-)
-
-(define lbva-depth
-    (lambda (lbva)
-        (lc_car (lc_cdr lbva))
-    )
-)
-
-(define lbva-vec1
-    (lambda (lbva)
-        (lc_car (lc_car lbva))
-    )
-)
-
-(define lbva-vec2
-    (lambda (lbva)
-        (lc_cdr (lc_car lbva))
-    )
-)
-
-(define lbva-carry
-    (lambda (lbva)
-        (lc_cdr (lc_cdr lbva))
-    )
-)
-    
-
-(define lc-bit-vector-add
-    (lambda (depth)
-        (lambda (vec1)
-            (lambda (vec2)
-                ((Y
-                    (lambda (f)
-                        (lambda (x)
-                            (begin
-                                ;(display "depth = ")
-                                ;(display (church->int (lbva-depth x)))
-                                ;(newline)
-                            
-                            ((((is-zero? (lbva-depth x))
-                                (lambda (no_use)
-                                    (((lc-full-adder 
-                                        (lbva-vec1 x))
-                                        (lbva-vec2 x))
-                                        (lbva-carry x)
-                                    )
-                                ))
-                                (lambda (no_use)
-                                    ((lambda (first-part-sum)
-                                        ((lambda (second-part-sum)
-                                            (begin
-                                                ;(display first-part-sum)
-                                                ;(newline)
-                                                ;(display second-part-sum)
-                                                ;(newline)
-                                            ((make-result-and-carry
-                                                ((lc_cons 
-                                                    (r-c-result first-part-sum))
-                                                    (r-c-result second-part-sum)))
-                                                (r-c-carry second-part-sum)
-                                            )
-                                            )
-                                        )
-                                        
-                                            (f ((((make-lbva
-                                                (pred (lbva-depth x)))
-                                                (lc_cdr (lbva-vec1 x)))
-                                                (lc_cdr (lbva-vec2 x)))
-                                                (r-c-carry first-part-sum)
-                                            ))
-                                        )
-                                   )
-                                        (f 
-                                            ((((make-lbva 
-                                                (pred (lbva-depth x))) 
-                                                (lc_car (lbva-vec1 x))) 
-                                                (lc_car (lbva-vec2 x))) 
-                                                (lbva-carry x)
-                                            )
-                                        )
-                                   )
-                                ))
-                                    ; Pass zero as no_use
-                                    zero
-                            ))
-                        )
-                    )
-                ) 
-                ; This is the bootstrap for the Y combinator
-                ((((make-lbva depth) vec1) vec2) lc_false)
-                )
-            )
-        )
-    )
-)
-
-(define a (int->bit-vector 189))
-(display a)
-(newline)
-(define b (bit-vector->int (car a) (cadr a)))
-(display b)
-(newline)
-(define a (((lc-full-adder lc_true) lc_true) lc_true))
-(define t (greater-or-equal 5))
-
-(define (bool->lc bool) (if bool lc_true lc_false))
-(define bools-list (list #f #t))
-
-(define (test-full-adder)
-    (for-each 
-        (lambda (bit1)
-            (for-each
-                (lambda (bit2)
-                    (for-each
-                        (lambda (carry)
-                            (display (list bit1 bit2 carry))
-                            (display "    ")
-                            (display (full-adder-ret->scheme (((lc-full-adder (bool->lc bit1)) (bool->lc bit2)) (bool->lc carry))))
-                            (newline)
-                        )
-                        bools-list
-                    )               
-                )
-                bools-list
-            )
-        )
-        bools-list
-    )
-)
-
-;(test-full-adder)
-
-(define a_int 2000)
-(define b_int 1500)
-(define a (int->bit-vector a_int))
-(define b (int->bit-vector b_int))
-(if (not (= (cadr a) (cadr b)))
-    (error "the depths of a and b are not equal")
-)
-(define sum (((lc-bit-vector-add (int->church (cadr a))) (car a)) (car b)))
-(for-each display (list a_int "+" b_int " = " (bit-vector->int (r-c-result sum) (cadr a))))
-(newline)
-

File vipe/lambda-calculus/index.html

-<html>
-<head>
-<title>File listing for </title>
-</head>
-<body bgcolor="#FFFFFF">
-<h1>File listing for </h1>
-<a href="add.scm">add.scm</a><br>
-<a href="index.html">index.html</a><br>
-<a href="lc_prelude.scm">lc_prelude.scm</a><br>
-</body>
-</html>

File vipe/lambda-calculus/lc_prelude.scm

-; Boolean constants in lambda calculus.
-; -------------------------------------
-
-; Traditonally true and false are:
-(define lc_true  (lambda (x) (lambda (y) x)))
-(define lc_false (lambda (x) (lambda (y) y)))
-
-(define lc_cons
-    (lambda (mycar)
-        (lambda (mycdr)
-            ; we return this lambda-expression:
-            (lambda (which)
-                ((which mycar) mycdr)
-            )
-        )
-    )
-)
-
-(define lc_car
-    (lambda (tuple)
-        (tuple lc_true)
-    )
-)
-
-(define lc_cdr
-    (lambda (tuple)
-        (tuple lc_false)
-    )
-)
-
-; Boolean Operations in Lambda Calculus
-; -------------------------------------
-
-; Not:
-; Think of not(a) as
-; if a == true
-;      return false
-; else
-;      return true
-; end
-; Thus in lc it would become:
-(define lc_not
-    (lambda (x)
-            ((x lc_false) lc_true)
-    )
-)
-
-; And(x,y):
-; again, think of and as:
-; if x == true
-;      if b == true
-;          return true
-;      else
-;           return false
-;      end
-; else
-;      return false
-; end
-
-(define lc_and
-    (lambda (x)
-            (lambda (y)
-                    ((x ((y lc_true) lc_false)) lc_false)
-            )
-    )
-)
-
-; Or(x,y):
-; if x == true
-;     return true
-; else
-;     if y == true
-;         return true
-;     else
-;         return false
-;     end
-; end
-
-(define lc_or
-    (lambda (x)
-            (lambda (y)
-                    ((x lc_true) ((y lc_true) lc_false))
-            )
-    )
-)
-
-
-; Note, as opposed to the && and || operators in C or the "and" and "or" 
-; statements in Scheme, those ands and ors always evaluate both expressions.
-
-; Church Numerals
-; ---------------
-
-; But how to represent numbers in lambda calculus? Alonso Church, the 
-; logician who invented lambda calculus suggested the following method:
-(define zero (lambda (f) (lambda (x) x)))
-(define one  (lambda (f) (lambda (x) (f x))))
-(define two  (lambda (f) (lambda (x) (f (f x)))))
-(define three  (lambda (f) (lambda (x) (f (f (f x))))))
-
-; We take f and execute it on x N times
-
-; Converting Church numerals to regular integers:
-
-(define (church->int church)
-	(
-        (church 
-            (lambda (a) (+ a 1))
-        ) 
-            0
-    )
-)
-
-; Finding the successor to a Church numeral:
-; Let's take f and execute it on n one more time:
-(define succ 
-    (lambda (n) 
-	    (lambda (f) 
-    		(lambda (x) 
-    			(f ((n f) x))
-    		)
-    	)
-    )
-)
-
-; Converting an integer to a Church numeral
-(define (int->church n)
-	(if (= n 0)
-		zero
-		(succ (int->church (- n 1)))
-	)
-)
-
-; Operations with Church Numerals
-; -------------------------------
-
-; We already saw how to get the number that follows a given number. Now
-; how to do addition, substraction, multiplication, etc.
-
-; Addition:
-; We can repeat succ on m for n times in order to add n to m:
-
-; We can evaluate it into:
-(define add
-    (lambda (m)
-        (lambda (n)
-            (lambda (f)
-                (lambda (x)
-                    ((m f) 
-                        ((n f) x)
-                    )
-                )
-            )
-        )
-    )
-)
-
-; Now let's try multiplication. Since a church numeral is basically about
-; repeating something n times, we can repeat the other multiplicand N times.
-
-(define mult
-    (lambda (m)
-        (lambda (n)
-            (lambda (f)
-                (m (n f))
-            )
-        )
-    )
-)
-
-; Power: we can repeat the LC's mult m times
-
-(define power
-    (lambda (m)
-        (lambda (n)
-            ((n (mult m)) (succ zero))
-        )
-    )
-)
-
-; This, in turn can be simplified into:
-
-(define power
-    (lambda (m)
-        (lambda (n)
-            (n m)
-        )
-    )
-)
-
-; Displays 1, which is another proof that 0^0 is 1.
-
-; Predecessor
-; -----------
-
-; Getting the predecessor in Church numerals is quite tricky. 
-; Let's consider the following method:
-;
-; Create a pair [0,0] and convert it into the pair [0,1]. (what
-; we do is take the cdr and put it in the car and set the cdr to it plus
-; 1).
-; 
-; Then into [1,2], [2,3], etc. Repeat this process N times and 
-; we'll get [N-1, N].
-;
-; Then we can return the first element of the final pair which is N-1.
-
-(define pred_next_tuple
-    (lambda (tuple)
-        ((lc_cons
-            (lc_cdr tuple))       
-            (succ (lc_cdr tuple)))
-    )
-)
-; Note that we base the next tuple on the second item of the original tuple.
-
-(define pred
-    (lambda (n)
-        (lc_car 
-            ((n pred_next_tuple) 
-                ; A tuple with two zeros.
-                ((lc_cons zero) zero)
-            )
-        )
-    )
-)
-
-; Note that the pred of zero is zero, because there isn't -1 in church numerals
-
-; Subtraction is simply repeating pred m times
-
-(define subtract
-    (lambda (n)
-        (lambda (m)
-            ((m pred) n)
-        )
-    )
-)
-
-
-; Now, how do we compare two Church numerals? We can subtract the
-; first one from the second one. If the result is equal to zero, then the 
-; second one is greater or equal to the first.
-
-(define is-zero?
-    (lambda (n)
-            ((n (lambda (x) lc_false)) lc_true)
-    )
-)
-
-(define less-or-equal
-    (lambda (x)
-            (lambda (y)
-                    (is-zero? ((subtract x) y))
-            )
-    )
-)
-
-; In a similiar way and by using not we can define all other comparison 
-; operators.
-
-
-; Division and modulo? For this we need the Y combinator.
-; Stay tuned...
-
-; Operations with Church Numerals
-; -------------------------------
-
-; We already saw how to get the number that follows a given number. Now
-; how to do addition, substraction, multiplication, etc.
-
-; Addition:
-; We can repeat succ on m for n times in order to add n to m:
-
-(define add
-    (lambda (n)
-        (lambda (m)
-            ((n succ) m)
-        )    
-    )
-)
-
-; We can evaluate it into:
-(define add
-    (lambda (m)
-        (lambda (n)
-            (lambda (f)
-                (lambda (x)
-                    ((m f) 
-                        ((n f) x)
-                    )
-                )
-            )
-        )
-    )
-)
-
-; Now let's try multiplication. Since a church numeral is basically about
-; repeating something n times, we can repeat the other multiplicand N times.
-
-(define mult
-    (lambda (m)
-        (lambda (n)
-            (lambda (f)
-                (m (n f))
-            )
-        )
-    )
-)
-
-; Power: we can repeat the LC's mult m times
-
-(define power
-    (lambda (m)
-        (lambda (n)
-            ((n (mult m)) (succ zero))
-        )
-    )
-)
-
-; This, in turn can be simplified into:
-
-(define power
-    (lambda (m)
-        (lambda (n)
-            (n m)
-        )
-    )
-)
-
-; Displays 1, which is another proof that 0^0 is 1.
-
-; Predecessor
-; -----------
-
-; Getting the predecessor in Church numerals is quite tricky. 
-; Let's consider the following method:
-;
-; Create a pair [0,0] and convert it into the pair [0,1]. (what
-; we do is take the cdr and put it in the car and set the cdr to it plus
-; 1).
-; 
-; Then into [1,2], [2,3], etc. Repeat this process N times and 
-; we'll get [N-1, N].
-;
-; Then we can return the first element of the final pair which is N-1.
-
-(define pred_next_tuple
-    (lambda (tuple)
-        ((lc_cons
-            (lc_cdr tuple))       
-            (succ (lc_cdr tuple)))
-    )
-)
-; Note that we base the next tuple on the second item of the original tuple.
-
-(define pred
-    (lambda (n)
-        (lc_car 
-            ((n pred_next_tuple) 
-                ; A tuple with two zeros.
-                ((lc_cons zero) zero)
-            )
-        )
-    )
-)
-
-; Note that the pred of zero is zero, because there isn't -1 in church numerals
-
-; Subtraction is simply repeating pred m times
-
-(define subtract
-    (lambda (n)
-        (lambda (m)
-            ((m pred) n)
-        )
-    )
-)
-
-
-; Now, how do we compare two Church numerals? We can subtract the
-; first one from the second one. If the result is equal to zero, then the 
-; second one is greater or equal to the first.
-
-(define is-zero?
-    (lambda (n)
-            ((n (lambda (x) lc_false)) lc_true)
-    )
-)
-
-(define less-or-equal
-    (lambda (x)
-            (lambda (y)
-                    (is-zero? ((subtract x) y))
-            )
-    )
-)
-
-; In a similiar way and by using not we can define all other comparison 
-; operators.
-
-
-; Division and modulo? For this we need the Y combinator.
-; Stay tuned...
-
-(define Y
-    (lambda (f)
-        (
-            (lambda (x)
-                    (f (lambda (y) ((x x) y)))
-            )
-            (lambda (x)
-                    (f (lambda (y) ((x x) y)))
-            )
-        )
-    )
-)
-
-
-

File vipe/lame/lame.zip

Binary file removed.