summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/ricketyspace/sicp/one/thirtysix.scm113
1 files changed, 113 insertions, 0 deletions
diff --git a/net/ricketyspace/sicp/one/thirtysix.scm b/net/ricketyspace/sicp/one/thirtysix.scm
new file mode 100644
index 0000000..25e2c80
--- /dev/null
+++ b/net/ricketyspace/sicp/one/thirtysix.scm
@@ -0,0 +1,113 @@
+;;;; Under Creative Commons Attribution-ShareAlike 4.0
+;;;; International. See
+;;;; <https://creativecommons.org/licenses/by-sa/4.0/>.
+
+(define-module (net ricketyspace sicp one thirtysix)
+ #:export (fixed-point x-to-the-x-1000))
+
+(define tolerance 0.0000000000001)
+
+(define (fixed-point f first-guess)
+ (define (close-enough? v1 v2)
+ (< (abs (- v1 v2)) tolerance))
+ (define (try guess)
+ (let ((next (f guess)))
+ (display next)
+ (newline)
+ (if (close-enough? guess next)
+ next
+ (try next))))
+ (try first-guess))
+
+(define (x-to-the-x-1000)
+ (fixed-point (lambda (x) (/ (log 1000) (log x))) 1.1))
+
+;;; Guile REPL
+;;;
+;;; scheme@(guile-user)> ,use (net ricketyspace sicp one thirtysix)
+;;; scheme@(guile-user)> (x-to-the-x-1000)
+;;; 72.47657378429035p
+;;; 1.6127318474109593
+;;; 14.45350138636525
+;;; 2.5862669415385087
+;;; 7.269672273367045
+;;; 3.4822383620848467
+;;; 5.536500810236703
+;;; 4.036406406288111
+;;; 4.95053682041456
+;;; 4.318707390180805
+;;; 4.721778787145103
+;;; 4.450341068884912
+;;; 4.626821434106115
+;;; 4.509360945293209
+;;; 4.586349500915509
+;;; 4.535372639594589
+;;; 4.568901484845316
+;;; 4.546751100777536
+;;; 4.561341971741742
+;;; 4.551712230641226
+;;; 4.558059671677587
+;;; 4.55387226495538
+;;; 4.556633177654167
+;;; 4.554812144696459
+;;; 4.556012967736543
+;;; 4.555220997683307
+;;; 4.555743265552239
+;;; 4.555398830243649
+;;; 4.555625974816275
+;;; 4.555476175432173
+;;; 4.555574964557791
+;;; 4.555509814636753
+;;; 4.555552779647764
+;;; 4.555524444961165
+;;; 4.555543131130589
+;;; 4.555530807938518
+;;; 4.555538934848503
+;;; 4.555533575300744
+;;; 4.555537109821491
+;;; 4.555534778870584
+;;; 4.555536316089023
+;;; 4.555535302322066
+;;; 4.555535970882422
+;;; 4.555535529979327
+;;; 4.555535820746685
+;;; 4.555535628991034
+;;; 4.555535755450307
+;;; 4.555535672052776
+;;; 4.555535727051891
+;;; 4.555535690781
+;;; 4.5555357147009765
+;;; 4.555535698926199
+;;; 4.555535709329369
+;;; 4.5555357024686725
+;;; 4.555535706993175
+;;; 4.555535704009349
+;;; 4.555535705977127
+;;; 4.555535704679414
+;;; 4.555535705535232
+;;; 4.555535704970835
+;;; 4.555535705343044
+;;; 4.55553570509758
+;;; 4.555535705259459
+;;; 4.555535705152702
+;;; 4.555535705223107
+;;; 4.555535705176676
+;;; 4.555535705207297
+;;; 4.555535705187102
+;;; 4.555535705200421
+;;; 4.555535705191637
+;;; 4.555535705197429
+;;; 4.555535705193611
+;;; 4.555535705196128
+;;; 4.555535705194468
+;;; 4.555535705195563
+;;; 4.55553570519484
+;;; 4.555535705195317
+;;; 4.555535705195004
+;;; 4.555535705195211
+;;; 4.555535705195074
+;;; 4.5555357051951635
+;;; $6 = 4.5555357051951635
+;;; scheme@(guile-user)> (expt 4.5555357051951635 4.5555357051951635)
+;;; $7 = 1000.0000000000892
+