Programme

Ich gebe ein paar Programme an, die ich in Lisp geschrieben habe.

Rechnen ist mühsam. Euklid hatte dazu vielleicht einen schlauen Sklaven. Wir verwenden den Computer. Ich möchte die Programmiersprache Lisp verwenden, da sie besonders nahe an der Mathematik angesiedelt ist. Außerdem enthält sie schon eine Arithmetik mit exakten rationalen Zahlen. Ist a = q . b + r wie im Satz so bezeichne ich (mod a b):=r. Das ist die gleiche Bezeichnung wie in Lisp.

 (mod 17 12) ===> 5
 (mod 17/3 8/7) ===> 23/21

(defun ggM(a b)
  "Ergibt das groesste gemeinsame Mass von a und b"
(if   (= b 0) a
  (ggM b  (mod a b)))
)
(ggM 17/9 7/5) ===> 1/45

(defconst winzigklein 0.00000000000001)
(load-library "cl")
Die Library cl wird geladen um die Möglichkeiten von Common Lisp zu nutzen.
(defun punkt(&rest a)
  "Ruft man (punkt 1 2 3) auf so ergibt sich: 
   ===> (1.0 2.0 3.0)"
(mapcar 'float a))
 (defun iota(a n)
  "Bettet den Vektor in eine Vektorraum groesserer Dimension ein
   es werden genuegend viele Nullen dreangehaengt"
 (append a (make-list (- n (length a)) 0.0))
)

(defun v+(a b)
 "Ergibt die Summe zweier Vektoren"
 (cond ((< (length a) (length b)) (mapcar* '+ (iota a (length b)) b))
       ((> (length a) (length b)) (mapcar* '+ a (iota b (length a))))
       ((= (length a) (length b)) (mapcar* '+ a b))
 )
)

(defun v-(a b)
 (cond ((< (length a) (length b)) (mapcar* '- (iota a (length b)) b))
       ((> (length a) (length b)) (mapcar* '- a (iota b (length a))))
       ((= (length a) (length b)) (mapcar* '- a b))
 )
)

(defun det2x2(a b)
 "Ergibt die 2x2 Determinante zweier zweidimensionaler Vektoren"
  (- (* (nth 0 a) (nth 1 b)) (* (nth 1 a) (nth 0 b)))
)
(defun imstreifen( punkt vs u)
    (and (< (det2x2 u (punkt 1 0)) (det2x2 u (v- punkt vs)))
         (<= (det2x2 u (v- punkt vs)) (det2x2 u (punkt 0 1))))
)
Die Operationen v+ und v- addieren beziehungsweise subtrahieren Vektoren. det2x2 gibt die Determinante einer quadratischen Matrix mit zwei Zeilen an.

 
(defun musterwort(vs breite u)
(let ((i 0)
      (p (punkt (ceiling (nth 0 vs)) (ceiling (nth 1 vs))))
      (pn (v+ p (punkt 1 0)))
      (wort "")
      )
(while (< i breite)
    (setq pn (v+ p (punkt 1 0)))
    (if (imstreifen pn vs u) 
        (setq wort (concat wort "r")
               p pn)
        (setq wort (concat wort "h")
         p (v+ p (punkt 0 1)))
      ) 
(setq i (+ 1 i))     
)
wort
)
)
(setq vs (punkt 0 0) phi (/ (+ 1 (sqrt 5)) 2)
       u (punkt phi 1))


(setq vs (punkt 0 0) phi (+ 1 (sqrt 2))
       u (punkt phi 1))

(musterwort (punkt 0 0) 80 u)
 "hrrrhrrhrrrhrrhrrrhrrhrrhrrrhrrhrrrhrrhrrhrrrhrrhrrrhrrhrrrhrrhrrhrrrhrrhrrrhrrh"
 "hrrhrrhrhrrhrrhrhrrhrhrrhrrhrhrrhrrhrhrrhrhrrhrrhrhrrhrhrrhrrhrhrrhrrhrhrrhrhrrh"
 "hrrhrrhrhrrhrrhrhrrhrhrrhrrhrhrrhrrhrhrrhrhrrhrrhrhrrhrhrrhr"
(musterwort (punkt 0 (sqrt 2)) 60 u)
 "hrrhrrhrhrrhrrhrhrrhrhrrhrrhrhrrhrrhrhrrhrhrrhrrhrhrrhrhrrhr"
"rhrrhrrhrhrrhrrhrhrrhrhrrhrrhrhrrhrhrrhrrhrhrrhrrhrhrrhrhrrh"
"hrrhrrhrhrrhrrhrhrrhrhrrhrrhrh"
"hrrhrrhrhrrhrrhrhrrhrhrrhrrhrh"

"h"
"hr"
"hrrhr"
"hrrhrrhrhrrhr"
"hrrhrrhrhrrhrrhrhrrhrhrrhrrhrhrrhr"

(setq vs (punkt 0 0) phi (+ 1 (sqrt 2))
       u (punkt phi 1))
(musterwort (punkt 0 0) 8 u)
"hrrrhrrh"
"hrrrhrr"
"hrr|rhrrhrr|rhrrhrr|rhrrhrr|hrr|rhrrhrr|rhrrhrr|hrr|rhrrhrrrhrrhrrrh"
"hrr|rhrrhrr|rhrrhrr|rhrrhrr|hrr|rhr"

"h"
"hrrrhrrhrrrhrr"
"hrrrhrrhrr"
"hrrrhrr"

Andreas Bartholome
2004-10-27