Partial Answers to Rec 9
9.2
> (setq r1 (/ (+ (- b) (sqrt (- (* b b) (* a c 4L0)))) (* 2L0 a) ))
1.6180339887498948482L0
> (setq r1 (/ (- (- b) (sqrt (- (* b b) (* a c 4L0)))) (* 2L0 a) ))
-0.6180339887498948482L0
------------------------------------------
9.4
> (defun harm (n)
(cond
((= n 1) 1)
(t (+ (/ 1 n) (harm (1- n)))) ))
HARM
> (harm 10)
7381/2520
> (harm 20)
55835135/15519504
------------------------------------------
> (defun harm (n)
(cond
((= n 1) 1L0)
(t (+ (/ 1L0 n) (harm (1- n)))) ))
HARM
> (harm 10)
2.9289682539682539684L0
------------------------------------------
9.5
> (defun f(n)
(cond ((= n 0) 0)
((= n 1) 1)
(t (+ (f (1- n)) (f (- n 2)))) ))
F
> (f 10)
55
> (f 20)
6765
> (f 30)
832040 (6 seconds)
> (f 35)
9227465 (70 seconds)
(after compiling)
> (f 30)
832040 (2 seconds)
> (f 35)
9227465 (12 seconds)
------------------------------------------
9.6
> (defun sqr (a) (* a a))
SQR
> (defun pow (a b)
(cond ((= b 0) 1L0)
((> b 0)(* a (pow a (- b 1))))
(t (pow (/ 1L0 a) (- b) )) ))
POW
> (pow 2 -10)
9.765625L-4
> (pow (pow 2 -10) 10)
7.888609052210118054L-31
> (pow (pow 2 -10) -10)
1.2676506002282294015L30
------------------------------------------
9.7
> (defun pow (a b)
(cond ((= b 0) 1)
(t (* (pow a (1- b)) a)) ))
POW
> (SETF (EXT:LONG-FLOAT-DIGITS) 200)
200
(setq phi (/ (+ 1L0 (sqrt 5l0)) 2L0))
1.6180339887498948482045868343656381177203091798057628621354486227053L0
> (pow phi 100)
7.920708398483722531269999999999999999999987374866619361570578109776L20 =
792070839848372253126.9999999999999999999987374866619361570578109776
> (pow phi 121)
1.9386725908489881939795601000000000000000000000000051581685567756328L25 =
19386725908489881939795601.000000000000000000000000051581685567756328
------------------------------------------
9.8 a. b.
> (defun sqr (a) (* a a))
SQR
> (defun rtp (a b)
(princ '|rtp: |)(prin1 a)(princ '| |)(prin1 b)(terpri)
(cond ((= b 0) 1)
((< b 0) (rtp (/ 1 a) (- b) ))
((= (rem b 2) 0) (sqr (rtp a (/ b 2))))
(t (* a (sqr (rtp a (/ (1- b) 2))))) ))
RTP
> (rtp 7 23)
rtp: 7 23
rtp: 7 11
rtp: 7 5
rtp: 7 2
rtp: 7 1
rtp: 7 0
27368747340080916343
> (rtp 2 2143)
rtp: 2 2143
rtp: 2 1071
rtp: 2 535
rtp: 2 267
rtp: 2 133
rtp: 2 66
rtp: 2 33
rtp: 2 16
rtp: 2 8
rtp: 2 4
rtp: 2 2
rtp: 2 1
rtp: 2 0
1280208504496147879536757151501346598247767700808384824056269949281586845410140428570655004658446632171156255873813584603566604508719187209392408881752115721878449925841122814063052169274411195304507380386406346930112508549825064495772572662547879518878610056826895706997973238983411408891089983619246264598874443200316056422176354317651119974563776407204040441178038071701226728913070775474376251696747528133766494853220741527352680539014459515990498275757204823370269578341956623072977874976804864441052868382689183762460103808291244046216190050982246548673523422119818636196632614401163944328318638946715429911315024874141425080268348832350208
------------------------------------------
9.8 c.
At each recursive call, b is divided by 2, so b gets down to
1 in log2(b) calls.
------------------------------------------