-
Notifications
You must be signed in to change notification settings - Fork 1
/
Exercise 3.75 zero-crossings on noisy signal.rkt
1479 lines (1400 loc) · 32 KB
/
Exercise 3.75 zero-crossings on noisy signal.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#lang racket
; Exercise 3.75. Unfortunately, Alyssa's zero-crossing detector in exercise 3.74 proves to be
; insufficient, because the noisy signal from the sensor leads to spurious zero crossings.
; Lem E. Tweakit, a hardware specialist, suggests that Alyssa smooth the signal to filter out
; the noise before extracting the zero crossings. Alyssa takes his advice and decides to
; extract the zero crossings from the signal constructed by averaging each value of the sense
; data with the previous value. She explains the problem to her assistant, Louis Reasoner, who
; attempts to implement the idea, altering Alyssa's program as follows:
; (define (make-zero-crossings input-stream last-value)
; (let ((avpt (/ (+ (stream-car input-stream) last-value) 2)))
; (cons-stream (sign-change-detector avpt last-value)
; (make-zero-crossings (stream-cdr input-stream)
; avpt))))
; This does not correctly implement Alyssa's plan. Find the bug that Louis has installed and
; fix it without changing the structure of the program. (Hint: You will need to increase the
; number of arguments to make-zero-crossings.)
; S O L U T I O N
; Explanation: Louis Reasoner's logic does not average the right quantities. Instead of
; averaging each value of the sensor data with the previous value, it averages each value
; with the previous *average*. So the smoothed signal will gradually drift away from the
; raw sensor signal.
; The attached graphs show how the different signals compare with each other. The first
; graph shows what happens when we do the two types of average-smoothing of a stream of
; random values. We can see that my implementation more closely tracks the raw signal
; than Louis' implementation.
;
; The second graph shows the same graphs for a values produced by a parabolic function:
; f(x) = x^2 - 15
; It is easy to see how Louis's stream of average values gradually diverges from the
; raw signal whereas my average stream tracks the raw stream more closely.
(define (make-zero-crossings input-stream last-avpt)
(let ((avpt (/ (+ (stream-first input-stream) (stream-first (stream-rest input-stream))) 2)))
(stream-cons
(sign-change-detector avpt last-avpt)
(make-zero-crossings (stream-rest input-stream) avpt)
)
)
)
(define (louis-reasoner-make-zero-crossings input-stream last-value)
(let ((avpt (/ (+ (stream-first input-stream) last-value) 2)))
(stream-cons
(sign-change-detector avpt last-value)
(louis-reasoner-make-zero-crossings (stream-rest input-stream) avpt)
)
)
)
(define (make-stream-of-averages input-stream)
(let ((avpt (/ (+ (stream-first input-stream) (stream-first (stream-rest input-stream))) 2)))
(stream-cons
avpt
(make-stream-of-averages (stream-rest input-stream))
)
)
)
(define (louis-reasoner-make-stream-of-averages input-stream last-value)
(let ((avpt (/ (+ (stream-first input-stream) last-value) 2)))
(stream-cons
avpt
(louis-reasoner-make-stream-of-averages (stream-rest input-stream) avpt)
)
)
)
; Proc to create a stream from a list
(define (make-stream-from-list l)
(if (not (null? l))
(stream-cons
(car l)
(make-stream-from-list (cdr l))
)
empty-stream
)
)
; Proc to create a stream of values from a function y = f(x)
(define (make-stream-from-function f starting-x-value x-increment)
(stream-cons
(f starting-x-value)
(make-stream-from-function f (+ starting-x-value x-increment) x-increment)
)
)
; Proc to create a stream of random values in the range (min, max)
(define (make-random-value-stream range-min range-max)
(if (<= range-max range-min)
(error "make-random-value-stream: range max needs to be larger than range-min")
(stream-cons
(+ (* (random) (- range-max range-min)) range-min)
(make-random-value-stream range-min range-max)
)
)
)
(define sense-data (make-stream-from-function sin 0 0.5))
(define (sign-change-detector a b)
(cond
((and (< a 0) (>= b 0))
1
)
((and (>= a 0) (< b 0))
-1
)
(else
0
)
)
)
(define (RC resistance capacitance dt)
(lambda (current-values-stream initial-capacitor-voltage)
(add-streams
(scale-stream current-values-stream resistance)
(integral
(scale-stream current-values-stream (/ 1.0 capacitance))
initial-capacitor-voltage
dt
)
)
)
)
(define (integral integrand initial-value dt)
(define int
(stream-cons
initial-value
(add-streams (scale-stream integrand dt) int)
)
)
int
)
(define (extract-three-consecutive-pairs-with-same-weight stream-of-pairs weight-proc)
(let ((p1 (stream-first stream-of-pairs))
(p2 (stream-first (stream-rest stream-of-pairs)))
(p3 (stream-first (stream-rest (stream-rest stream-of-pairs)))))
(let ((wp1 (weight-proc p1)) (wp2 (weight-proc p2)) (wp3 (weight-proc p3)))
(cond
((and (= wp1 wp2) (= wp2 wp3))
(stream-cons
(list wp1 p1 p2 p3)
(extract-three-consecutive-pairs-with-same-weight
(stream-rest stream-of-pairs)
weight-proc
)
)
)
((and (not (= wp1 wp2)) (= wp2 wp3))
(extract-three-consecutive-pairs-with-same-weight
(stream-rest stream-of-pairs)
weight-proc
)
)
(else
(extract-three-consecutive-pairs-with-same-weight
(stream-rest (stream-rest stream-of-pairs))
weight-proc
)
)
)
)
)
)
(define (extract-consecutive-pairs-with-same-weight stream-of-pairs weight-proc)
(let ((p1 (stream-first stream-of-pairs)) (p2 (stream-first (stream-rest stream-of-pairs))))
(if (= (weight-proc p1) (weight-proc p2))
(stream-cons
(list (weight-proc p1) p1 p2)
(extract-consecutive-pairs-with-same-weight
(stream-rest stream-of-pairs)
weight-proc
)
)
(extract-consecutive-pairs-with-same-weight
(stream-rest stream-of-pairs)
weight-proc
)
)
)
)
; This procedure displays 'count' number of elements from the supplied stream
; of pairs along with the weight of each pair
(define (display-pairs-with-weight stream-of-pairs count weight-proc)
(if (= 0 count)
(begin
(newline)
'done
)
(begin
(newline)
(display (stream-first stream-of-pairs))
(display " ")
(display (weight-proc (stream-first stream-of-pairs)))
(display-pairs-with-weight (stream-rest stream-of-pairs) (- count 1) weight-proc)
)
)
)
(define (weighted-pairs s t weight)
(stream-cons
(list (stream-first s) (stream-first t))
(merge-weighted
(stream-map (lambda (x) (list (stream-first s) x)) (stream-rest t))
(weighted-pairs (stream-rest s) (stream-rest t) weight)
weight
)
)
)
(define (merge-weighted s1 s2 weight)
(cond
((stream-empty? s1) s2)
((stream-empty? s2) s1)
(else
(let ((s1car (stream-first s1)) (s2car (stream-first s2)))
(cond
((< (weight s1car) (weight s2car))
(stream-cons s1car (merge-weighted (stream-rest s1) s2 weight))
)
((> (weight s1car) (weight s2car))
(stream-cons s2car (merge-weighted s1 (stream-rest s2) weight))
)
(else
(stream-cons
s1car
(stream-cons
s2car
(merge-weighted (stream-rest s1) (stream-rest s2) weight)
)
)
)
)
)
)
)
)
; The following procedure expects two ascending infinite streams,
; one of which needs to be a subset of the other. Let S be the stream with the superset
; and let T be the stream with the subset. Then this procedure will produce a new stream
; that contains all those elements that are present in S but not in T
(define (s-minus-t s t)
; Assumes that S and T are ordered ascending and T is a subset of S
(cond
((stream-empty? t) s)
((stream-empty? s) empty-stream)
(else
(let ((scar (stream-first s)) (tcar (stream-first t)))
(cond
((< scar tcar)
(stream-cons
scar
(s-minus-t (stream-rest s) t)
)
)
((> scar tcar)
(s-minus-t s (stream-rest t))
)
(else
(s-minus-t (stream-rest s) (stream-rest t))
)
)
)
)
)
)
; The following proc copied from SICP Exercise 3.56
(define (merge s1 s2)
(cond
((stream-empty? s1) s2)
((stream-empty? s2) s1)
(else
(let ((s1car (stream-first s1)) (s2car (stream-first s2)))
(cond
((< s1car s2car)
(stream-cons s1car (merge (stream-rest s1) s2))
)
((> s1car s2car)
(stream-cons s2car (merge s1 (stream-rest s2)))
)
(else
(stream-cons s1car
(merge (stream-rest s1) (stream-rest s2))
)
)
)
)
)
)
)
; Implementation of procedure triples
; The infinite streams S, T and U are represented as follows:
; S0 T0 U0
; S1 T1 U1
; S2 T2 U2
; S3 T3 U3
; S4 T4 U4
; . . .
; . . .
; . . .
; All triples (Si, Tj, Uk) such that i < j < k can be produced by combining the following:
; 1. (S0, T1, U2)
; 2. S0 combined with all the pairs produced using the streams (T1, T2, T3, ...) and
; (U1, U2, U3, ...) such that for every pair (Tj, Uk), j < k. We need to exclude the
; first element from this combined stream because the first element will be
; (S0, T1, U2) which is already accounted for.
; 3. triples called recursively on the streams (S1, S2, ...) (T1, T2, ...) and (U1, U2, ...)
(define (triples s t u)
(stream-cons
(list
(stream-first s)
(stream-first (stream-rest t))
(stream-first (stream-rest (stream-rest u)))
)
(interleave
(stream-map
(lambda (x) (cons (stream-first s) x))
(stream-rest (less-than-pairs (stream-rest t) (stream-rest u)))
)
(triples (stream-rest s) (stream-rest t) (stream-rest u))
)
)
)
(define (is-pythagorean-triple? triple)
; This procedure assumes that the elements in the triple are in increasing order
(= (+ (square (car triple)) (square (car (cdr triple)))) (square (car (cdr (cdr triple)))))
)
; This procedures produces all pairs (Si, Tj) where i < j
(define (less-than-pairs s t)
(stream-cons
(list (stream-first s) (stream-first (stream-rest t)))
(interleave
(stream-map (lambda (x) (list (stream-first s) x)) (stream-rest (stream-rest t)))
(less-than-pairs (stream-rest s) (stream-rest t))
)
)
)
(define (all-pairs s t)
(stream-cons
(list (stream-first s) (stream-first t))
(interleave
(stream-map (lambda (x) (list (stream-first s) x)) (stream-rest t))
(interleave
(stream-map (lambda (x) (list x (stream-first t))) (stream-rest s))
(all-pairs (stream-rest s) (stream-rest t))
)
)
)
)
(define (pairs s t)
(stream-cons
(list (stream-first s) (stream-first t))
(interleave
(stream-map (lambda (x) (list (stream-first s) x)) (stream-rest t))
(pairs (stream-rest s) (stream-rest t))
)
)
)
(define (interleave s1 s2)
(if (stream-empty? s1)
s2
(stream-cons
(stream-first s1)
(interleave s2 (stream-rest s1))
)
)
)
(define (partial-sums S)
(stream-cons (stream-first S) (add-streams (partial-sums S) (stream-rest S)))
)
(define (ln2-summands n)
(stream-cons
(/ 1.0 n)
(stream-map - (ln2-summands (+ n 1)))
)
)
(define ln2-stream
(partial-sums (ln2-summands 1))
)
(define (sqrt x tolerance)
(stream-limit (sqrt-stream x) tolerance)
)
(define (stream-limit s t)
(let ((s0 (stream-ref s 0)) (s1 (stream-ref s 1)))
(if (< (abs (- s1 s0)) t)
s1
(stream-limit (stream-rest s) t)
)
)
)
(define (sqrt-stream x)
(define guesses
(stream-cons
1.0
(stream-map
(lambda (guess) (sqrt-improve guess x))
guesses
)
)
)
guesses
)
(define (sqrt-improve guess x)
(average guess (/ x guess))
)
(define (average x y) (/ (+ x y) 2))
(define (square x) (* x x))
(define (cube x) (* x x x))
(define (euler-transform s)
(let ((s0 (stream-ref s 0)) ; Sn-1
(s1 (stream-ref s 1)) ; Sn
(s2 (stream-ref s 2))) ; Sn+1
(stream-cons
(-
s2
(/ (square (- s2 s1)) (+ s0 (* -2 s1) s2))
)
(euler-transform (stream-rest s))
)
)
)
(define (make-tableau transform s)
(stream-cons
s
(make-tableau transform (transform s))
)
)
(define (accelerated-sequence transform s)
(stream-map stream-first (make-tableau transform s))
)
(define (scale-stream stream factor)
(stream-map (lambda (x) (* x factor)) stream)
)
(define (stream-map proc . argstreams)
; (displayln "Entered stream-map")
(if (stream-empty? (car argstreams))
empty-stream
(stream-cons
(apply proc (map stream-first argstreams))
(apply stream-map (cons proc (map stream-rest argstreams)))
)
)
)
(define (stream-filter pred stream)
(cond
((stream-empty? stream) empty-stream)
((pred (stream-first stream))
(stream-cons
(stream-first stream)
(stream-filter pred (stream-rest stream))
)
)
(else
(stream-filter pred (stream-rest stream))
)
)
)
(define (stream-ref s n)
; (display "Entered stream-ref with n = ")
; (display n)
; (newline)
(if (= n 0)
(stream-first s)
(stream-ref (stream-rest s) (- n 1))
)
)
; This procedure produces a stream with a maximum number of count elements from
; the supplied stream
(define (truncate-stream s count)
(if (<= count 0)
empty-stream
(stream-cons
(stream-first s)
(truncate-stream (stream-rest s) (- count 1))
)
)
)
; This procedure displays a finite number of elements from the supplied stream
; as specified by 'count'
(define (display-stream-elements s count)
(if (= 0 count)
(begin
(newline)
'done
)
(begin
(newline)
(display (stream-first s))
(display-stream-elements (stream-rest s) (- count 1))
)
)
)
(define (display-stream s)
(stream-for-each display-line s)
)
(define (display-line x)
(newline)
(display x)
)
(define (indent-and-display pair)
(display-spaces (car pair))
(display pair)
(newline)
)
(define (display-spaces n)
(if (<= n 0)
(void)
(begin
(display " ")
(display-spaces (- n 1))
)
)
)
(define (div-series dividend-series divisor-series)
(cond
((= 0 (stream-first divisor-series))
(error "Denominator should not have a zero constant: " (stream-first divisor-series))
)
(else
(mul-series
dividend-series
(invert-unit-series (scale-stream divisor-series (/ 1 (stream-first divisor-series))))
)
)
)
)
(define (invert-unit-series s)
(stream-cons
1
(mul-series
(scale-stream (stream-rest s) -1)
(invert-unit-series s)
)
)
)
(define (mul-series s1 s2)
(stream-cons
; (a0 * b0) (The following is the constant term of the series resulting from
; the multiplication)
(* (stream-first s1) (stream-first s2))
; The following is the rest of the series starting with the x^1 term
(add-streams
; {a0 * (b1x + b2x^2 + b3x^3 + ...)} +
; {b0 * (a1x + a2x^2 + a3x^3 + ...)} +
(add-streams
(scale-stream (stream-rest s2) (stream-first s1))
(scale-stream (stream-rest s1) (stream-first s2))
)
; {(a1x + a2x^2 + a3x^3 + ...) * (b1x + b2x^2 + b3x^3 + ...)}
(stream-cons
; 0 needs to be prepended to this stream so that the first term of the stream
; is the x^1 term. Only then the outer add-streams will add like terms in the
; two series supplied to it
0
(mul-series (stream-rest s1) (stream-rest s2))
)
)
)
)
(define exp-series
(stream-cons 1 (integrate-series exp-series))
)
; the integral of negative sine is cosine
(define cosine-series
(stream-cons 1 (integrate-series (scale-stream sine-series -1)))
)
; the integral of cosine is sine
(define sine-series
(stream-cons 0 (integrate-series cosine-series))
)
(define tan-series
(div-series sine-series cosine-series)
)
(define (integrate-series s)
(div-streams s integers)
)
(define (add-streams s1 s2)
(stream-map + s1 s2)
)
(define (div-streams s1 s2)
(stream-map / s1 s2)
)
(define ones (stream-cons 1 ones))
(define integers (stream-cons 1 (add-streams ones integers)))
; Test Driver
(define (run-test return-type proc . args)
(define (print-item-list items first-time?)
(cond
((not (pair? items)) (void))
(else
(if (not first-time?)
(display ", ")
(void)
)
(print (car items))
(print-item-list (cdr items) false)
)
)
)
(display "Applying ")
(display proc)
(if (not (null? args))
(begin
(display " on: ")
(print-item-list args true)
)
(void)
)
(newline)
(let ((result (apply proc args)))
(if (not (eq? return-type 'none))
(display "Result: ")
(void)
)
(cond
((procedure? result) ((result 'print)))
; ((eq? return-type 'deque) (print-deque result))
((eq? return-type 'none) (void))
(else
(print result)
(newline)
)
)
)
(newline)
)
(define (execution-time proc . args)
(define start-time (current-milliseconds))
; (display start-time)
; (display " ")
(apply proc args)
(define end-time (current-milliseconds))
; (display end-time)
(display "Execution time of ")
(display proc)
(display ": ")
(- end-time start-time)
)
; Tests
; Test Results
Welcome to DrRacket, version 6.11 [3m].
Language: racket, with debugging; memory limit: 4096 MB.
> (define rvs (make-random-value-stream -5 5))
> (define lr-avgs-s (louis-reasoner-make-stream-of-averages rvs 0))
> (define avgs-s (make-stream-of-averages rvs))
> (display-stream-elements rvs 50)
4.563160468623364
3.769919600836765
-1.6915989764622847
4.825967087829756
-2.8111305261764556
-1.801123806422984
4.793097962849862
0.7226744481167486
-1.787324294392823
-0.26453510276584424
-2.4166203715505628
1.6865422019736798
2.400155437465835
-4.399427376939192
-0.3601551300176107
2.5001056282832224
-0.9243701543353939
3.539587614646699
1.1303704406872983
-3.748757976512811
3.606897115296359
-3.7391895306649205
1.7065394983999935
-4.91907363132744
1.9659774096038438
-3.339404236664083
-3.3313225123367927
0.7554898008568864
-0.7154840204912878
4.283413044398166
4.215847974851815
-0.4138006610028757
4.4934167956539195
-3.6474506833287283
-2.7262837456229647
-3.3152802613513295
-4.769498855354209
-2.345250104044569
-2.6798053545410543
1.5004335022741397
-1.068299059338449
-2.864620733503511
-4.341420331740618
-4.692082739424242
-1.6321964816881502
3.289632753991432
-3.8285435797500105
-2.923811468796987
-2.7784701152522544
-4.806255921651896
'done
> (display-stream-elements lr-avgs-s 50)
2.281580234311682
3.0257499175742235
0.6670754705559694
2.746521279192863
-0.0323046234917963
-0.9167142149573901
1.9381918739462356
1.3304331610314921
-0.2284455666806654
-0.24649033472325482
-1.3315553531369089
0.17749342441838545
1.2888244309421102
-1.5553014729985408
-0.9577283015080758
0.7711886633875733
-0.07659074547391032
1.7314984345863942
1.4309344376368462
-1.1589117694379825
1.2239926729291883
-1.257598428867866
0.2244705347660637
-2.3473015482806883
-0.19066206933842222
-1.7650331530012526
-2.5481778326690225
-0.896344015906068
-0.8059140181986779
1.7387495130997443
2.97729874397578
1.281749041486452
2.887582918570186
-0.3799338823792713
-1.553108814001118
-2.4341945376762237
-3.6018466965152163
-2.973548400279893
-2.8266768774104736
-0.6631216875681669
-0.8657103734533079
-1.8651655534784095
-3.1032929426095137
-3.897687841016878
-2.764942161352514
0.262345296319459
-1.7830991417152757
-2.3534553052561313
-2.565962710254193
-3.6861093159530447
'done
> (display-stream-elements avgs-s 50)
4.1665400347300645
1.0391603121872401
1.5671840556837358
1.0074182808266503
-2.30612716629972
1.4959870782134388
2.757886205483305
-0.5323249231380371
-1.0259296985793336
-1.3405777371582035
-0.3650390847884415
2.0433488197197573
-0.9996359697366786
-2.3797912534784014
1.0699752491328058
0.7878677369739142
1.3076087301556525
2.3349790276669986
-1.3091937679127563
-0.0709304306082259
-0.0661462076842807
-1.0163250161324635
-1.6062670664637233
-1.4765481108617982
-0.6867134135301196
-3.335363374500438
-1.2879163557399531
0.020002890182799327
1.7839645119534393
4.249630509624991
1.9010236569244698
2.039808067325522
0.42298305616259557
-3.1868672144758463
-3.020782003487147
-4.042389558352769
-3.557374479699389
-2.5125277292928114
-0.5896859261334573
0.2160672214678454
-1.96645989642098
-3.6030205326220646
-4.51675153558243
-3.162139610556196
0.8287181361516409
-0.2694554128792892
-3.3761775242734986
-2.851140792024621
-3.7923630184520754
-3.1200506826794108
'done
> (define parabolic-stream (make-stream-from-function (lambda (x) (- (* x x) 15)) 0 0.1))
> (define lr-avgs-ps (louis-reasoner-make-stream-of-averages parabolic-stream 0))
> (define avgs-ps (make-stream-of-averages parabolic-stream))
> (display-stream-elements parabolic-stream 200)
-15
-14.99
-14.96
-14.91
-14.84
-14.75
-14.64
-14.51
-14.36
-14.19
-14.0
-13.790000000000001
-13.56
-13.31
-13.04
-12.75
-12.44
-12.11
-11.759999999999998
-11.389999999999997
-10.999999999999998
-10.589999999999998
-10.159999999999997
-9.709999999999997
-9.239999999999995
-8.749999999999996
-8.239999999999995
-7.709999999999995
-7.159999999999994
-6.589999999999993
-5.999999999999991
-5.389999999999992
-4.759999999999991
-4.109999999999989
-3.439999999999989
-2.7499999999999876
-2.0399999999999867
-1.3099999999999863
-0.5599999999999845
0.21000000000001684
1.0000000000000142
1.810000000000013
2.6400000000000077
3.4900000000000055
4.360000000000003
5.25
6.159999999999997
7.089999999999993
8.039999999999988
9.009999999999987
9.999999999999982
11.009999999999977
12.039999999999974
13.089999999999971
14.159999999999965
15.249999999999961
16.359999999999957
17.489999999999952
18.639999999999944
19.80999999999994
20.999999999999936
22.20999999999993
23.439999999999927
24.68999999999992
25.959999999999916
27.249999999999908
28.559999999999903
29.889999999999894
31.23999999999989
32.609999999999886
33.99999999999988
35.40999999999987
36.83999999999986
38.28999999999986
39.75999999999985
41.249999999999844
42.759999999999835
44.28999999999982
45.83999999999982
47.40999999999981
48.9999999999998
50.609999999999786
52.23999999999978
53.88999999999977
55.55999999999976
57.24999999999976
58.95999999999975
60.68999999999974
62.43999999999973
64.20999999999972
65.99999999999972
67.8099999999997
69.63999999999969
71.48999999999968
73.35999999999967
75.24999999999966
77.15999999999966
79.08999999999965
81.03999999999964
83.00999999999962
84.99999999999962
87.0099999999996
89.03999999999958
91.08999999999958
93.15999999999957
95.24999999999956
97.35999999999954
99.48999999999953
101.63999999999952
103.8099999999995
105.99999999999949
108.20999999999948
110.43999999999947
112.68999999999946
114.95999999999944
117.24999999999943
119.5599999999994
121.88999999999939
124.23999999999938
126.60999999999939
128.99999999999937
131.40999999999934
133.83999999999932
136.2899999999993
138.7599999999993
141.2499999999993
143.75999999999928
146.28999999999925
148.83999999999924