-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPCM20210811_SICP_1.3.1.1_Procedures_as_Arguments_I.jl
3013 lines (2425 loc) · 105 KB
/
PCM20210811_SICP_1.3.1.1_Procedures_as_Arguments_I.jl
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
### A Pluto.jl notebook ###
# v0.19.27
using Markdown
using InteractiveUtils
# ╔═╡ f1c1495e-4203-4d73-a96b-f47e3e54d865
using Plots, QuadGK, LaTeXStrings, Statistics
# ╔═╡ 015f86b0-fa99-11eb-0a32-5bee9e7368fb
md"
=====================================================================================
#### SICP: [1.3.1.1 Procedures as Arguments I](https://sarabander.github.io/sicp/html/1_002e3.xhtml#g_t1_002e3_002e1): Basics (e.g. Cantor Set, Integration à la Riemann & Lebesgue (NonSICP))
##### file: PCM20210811\_SICP\_1.3.1.1\_Procedures\_as\_Arguments\_I.jl
##### Julia/Pluto.jl-code (1.9.3/19.27) by PCM *** 2023/11/12 ***
=====================================================================================
"
# ╔═╡ acd01166-5258-4012-a6f4-e4f05b49dce3
md"
##### 1.3.1.1 SICP-Scheme-like *functional* Julia
"
# ╔═╡ e3414514-9956-416e-ad41-503795d32556
md"""
---
$cube: (\mathbb N \cup \mathbb R) \times (\mathbb N \cup \mathbb R) \rightarrow (\mathbb N \cup \mathbb R)$
$\;$
$x \mapsto cube(x)$
$\;$
$cube(x) := x^3$
$\;$
"""
# ╔═╡ f63fda47-0ee7-4fac-b90c-b4bd893daa7d
cube(x) = *(x, x, x) # '*' is prefix operator (SICP, p.57)
# ╔═╡ 7fcc1606-a914-458a-82ab-a3fa4f1b0b49
cube(3) # result is Integer
# ╔═╡ 590b9e77-9983-4e54-9914-4d6bb5ce8336
cube(3.) # result is Float
# ╔═╡ 6414c834-cfe4-4208-a4b1-7fbf3ced47df
md"
---
$sumIntegers : (\mathbb N \cup \mathbb R) \times (\mathbb N \cup \mathbb R) \rightarrow (\mathbb N \cup \mathbb R)$
$\;$
$(a, b) \mapsto sumIntegers(a, b)$
$\;$
$sumIntegers(a, b) := \sum_{i=a}^{b}i$
$\;$
$\;$
$\;$
"
# ╔═╡ df6d6fdc-20f1-4ead-8e3e-07340ddb521a
sumIntegers1(a, b) = # (SICP, p.57)
>(a, b) ?
0 :
+(a, sumIntegers1(+(a, 1), b))
# ╔═╡ 5e22d368-1433-4ea1-b094-0188cb755c89
sumIntegers1(0, 0) # result is Integer
# ╔═╡ 27d6dbc2-349d-4848-a915-031f42b72d91
sumIntegers1(0., 0) # result is Float
# ╔═╡ 99bc5602-46d7-401e-a625-2efa10806042
sumIntegers1(0, 0.) # result is Integer
# ╔═╡ 3a7dc73f-9435-40ec-a58c-09600dcb834d
sumIntegers1(0., 0.) # result is Float
# ╔═╡ 0b466d51-d50d-45bf-8290-31414a36c3c5
sumIntegers1(2, 5) # result is Integer
# ╔═╡ 4e086e86-51c8-47ec-8810-55c253f3c92c
sumIntegers1(2., 5) # result is Float
# ╔═╡ dbaa23c2-accd-478e-83da-cb9383a2557b
sumIntegers1(2, 5.) # result is Integer
# ╔═╡ 381b81f0-7f5f-4312-b63a-fb654e1668e6
sumIntegers1(2., 5.) # result is Float
# ╔═╡ 0f94752d-afc7-4c19-96b8-f0e40edd8f6f
md"
---
$sumCubes : (\mathbb N \cup \mathbb R) \times (\mathbb N \cup \mathbb R) \rightarrow (\mathbb N \cup \mathbb R)$
$\;$
$(a, b) \mapsto sumCubes(a, b)$
$\;$
$sumCubes(a, b) := \sum_{i=a}^{b}i^3$
$\;$
$\;$
$\;$
"
# ╔═╡ a92d3b32-fc1c-4bd9-ba16-d650ffc805eb
sumCubes1(a, b) = # (SICP, p.57)
>(a, b) ?
0 :
+(cube(a), sumCubes1(+(a, 1), b))
# ╔═╡ a8fbd1f3-9994-4e68-83e1-5272aa85f52f
sumCubes1(0, 1) # result is Integer
# ╔═╡ ce73399c-aa70-4116-beb2-4f861fc01031
sumCubes1(0, 3) # 0+1+2*2*2 + 3*3*3 = 1 + 8 + 27 = 36
# ╔═╡ a890a15b-e0ac-4336-b666-17389f7bae8a
sumCubes1(1, 4) # 36 + 4*4*4 = 36 + 64 = 100
# ╔═╡ 43ca7083-657d-499e-b273-0da40720342a
sumCubes1(1., 4) # result is Float
# ╔═╡ fe6b263c-a804-4e64-9f19-78fe146abc5b
sumCubes1(1, 4.) # result is Integer
# ╔═╡ f33b6724-4bad-4b46-aff7-2763f51fb1a8
sumCubes1(1., 4.) # result is Float
# ╔═╡ 0c1a55e9-5c9f-4613-bc04-8a9959450a9b
md"
---
$\pi_{Sum}: (\mathbb N \cup \mathbb R) \times (\mathbb N \cup \mathbb R) \rightarrow (\mathbb N \cup \mathbb R)$
$\;$
$\pi_{Sum}: (a, b) \mapsto \pi_{Sum}(a, b)$
$\;$
$\pi_{Sum}(a=1, b) := \frac{1}{1\cdot3}+\frac{1}{5\cdot7}+\frac{1}{9\cdot11}+... \approx \frac{\pi}{8}$
$\;$
$\;$
"
# ╔═╡ ac7668db-45f4-456c-a55b-b9106555fca4
md"
---
The well known but slow converging [*Leibniz* formula](https://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80) for determining $\pi$ is :
$\frac{\pi}{4} = \sum_{k=0}^\infty \frac{(-1)^k}{(2k+1)} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \frac{1}{11} + ...$
$\;$
$\;$
$\;$
We partition the series into a sum of pairs:
$\;$
$\frac{\pi}{4} = \sum_{k=0}^\infty \frac{(-1)^k}{(2k+1)} = \left(1 - \frac{1}{3} \right) + \left(\frac{1}{5} - \frac{1}{7}\right) + \left(\frac{1}{9} - \frac{1}{11}\right) + ...$
$\;$
$\;$
$\;$
$\frac{\pi}{4} = \sum_{k=0,2,4,...}^\infty \left(\frac{1}{(2k+1)}-\frac{1}{2(k+1+1)} \right) = \sum_{k=0,2,4,...}^\infty \frac{2}{(2k+1)(2k+3)}$
$\;$
$\;$
$\;$
Divison by $2$ simplifies the numerator:
$\;$
$\frac{\pi}{8} = \sum_{k=0,2,4,...}^\infty \frac{1}{(2k+1)(2k+3)} = \frac{1}{1\cdot3}+\frac{1}{5\cdot7}+\frac{1}{9\cdot11}+...$
$\;$
$\;$
$\;$
"
# ╔═╡ fb0e59f2-a9c5-44c3-9d41-7cb8c0347bfb
piSum1(;a=1, b=1) = # SICP, p.57, keyword parms
>(a, b) ?
0 :
+(/(1.0, *(a, +(a, 2))), piSum1(a=+(a+4), b=b)) # keyword parameters
# ╔═╡ 2b2937e1-dba3-462c-a769-60804d676bf5
*(8, piSum1(b=1)) # keyword arguments
# ╔═╡ e25a03e0-886c-4862-badb-bcb5be6f477a
myError(approxPi) = abs(pi - approxPi)
# ╔═╡ 31ea7745-7d46-4ade-97d1-41ce15f970f7
myError(*(8, piSum1(b=1))) # error 0.4749259869231266
# ╔═╡ eb647d89-bbc8-42db-9265-5cfc9ad8a03c
*(8, piSum1(b=10))
# ╔═╡ ba2a843a-a31a-4232-8c94-3893ec0ec760
myError(*(8, piSum1(a=1, b=10))) # error 0.16554647754361707
# ╔═╡ b6caf296-0dea-4572-9043-d515f71d6f93
myError(*(8, piSum1(a=1, b=10^2))) # error 0.019998000998782572
# ╔═╡ d6144688-4c14-4db3-8c49-65c9eaf7c30b
myError(*(8, piSum1(a=1, b=10^3))) # error 0.0019999980000102724
# ╔═╡ 54b81d43-1219-45e9-abaa-805311268810
myError(*(8, piSum1(a=1, b=10^4))) # error 0.00019999999800024426
# ╔═╡ 1745d75d-dcc8-4a32-b9a8-607f5da744d9
# stack overflow, as expected
*(8, piSum1(a=1, b=^(10, 5)))
# ╔═╡ ddae764c-b5c0-4eda-8c80-4f57fbeac486
# stack overflow, as expected
myError(*(8, piSum1(a=1, b=^(10, 5))))
# ╔═╡ 6c793213-177e-4c50-99b2-482704cbad75
md"
---
###### The *Lebesgue Measure* $\lambda(C)$ (= Length) of [*Cantor's Set (=Discontinuum) C*](https://en.wikipedia.org/wiki/Cantor_set))
(NonSICP)
We take the interval
$C_0=[0,1]$
$\;$
$\lambda(C_0) = |C_0| = 1$
$\;$
and construct the *discontinuum* (Schilling, 2015, p.2f.) by removing ternary *open* intervals $(...,...)_3$:
- 1st construction step generating $C_1$: Remove from $C_0$ the middle *open* interval $I_2$
$I_2=(0.1,0.2)_3=(0*3^0+1*3^{-1}, 0*3^0+2*3^{-1})=\left(\frac{1}{3},\frac{2}{3}\right)$
$\;$
$\;$
$C_1 = C_0\backslash\;I_2=\left[0,\frac{1}{3}\right]\cup\left[\frac{2}{3},1\right]$
$\;$
$\;$
$\lambda(C_1)=|C_1|=\frac{1}{3}+\frac{1}{3}=\frac{2}{3}=\frac{\#intercals}{interval\, size}=0.\overline{6}$
$\;$
$\;$
- 2nd construction step generating $C_2$: Remove from the $2^1$ *closed* intervals of $C_1$ the middle *open* intervals $I_{t_12}$ where $t_1 \in \{0,2\}$
$\;$
$I_{02} := (0.01,0.02)_3=$
$(0*3^0+0*3^{-1}+1*3^{-2},0*3^0+0*3^{-1}+2*3^{-2})=\left(\frac{1}{9}, \frac{2}{9}\right)$
$\;$
$\;$
$I_{22} := (0.21,0.22)_3=$
$(0*3^0+2*3^{-1}+1*3^{-2},0*3^0+2*3^{-1}+2*3^{-2})=\left(\frac{7}{9}, \frac{8}{9}\right)$
$\;$
$\;$
$\;$
$C_2=C_1\;\backslash I_{02}\cup I_{22}=$
$\;$
$=\left[0,\frac{1}{9}\right]\cup\left[\frac{2}{9},\frac{1}{3}\right]\cup\left[\frac{2}{3},\frac{7}{9}\right]\cup\left[\frac{8}{9},1\right]$
$\;$
$\;$
$\lambda(C_2)=|C_2| = \frac{4}{9}=\frac{\#intercals}{interval\, size}=0.\overline{4}$
$\;$
$\;$
- 3rd construction step generating $C_3$: Remove from the $2^2$ *closed* intervals of $C_2$ the middle *open* intervals $I_{1_1t_22}$ where $t_1,t_2 \in \{0,2\}$
$\;$
$I_{002} = (0.001, 0.002)_3 =$
$\;$
$=(0*3^0 + 0*3^{-1} + 0*3^{-2} + 1*3^{-3},
0*3^0 + 0*3^{-1} + 0*3^{-2} + 2*3^{-3})=$
$\;$
$\;$
$\left(0+0+0+\frac{1}{27}, 0+0+0+\frac{2}{27}\right)=\left(\frac{1}{27}, \frac{2}{27}\right) = (0.03704, 0.07407)$
$\;$
$\;$
$\;$
$I_{022}= (0.021, 0.022)_3=$
$\;$
$=(0*3^0 + 0*3^{-1} + 2*3^{-2} + 1*3^{-3},
0*3^0 + 0*3^{-1} + 2*3^{-2} + 2*3^{-3})=$
$\;$
$\;$
$=\left(0+0+\frac{2}{9}+\frac{1}{27}, 0+0+\frac{2}{9}+\frac{2}{27}\right)=\left(\frac{7}{27}, \frac{8}{27}\right)=(0.25926,0.29630)$
$\;$
$\;$
$\;$
$I_{202}= (0.201, 0.202)_3=$
$\;$
$=(0*3^0 + 2*3^{-1} + 0*3^{-2} + 1*3^{-3},
0*3^0 + 2*3^{-1} + 0*3^{-2} + 2*3^{-3})=$
$\;$
$\;$
$=\left(0+\frac{2}{3}+0+\frac{1}{27},0+\frac{2}{3}+0+\frac{2}{27}\right)=$
$\;$
$\;$
$=\left(\frac{19}{27},\frac{20}{27}\right)=(0.70370, 0.74074)$
$\;$
$\;$
$\;$
$I_{222}=(0.221, 0.222)_3=$
$\;$
$\;$
$=(0*3^0 + 2*3^{-1} + 2*3^{-2} + 1*3^{-3},
0*3^0 + 2*3^{-1} + 2*3^{-2} + 2*3^{-3})=$
$\;$
$\;$
$=\left(0+\frac{2}{3}+\frac{2}{9}+\frac{1}{27},0+\frac{2}{3}+\frac{2}{9}+\frac{2}{27}\right)=\left(\frac{25}{27},\frac{26}{27}\right)=(0.9293,0.96296)$
$\;$
$\;$
$\;$
$\;$
$C_3 = C_2 \backslash\;I_{002} \cup I_{022} \cup I_{202} \cup I_{222}=$
$\;$
$\;$
$=\left[0,\frac{1}{27}\right]\cup\left[\frac{2}{27},\frac{1}{3}\right]\cup\left[\frac{2}{9},\frac{7}{27}\right]\cup\left[\frac{8}{27},\frac{1}{3}\right]\cup\left[\frac{7}{3},\frac{19}{27}\right]\cup\left[\frac{20}{27},\frac{7}{9}\right]\cup\left[\frac{8}{9},\frac{25}{27}\right]\cup\left[\frac{26}{27},1\right]$
$\;$
$\;$
$\lambda(C_3) = \frac{8}{27}=\frac{\#intercals}{interval\, size}=0.\overline{2}\overline{9}\overline{6}.$
$\;$
$\;$
"
# ╔═╡ d9eefee2-a53c-4064-8ebf-c4345a76798c
md"
###### Numeration of Intervals in the *Cantor Set*
(NonSICP)
In the $n^{th}+1$ step we remove all intervals
$I_{t_1t_2...t_{n-1}t_n2}=(0.t_1t_2...t_{n-1}t_n1, 0.t_1t_2...t_{n-1}t_n2)_3 \in \{0,2\}.$
$\;$
Endpoints are written as *triadic* numbers with numbers $t_1t_2...t_{n-1}t_n \in \{0,2\}.$ The sequence of triadic numbers $t_1...t_n$ encodes the position of the interval $I_{t_1t_2...t_{n-1}t_n2}$ in relation to the interval $I_{t_1t_2...t_{n-1}2}.$ $t_n=0$ means that the interval is *left* of $I_{t_1t_2...t_{n-1}2}$ and $t_n=2$ means that it is *right* of. This results in a binary tree (plot below).
The *Lebesgue* measure (= length) of the interval $I_{t_1t_2...t_{n-1}t_n2}$ is:
$\;$
$\lambda(I_{t_1t_2...t_{n-1}t_n2})=0.t_1t_2...t_{n-1}t_n2-
0.t_1t_2...t_{n-1}t_n1=0.00...001_3=3^{-(n+1)}.$
$\;$
$\;$
$\text{e.g. }3^{-(0+1)}=\frac{1}{3},\; 3^{-(1+1)}=\frac{1}{9},\; 3^{-(2+1)}=\frac{1}{27},\;...$
$\;$
$\;$
So interval lengths can be derived from this ternary encoding:
- 1st step: 2^0 intervals $\lambda(I_2) = 0.2_3-0.1_3=0.1_3=3^{-(0+1)}=\frac{1}{3}$
- 2nd step: 2^1 intervals $\lambda(I_{02}), \lambda(I_{22}) =3^{-(1+1)}=\frac{1}{9}$
- 3rd step: 2^2 intervals $\lambda(I_{002}), \lambda(I_{022}), \lambda(I_{022}) , \lambda(I_{222})=3^{-(2+1)}=\frac{1}{27}$
- (n+1)th step: 2^n intervals with length $3^{-(n+1)}.$
$\;$
"
# ╔═╡ b61f0964-d023-4bba-9822-812e3218f716
begin
plot(x->1.0, 0.0, 1.0, size=(700, 400), xlims=(-0.02, 1.24), ylims=(0, 1.2), line=:blue, lw=3, label="", title="Construction of Cantor's Set (=Discontinuum)", framestyle=:semi)
plot!([(0.0,1.02),(0.0,0.98)],line=:blue,lw=1,label="") # left vertical start bar
plot!([(1.0,1.02),(1.0,0.98)],line=:blue,lw=1,label="") # right vertical end bar
annotate!(1.1, 1.0, L"C_0")
#----------------------------------------------------------------------------------
annotate!(1/3, 0.83, L"\frac{1}{3}", 10); annotate!(2/3, 0.83, L"\frac{2}{3}", 10)
plot!(x->0.75, [[0.0, 1/3], [2/3, 1.0]], line=:blue, lw=3, label="")
plot!([(0.0,0.77),(0.0,0.73)],line=:blue,lw=1,label="") # left vertical start bar
plot!([(1/3,0.77),(1/3,0.73)],line=:blue,lw=1,label="") # left vertical bar
plot!([(2/3,0.77),(2/3,0.73)],line=:blue,lw=1,label="") # left vertical bar
plot!([(1.0,0.77),(1.0,0.73)],line=:blue,lw=1,label="") # right vertical end bar
annotate!(1.1, 0.75, L"C_1")
annotate!(1/2, 3/4, L"I_2")
annotate!(1/9, 0.58, L"\frac{1}{9}", 10); annotate!(2/9, 0.58, L"\frac{2}{9}", 10)
annotate!(7/9, 0.58, L"\frac{7}{9}", 10); annotate!(8/9, 0.58, L"\frac{8}{9}", 10)
#----------------------------------------------------------------------------------
plot!(x->0.50, [[0.0, 1/9], [2/9, 3/9], [6/9, 7/9], [8/9, 9/9]], line=:blue, lw=3, label="")
plot!([(0.0,0.52),(0.0,0.48)],line=:blue,lw=1,label="") # left vertical start bar
plot!([(1/9,0.52),(1/9,0.48)],line=:blue,lw=1,label="") # left vertical bar
plot!([(2/9,0.52),(2/9,0.48)],line=:blue,lw=1,label="") # left vertical bar
plot!([(3/9,0.52),(3/9,0.48)],line=:blue,lw=1,label="") # left vertical bar
plot!([(6/9,0.52),(6/9,0.48)],line=:blue,lw=1,label="") # left vertical bar
plot!([(7/9,0.52),(7/9,0.48)],line=:blue,lw=1,label="") # left vertical bar
plot!([(8/9,0.52),(8/9,0.48)],line=:blue,lw=1,label="") # left vertical bar
plot!([(1.0,0.52),(1.0,0.48)],line=:blue,lw=1,label="") # left vertical bar
annotate!(1.1, 0.5, L"C_2")
annotate!(0.17, 0.5, L"I_{02}")
annotate!(0.835, 0.5, L"I_{22}")
#----------------------------------------------------------------------------------
plot!(x->0.25, [[0.0, 1/27], [2/27, 3/27], [6/27, 7/27], [8/27, 9/27], [18/27, 19/27], [20/27, 21/27], [24/27, 25/27], [26/27, 27/27]], line=:blue, lw=3, label="")
plot!([( 0/27,0.27),( 0/27,0.23)],line=:blue,lw=1,label="") # left vertical start bar
plot!([( 1/27,0.27),( 1/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([( 2/27,0.27),( 2/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([( 3/27,0.27),( 3/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([( 6/27,0.27),( 6/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([( 7/27,0.27),( 7/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([( 8/27,0.27),( 8/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([( 9/27,0.27),( 9/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([(18/27,0.27),(18/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([(19/27,0.27),(19/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([(20/27,0.27),(20/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([(21/27,0.27),(21/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([(24/27,0.27),(24/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([(25/27,0.27),(25/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([(26/27,0.27),(26/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
plot!([(27/27,0.27),(27/27,0.23)],line=:blue,lw=1,label="") # left vertical bar
annotate!(1.1, 0.25, L"C_3")
annotate!(0.075, 0.20, L"I_{002}")
annotate!(1/27-0.005, 0.32, L"\frac{1}{27}",8), annotate!(2/27+0.007, 0.32, L"\frac{2}{27}",8)
annotate!(7/27-0.005, 0.32, L"\frac{7}{27}",8), annotate!(8/27+0.007, 0.32, L"\frac{8}{27}",8)
annotate!(19/27-0.005, 0.32, L"\frac{19}{27}",8), annotate!(20/27+0.007, 0.32, L"\frac{20}{27}",8)
annotate!(25/27-0.005, 0.32, L"\frac{25}{27}",8), annotate!(26/27+0.007, 0.32, L"\frac{26}{27}",8)
annotate!(0.3, 0.20, L"I_{022}")
annotate!(0.745, 0.20, L"I_{202}")
annotate!(0.97, 0.20, L"I_{222}")
#----------------------------------------------------------------------
# binary tree
plot!([(1/2, 3/4), (0.17, 0.5)], color=:pink,lw=2,ls=:dash,label="")
plot!([(1/2, 3/4),(0.835, 0.5)], color=:pink,lw=2,ls=:dash,label="")
plot!([(0.17, 0.5),(0.055, 0.25)], color=:pink,lw=2,ls=:dash,label="")
plot!([(0.17, 0.5),(0.28, 0.25)], color=:pink,lw=2,ls=:dash,label="")
plot!([(0.835, 0.5),(0.722, 0.25)], color=:pink,lw=2,ls=:dash,label="")
plot!([(0.835, 0.5),(0.945, 0.25)], color=:pink,lw=2,ls=:dash,label="")
#----------------------------------------------------------------------
end # begin
# ╔═╡ d2f67bf1-a301-4c93-aaac-4c66a7c9b944
md"
---
###### Measuring $\lambda(C_n)$
(NonSICP)
The *Lebesgue Measure* $\lambda(C)$ of *Cantor's Discontinuum* $C$ is (c.f. Schilling, 2015, p.2f.):
$\lambda(C_0)=\lambda([0,1])=1$
$\;$
$\lambda(C_1)=\lambda(C_0)-\frac{1}{3}=\lambda([0,1])-\frac{1}{3}=1-\frac{1}{3}= \frac{2}{3}=0.\overline{6}$
$\;$
$\;$
$\lambda(C_2)=\lambda(C_1)-2\cdot\frac{1}{9} = \frac{2}{3}-\frac{2}{9}=\frac{6}{9}-\frac{2}{9}=\frac{4}{9}=0.\overline{4}$
$\;$
$\;$
$\lambda(C_3)=1-\frac{1}{3}\left[\frac{2^0}{3^0}+\frac{2^1}{3^1}+\frac{2^2}{3^2}\right]=1-\frac{1}{3}\left[1+\frac{2}{3}+\frac{4}{9}\right]=$
$\;$
$\;$
$\;$
$=1-\frac{1}{3}\cdot\frac{19}{9}=1-\frac{19}{27}=\frac{8}{27}=0.\overline{2}\overline{9}\overline{6}$
$\;$
$\;$
$......$
$\;$
$\lambda(C_{n+1})=1-2^0\times\frac{1}{3^1}-2^1\times\frac{1}{3^2}-...-2^n\times\frac{1}{3^{n+1}}=1-\frac{1}{3}\sum_{j=0}^n\frac{2^j}{3^j}=1-\frac{1}{3}\sum_{j=0}^n\left(\frac{2}{3}\right)^j$
$\;$
$\;$
$......$
$\;$
$\lambda(C)=1-\sum_{n=0}^\infty\frac{2^n}{3^{n+1}}=1-\frac{1}{3}\sum_{n=0}^\infty\frac{2^n}{3^n}=1-\frac{1}{3}\sum_{n=0}^\infty\left(\frac{2}{3}\right)^n=0.$
$\;$
$\;$
$\;$
This means that the *Cantor set* is a [*Null Set*](https://en.wikipedia.org/wiki/Null_set). It has length *zero* though it is not empty. It contains at least the endpoints of the intervals.
$\;$
"
# ╔═╡ 4dae9415-e8e2-4133-9cef-a3c4618bdbda
md"
Because $\sum_{n=0}^\infty\left(\frac{2}{3}\right)^n$ is a convergent geometric series with $r=\frac{2}{3}$ the sum is
$\;$
$\;$
$\sum_{n=0}^\infty\left(r\right)^n=\frac{1}{1-r}$
$\;$
$\;$
and
$\;$
$\lambda(C)=1-\frac{1}{3}\sum_{n=0}^\infty\left(\frac{2}{3}\right)^n=1-\frac{1}{3}\left(\frac{1}{1-\frac{2}{3}}\right)=1-\frac{1}{3}\left(\frac{1}{\frac{1}{3}}\right)=1-\frac{1}{3}\left(\frac{3}{1}\right)=0$
$\;$
$\;$
$\;$
$\;$
*C* is not empty (e.g. Schilling, 2015, p.3). At least the end points of intervals are left over in $C$ after removings.
$\;$
"
# ╔═╡ ed9af448-5867-4cfd-815a-c295eaffac8b
function λC(n; j=0, accu=0.0)
r = 2/3
if j == n
1 - 1/3 * accu
else
reduction = r^j
accuOld = accu
accuNew = accu + reduction
if accuOld ≈ accuNew
error("no substantial reduction with j = $j")
end # if
λC(n; j=j+1, accu=accu+reduction)
end # if
end # function λC
# ╔═╡ ed8e7ccf-5c04-4304-baf9-60cc07773d28
λC(0) # ==> 1.0 --> :)
# ╔═╡ 83b7e51e-2e73-4448-8cb1-ed98787c3994
λC(1) # ==> 2/3 --> 0.666... --> :)
# ╔═╡ 14b8a22d-5443-4fae-abd9-b54a283eaa92
λC(2) # ==> 4/9 --> 0.444... --> :)
# ╔═╡ c9905375-c8ea-4403-8ce7-2af82324027a
λC(3) # ==> 8/27 --> 0.296... --> :)
# ╔═╡ 6052b447-cd20-4f1e-87e1-bda2ea6461a3
λC(10)
# ╔═╡ 650c0387-e516-4b08-8c9a-aa49682183a4
λC(50) # ==> no substantial reduction with j = 42
# ╔═╡ 299fb3ee-a3a6-44d1-9b0c-094283e6dfa4
λC(42)
# ╔═╡ f89d9a5d-0fd8-4684-82bd-797de43582a2
λC(43) # ==> no substantial reduction with j = 42
# ╔═╡ c193805e-df87-4842-bdb5-d1991db9ccf0
function λC2(n) #; j=0, accu=0.0)
j = 0
if n == 0
1
else
r = 2/3
1 - 1/3 * sum(
j -> r^(j-1), [j for j in 1:n], init=0.0)
end # if
end # function λC
# ╔═╡ 70ec1fa0-2e9d-4aab-923a-10fa0fb249a5
λC2(0)
# ╔═╡ 2eba09ba-f280-47c6-8753-18b9a77c4a5b
λC2(1)
# ╔═╡ 5d34717f-f9fe-4796-9fc5-51462bdabe85
λC2(2)
# ╔═╡ 6f6e5499-7dcb-4a3a-b0b9-a8ca9898b689
λC2(3)
# ╔═╡ b37131ce-d9c0-4b9e-9392-f752dba44c13
λC2(42) # same as λC(42)
# ╔═╡ 2874445b-ced9-45bd-9094-5a1e48651831
λC2(43) # less than λC(43)
# ╔═╡ f9034ab8-2af6-4d79-be1d-1da8c6cccd81
λC2(50) # less than λC(50)
# ╔═╡ 477debe7-5232-4bcf-8109-3ee8352f0047
λC2(60) # less than λC(60)
# ╔═╡ 2c0a3d9d-8656-46b9-83ce-080854f59923
λC2(70) # less than λC(70)
# ╔═╡ 281ea205-6462-45bb-a63a-24de59f396e2
λC2(70)
# ╔═╡ cb608af4-73cf-4c5b-824d-073b36414664
λC2(80)
# ╔═╡ e566a3ee-1f78-4caa-b56e-0c6354074fec
λC2(85)
# ╔═╡ bf31819b-32ef-4099-bd68-982f085be0c4
λC2(87)
# ╔═╡ 0d76bef3-53bf-4947-862b-8f46a0438481
λC2(88)
# ╔═╡ 07577047-ac4f-4f8f-950d-2db31ee94539
λC2(89)
# ╔═╡ e846e3a1-0b2f-43e0-adfb-866d9511c4f2
λC2(90) # no further improvement observable
# ╔═╡ fdcd0ad9-a81c-48c8-ab7d-8f8b70e38c4d
md"
---
(SICP, p.58)
$sum : (\mathbb N \rightarrow \mathbb N) \times (\mathbb N \cup \mathbb R) \times (\mathbb N \rightarrow \mathbb N) \times (\mathbb N \cup \mathbb R) \rightarrow (\mathbb N \cup \mathbb R)$
$\;$
$\;$
$(f, a, succ, b) \mapsto sum(f, a, succ, b)$
$\;$
$sum(f, a, succ, b) := \sum_{i=a}^b f(i) = f(a) + f(succ(a)) + ... + f(b)$
$\;$
$\;$
$\;$
"
# ╔═╡ da24559b-1937-4258-847d-e0f7b7a7c293
function sum1(f, a, succ, b) # SICP, p.58
if >(a, b)
0
else
+(f(a), sum1(f, succ(a), succ, b))
end # if
end # function sum1
# ╔═╡ b9c17500-0301-4a9f-8707-c18fda55261c
inc(n) = +(n, 1) # SICP, p.58
# ╔═╡ 76174121-4f07-4e04-9bde-f98344fc1a1e
sumCubes2(a, b) = sum1(cube, a, inc, b) # SICP, p.59
# ╔═╡ 792c2312-2469-4844-b7b8-4acd42333a82
sumCubes2(0, 1)
# ╔═╡ 39a8a3f7-391d-4adf-a217-9ce1db164099
# 0 + 1 + 2*2*2 + 3*3*3 = 1 + 8 + 27 = 36
sumCubes2(0, 3)
# ╔═╡ eb294e7b-3eb4-4038-bf10-3870819dd2ae
sumCubes1(1, 10) # SICP, p.59
# ╔═╡ 0779063c-bb2c-4060-84d7-e6268f9255a2
identity(x) = x # SICP, p.59
# ╔═╡ d14308c5-374a-495d-8865-1f52e198fb5e
sum_integers2(a, b) = sum1(identity, a, inc, b) # SICP, p.59
# ╔═╡ d195654c-302f-4c80-9d4b-0d95978b6a7c
sum_integers2(0, 6)
# ╔═╡ 33ea2359-475f-42ca-8de4-5f4e91148529
sum_integers2(1, 10) # SICP, p.59
# ╔═╡ 99baa676-35fc-4bcb-bd81-9f86b154c307
md"
---
###### Alternative $\pi_{sum_2}$ with functional arguments $term$ and $next$
(SICP, p.59)
"
# ╔═╡ 2a14bebd-8b53-442a-965f-983f040eeea3
md"
---
###### Riemann Integration by the [Trapezoidal Method](https://en.wikipedia.org/wiki/Trapezoidal_rule)
(SICP, p.59)
$\;$
$\int_a^b f(x)\; dx \approx \left[f\left(a+\frac{Δx}{2}\right)+f\left(a+Δx+\frac{Δx}{2}\right)+f\left(a+2Δx+\frac{Δx}{2}\right)...\right]\;Δx$
$\;$
$\;$
$\;$
$=\left[\sum_{i=0}^{b/Δx}f\left(a + i \cdot Δx + \frac{dx}{2}\right)\right]\;Δx$
$\;$
$\;$
$\;$
;
"
# ╔═╡ d0c513b0-e921-45b2-a12b-1ad41a1e902e
function integral1(f, a, b; Δx=0.01) # SICP, p.60
add_Δx(x) = x + Δx
sum1(f, a + Δx/2.0, add_Δx, b) * Δx
end # function integral1
# ╔═╡ cd4ad65b-6fa0-4eda-8dd5-0bb3d04eeeb2
md"
---
###### Cubic function
(SICP, p.60)
$$\int_0^1 x^3 dx= \left.\frac{x^4}{4}\right|_0^1=\frac{1^4}{4}-\frac{0^4}{4}=\frac{1}{4}$$
$\;$
$\;$
$\;$
$\;$
"
# ╔═╡ 02bf20ff-0e44-40bc-bd6a-1e55e2086571
plot(cube, 0.0, 1.0, size=(525, 400), xlims=(0.0, 1.1), ylims=(0, 1.2), line=:darkblue, fill=(0, :lightblue), title=L"$x \mapsto x^3$", framestyle=:semi, label="")
# ╔═╡ bf281edd-d933-446b-8b54-903e52c4505b
integral1(cube, 0, 1) # SICP, p.60
# ╔═╡ dc5ec344-9513-4cda-b97f-511a7449cb6d
integral1(cube, 0, 1, Δx=0.001) # SICP, p.60
# ╔═╡ 71319af0-3051-41c8-8c12-20c142901c11
integral1(cube, 0, 1, Δx=1.0E-4)
# ╔═╡ 7dffb4c0-1820-46c4-8676-f327de55048e
md"""
---
###### Halfparabola
(NonSICP), Stark, P.A., *Introduction to Numerical Methods*, 1970, ch. 6.2-6.3, p. 196, Example 6-1
$\;$
$\int_0^1\left(6-6x^5\right)dx = \left.\left(6x-6\frac{x^6}{6}\right)\right|_0^1=(6-1)=5$
$\;$
$\;$
$\;$
$\;$
"""
# ╔═╡ 76170408-797d-451b-bcf6-b69fec927085
halfParabola(x) = -6x^5 + 6 # Stark, P.A., Intro to Num. Methods, 1970, p.196f.
# ╔═╡ b2db2a4a-8a5e-43b1-bb99-d37828dbec0c
plot(halfParabola, 0.0, 1.0, size=(200, 400), xlim=(0.0, 1.1), ylim=(0, 6.5), line=:darkblue, fill=(0, :lightblue), framestyle=:semi, title=L"$x\mapsto -6x^5 + 6$", label="")
# ╔═╡ 73a0deb5-6dc3-41d8-b810-5553c74455ed
integral1(halfParabola, 0.0, 1.0, Δx=0.1) # should be 5.0
# ╔═╡ 08f1b671-dc0a-4b7a-92ce-4568c24589f1
integral1(halfParabola, 0.0, 1.0, Δx=0.01) # should be 5.0
# ╔═╡ 2cf94a78-f3ea-4e02-b417-aaa6510ff328
md"
---
###### [Standard Normal (= Gaussian) Distribution](https://en.wikipedia.org/wiki/Normal_distribution)
(NonSICP)
"
# ╔═╡ b2e9582d-bf46-486b-b7fb-1e3a68e77efe
gaussianDensity(x; μ=0.0, σ=1.0) = 1/(σ*sqrt(2π))*exp(-(1/2)*((x-μ)/σ)^2)
# ╔═╡ bd63330c-e1f8-4f4e-836f-b1285539a0c1
let x1 = +1.0
x2 = -1.0
y1 = gaussianDensity(+1.0)
y2 = gaussianDensity(-1.0)
plot(gaussianDensity, -1.0, 1.0, size=(525, 400), xlim=(-3.0, 3.0), ylim=(0, 0.45), line=:darkblue, fill=(0, :lightblue), framestyle=:semi, title=L"$p(-1.0 < X < +1.0)$ for $X \sim N(X\;\;| μ=0.0, σ=1.0)$", xlabel=L"$X$", ylabel=L"$f(X)$", label=L"f(X)")
plot!(gaussianDensity, -3.0, -1.0, line=:darkblue, label=L"$f(X)$")
plot!(gaussianDensity, 1.0, 3.0, line=:darkblue, label=L"$f(X)$")
plot!([x1, x1], [0, y1], color=:red, label=L"$x=+1.0=\sigma$")
plot!([x2, x2], [0, y2], color=:red, label=L"$x=-1.0=-\sigma$")
end # let
# ╔═╡ 12e0fa05-135d-48b6-b6c2-c28ce006b2d9
integral1(gaussianDensity, -1.0, 1.0, Δx=0.1) # ==> p = 0.682
# ╔═╡ 23824efd-d3d8-4e02-8ddd-5e20da7e99a4
integral1(gaussianDensity, -1.0, 1.0) # ==> p = 0.682
# ╔═╡ ae961cd1-bab0-41e2-9bc5-918d7346f82d
md"
---
##### 1.3.1.2 idiomatic *imperative* Julia ...
###### ... with *abstract* types 'Real', 'Integer', *self-defined*, 'while', '+='
"
# ╔═╡ cb1cbf7f-98e0-49d4-b12e-ee8b8808d316
pi # Julia constant π
# ╔═╡ d0ea0cc2-fdc3-4055-a651-946a66cb7db0
typeof(pi) # Irrational !
# ╔═╡ 9fde9515-3848-44c1-b33b-de9bae9c77c6
subtypes(Real)
# ╔═╡ 890ab8e8-12df-4975-90a4-fda312d60ba2
# idiomatic Julia-code with 'Real', 'while', '+='
#-----------------------------------------------------
function sumIntegers2(a::Real, b::Real)::Real
sum = 0
while !(a > b)
sum += a
a += 1
end # while
sum
end # function sumIntegers2
# ╔═╡ 20c6c63f-6f04-4aa2-987a-e6789a916383
sumIntegers2(1, 10)
# ╔═╡ 38295b22-5dfb-4e3a-bdd7-e7b91c65d342
sumIntegers2(2, 10) # ==> Integer
# ╔═╡ 46466ddf-7b65-49f0-b8d0-d0039f1165e0
sumIntegers2(2., 10) # ==> Float
# ╔═╡ 76cbceaa-ff7b-4e49-8935-6eda98b68729
sumIntegers2(2, 10.) # ==> Integer
# ╔═╡ 8a4adbdc-2553-4f6a-8cb2-e0c3d35cca08
sumIntegers2(2., 10.)
# ╔═╡ 81c0cc23-68f9-4d91-af01-38898e6d50af
# idiomatic Julia-code with 'Real, 'while', '+='
#---------------------------------------------------
function sumCubes3(a::Real, b::Real)::Real
#-----------------------------------------------
cube(x) = x^3
#-----------------------------------------------
sum = 0
while !(a > b)
sum += cube(a)
a += 1
end # while
sum
end # function sumCubes3
# ╔═╡ 732458d7-1938-4be1-9de2-8071d1ad644d
sumCubes3(0, 1)
# ╔═╡ 39c2206d-8a4d-49d0-a8d5-c7a744443000
sumCubes3(0, 3) # 0 + 1 + 2*2*2 + 3*3*3 = 1 + 8 + 27 = 36
# ╔═╡ 4d0c6403-7588-4971-8046-1f99e3a421a6
sumCubes3(0, 4) # sumCubes3(0, 3) + 4^3 = 36 + 64 = 100
# ╔═╡ 1e034229-e2a0-420e-97e7-8a02a577fe5a
sumCubes1(1, 4) # 36 + 4^3 = 36 + 64 = 100
# ╔═╡ 69618ff5-44f5-4d60-8297-cc15457a2ed8
# idiomatic Julia-code with 'Real','while', '+='
#-------------------------------------------------------
function piSum3(a::Real, b::Real)::Real
sum = 0
while !(a > b)
sum += 1.0 / (a * (a + 2))
a += 4
end # while
sum
end # function piSum3
# ╔═╡ 3127686e-0c30-48e2-8c73-e7563ee60124
8 * piSum3(1, 10^5)
# ╔═╡ 5a847c91-d008-434c-98de-90a74335012c
myError(8 * piSum3(1, 10^5))
# ╔═╡ 9fbc3781-1cf3-4b94-bc93-b5d8c7e0ad24
myError(8 * piSum3(1, 10^8))
# ╔═╡ 23cf565a-21a1-407d-981d-1ddc433327a8
8 * piSum3(1, 10^10)
# ╔═╡ 5b4e0581-36b1-47d3-be06-a84cfee8788f
myError(8 * piSum3(1, 10^10))
# ╔═╡ 3a72d464-a12c-4de5-8c8c-7768c60bec3c
typeof(Function)
# ╔═╡ 28aab614-3469-43d8-ab48-6feb0d30be92
typeof(DataType)
# ╔═╡ 82a083c1-2637-49cc-ada1-2c006c26b39f
supertype(Function)
# ╔═╡ a9f09569-210d-4bbd-8b81-556f628d9220
subtypes(Function)
# ╔═╡ d4290924-cbe3-4f51-88f7-3aaacdfd6b4f
# idiomatic Julia-code with 'Function', 'Real', 'while', '+='
#------------------------------------------------------------------
function sum2(f::Function, a::Real, succ::Function, b::Real)::Real
sum = 0
while !(a > b)
sum += f(a)
a = succ(a)
end # while
sum
end # function sum2
# ╔═╡ 7dc42461-ba3a-4837-ba37-e91920c8dc66
function piSum2(a::Real, b::Real)::Real # SICP, p.59
#---------------------------------------------------------------------
piTerm(x) = 1.0 / (x * (x + 2))
piNext(x) = x + 4
#---------------------------------------------------------------------
sum2(piTerm::Function, a::Real, piNext::Function, b::Real)
end # unction piSum2
# ╔═╡ 7fcba949-68ad-4622-8492-a21c21c81d56
8 * piSum2(1, 10^3) # SICP, p.59
# ╔═╡ 254b9112-0f77-4919-9fdb-1e8d4785187b
8 * piSum2(1, 10^6)
# ╔═╡ 5967b1d1-0990-4ebc-ae8b-6e6ec00b4f5d
8 * piSum2(1, 10^6)
# ╔═╡ ba73b5bb-e803-4e5a-91d9-9c93da299930
8 * piSum2(1.0, 10.0^6)
# ╔═╡ 0ad7a6d9-1d24-41dc-a573-a8856dfef417
sum_cubes4(a, b) = sum2(cube, a, inc, b)
# ╔═╡ f2d4ee8f-a71e-4370-845f-ac3d37cb4a51
sum_cubes4(1, 1)
# ╔═╡ fd9dadfb-e205-4016-9bad-ceb7fcc1f417
sum_cubes4(1, 2)
# ╔═╡ 9636b204-dc6b-4e9c-88b4-7f4f3a0ff353
sum_cubes4(1, 10)
# ╔═╡ 13f1da45-78ce-4ee9-86ed-0bdb4e592f1c
function integral2(f, a, b; Δx=0.01)
add_Δx(x) = x + Δx
sum2(f::Function, (a + Δx/2.0), add_Δx, b) * Δx
end
# ╔═╡ 7174bf72-b914-4944-95ac-a47cc7ddbfef
integral2(halfParabola, 0, 1, Δx=0.01) # should be 5.0