-
Notifications
You must be signed in to change notification settings - Fork 0
/
YCombinator005.nb
2866 lines (2677 loc) · 118 KB
/
YCombinator005.nb
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
(* Content-type: application/vnd.wolfram.mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 8.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 157, 7]
NotebookDataLength[ 117513, 2858]
NotebookOptionsPosition[ 101862, 2617]
NotebookOutlinePosition[ 102389, 2637]
CellTagsIndexPosition[ 102346, 2634]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[CellGroupData[{
Cell["Anonymous Recursive Functions", "Title",
CellChangeTimes->{{3.875983045630208*^9, 3.875983057899279*^9}, {
3.8759835180326643`*^9, 3.8759835279140453`*^9}, {3.8761281070959997`*^9,
3.876128125240752*^9}},ExpressionUUID->"fd2bd4a8-94f7-4e1f-b51a-\
cc7a16a24e1c"],
Cell["or, How to Square the Square Root of a Function", "Subtitle",
CellChangeTimes->{{3.876128138742877*^9, 3.876128173002418*^9}, {
3.876137391023239*^9,
3.87613739923882*^9}},ExpressionUUID->"8c54fd4a-cbf4-4245-8219-\
23565cfde7b3"],
Cell["\<\
Brian Beckman
30 Oct 2022\
\>", "Subtitle",
CellChangeTimes->{{3.875752008703356*^9, 3.8757520163109922`*^9}, {
3.876155978027803*^9,
3.876155978158963*^9}},ExpressionUUID->"f342aa65-c42f-417b-bd41-\
73a0d87c5073"],
Cell[CellGroupData[{
Cell["Introduction", "Section",ExpressionUUID->"66213823-9f30-43f9-a69c-35a6b49215a6"],
Cell["\<\
We want to do some calculations on a remote server. The server lets us send \
expressions to evaluate, one at a time, but doesn\[CloseCurlyQuote]t let us \
define variables or functions because that would use up memory. \
\>", "Text",
CellChangeTimes->{{3.875752032257053*^9, 3.8757521502296743`*^9}, {
3.875752201127811*^9, 3.875752303006906*^9}, {3.875752384576346*^9,
3.875752394501297*^9}, {3.8759493237354918`*^9, 3.875949345827779*^9}, {
3.8759493859659557`*^9, 3.875949418311593*^9}, {3.8759494521398573`*^9,
3.87594952370527*^9}, 3.87594956124124*^9, {3.8759662152657423`*^9,
3.875966306369495*^9}, {3.875966456861754*^9, 3.8759665725331078`*^9}, {
3.875975795923296*^9, 3.875975920926976*^9}, {3.875983100668502*^9,
3.875983109392643*^9}, {3.8761281793714027`*^9, 3.876128371818124*^9}, {
3.876128405806897*^9, 3.876128407367545*^9}, {3.8761324026535788`*^9,
3.8761324188076468`*^9}, {3.87613741543918*^9,
3.876137416652529*^9}},ExpressionUUID->"a97068cd-4068-4035-8158-\
a5245c4a0aef"],
Cell["\<\
For example, we want to compute the factorial of a number, say 6, but the \
server doesn't have a built-in for factorial. We'd like to send the standard \
recursive definition\
\>", "Text",
CellChangeTimes->{{3.875752032257053*^9, 3.8757521502296743`*^9}, {
3.875752201127811*^9, 3.875752303006906*^9}, {3.875752384576346*^9,
3.875752394501297*^9}, {3.8759493237354918`*^9, 3.875949345827779*^9}, {
3.8759493859659557`*^9, 3.875949418311593*^9}, {3.8759494521398573`*^9,
3.87594952370527*^9}, 3.87594956124124*^9, {3.8759662152657423`*^9,
3.875966306369495*^9}, {3.875966456861754*^9, 3.8759665725331078`*^9}, {
3.875975795923296*^9, 3.875975920926976*^9}, {3.875983100668502*^9,
3.875983109392643*^9}, {3.8761281793714027`*^9, 3.876128371818124*^9}, {
3.876128405806897*^9, 3.876128407367545*^9}, {3.8761324026535788`*^9,
3.876132422860383*^9}},ExpressionUUID->"ca6d1115-6182-4e4c-8602-\
cf53f501f540"],
Cell[BoxData[
RowBox[{
RowBox[{"fact", "[", "n_", "]"}], ":=",
RowBox[{"If", "[",
RowBox[{
RowBox[{"n", "<", "1"}], ",", "1", ",",
RowBox[{"n", " ",
RowBox[{"fact", "[",
RowBox[{"n", "-", "1"}], "]"}]}]}], "]"}]}]], "Input",
CellChangeTimes->{{3.8759524691213512`*^9, 3.8759524953139353`*^9}},
CellLabel->"In[2]:=",ExpressionUUID->"db4d9c66-a68a-4643-9b77-34be6f90e7e0"],
Cell["then, call it like this:", "Text",
CellChangeTimes->{{3.875952510093158*^9, 3.875952524149242*^9}, {
3.8759763087998877`*^9, 3.875976309975699*^9}, {3.876128423012834*^9,
3.876128428647091*^9}},ExpressionUUID->"84ff38a6-7bec-4038-9d02-\
aef87728eb0f"],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{"fact", "[", "6", "]"}]], "Input",
CellChangeTimes->{{3.875952526214127*^9, 3.875952528918627*^9}},
CellLabel->"In[3]:=",ExpressionUUID->"661f1a75-59d7-4d44-b713-32f38fcaabf4"],
Cell[BoxData["720"], "Output",
CellChangeTimes->{3.875952529720315*^9, 3.875975468618905*^9,
3.875976312223229*^9, 3.876039809376045*^9, 3.87604081797443*^9,
3.876128434992824*^9, 3.876138833351823*^9, 3.876146419888797*^9,
3.876146781746271*^9, 3.876156749110838*^9, 3.876209998784124*^9,
3.8762317570628853`*^9},
CellLabel->"Out[3]=",ExpressionUUID->"6b28cff5-fd6c-454d-b3b2-639f8e806517"]
}, Open ]],
Cell[TextData[{
"But that\[CloseCurlyQuote]s two shots, and we only get one shot. We can\
\[CloseCurlyQuote]t define ",
StyleBox["fact", "Input"],
", using up memory in the server\[CloseCurlyQuote]s symbol table, and then \
use it on the next shot. "
}], "Text",
CellChangeTimes->{{3.876132433196454*^9,
3.876132472881579*^9}},ExpressionUUID->"7b6f13ab-6231-472a-9ca6-\
ebcd62b37ed2"],
Cell["\<\
Are we out of luck? No. In fact, The following does the trick, as this \
article explains:\
\>", "Text",
CellChangeTimes->{{3.876132476745596*^9, 3.876132497206154*^9}, {
3.876156003480082*^9, 3.876156032276099*^9},
3.8761562110588512`*^9},ExpressionUUID->"6863d142-b9c6-4e93-9afe-\
40f26a79f01d"],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{
RowBox[{
RowBox[{"(",
RowBox[{"d", "\[Function]",
RowBox[{
RowBox[{"(",
RowBox[{"g", "\[Function]",
RowBox[{"g", "@", "g"}]}], ")"}], "[",
RowBox[{"sf", "\[Function]",
RowBox[{"d", "[",
RowBox[{"m", "\[Function]",
RowBox[{
RowBox[{"sf", "[", "sf", "]"}], "@", "m"}]}], "]"}]}], "]"}]}],
")"}], "[", "\[IndentingNewLine]",
RowBox[{"f", "\[Function]",
RowBox[{"n", "\[Function]",
RowBox[{"If", "[",
RowBox[{
RowBox[{"n", "<", "1"}], ",", "1", ",",
RowBox[{"n", " ",
RowBox[{"f", "[",
RowBox[{"n", "-", "1"}], "]"}]}]}], "]"}]}]}], "]"}], "@",
"6"}]], "Input",
CellChangeTimes->{{3.876156052335063*^9, 3.876156109128944*^9}, {
3.8761561662901707`*^9, 3.87615619699404*^9}, {3.876156244084908*^9,
3.876156254339106*^9}},
CellLabel->"In[4]:=",ExpressionUUID->"65d55b00-fe4b-4eb8-a4b3-8e7f69913ffd"],
Cell[BoxData["720"], "Output",
CellChangeTimes->{3.876156189227521*^9, 3.8761562639436913`*^9,
3.876156749125136*^9, 3.8762099987957687`*^9, 3.876231757066049*^9},
CellLabel->"Out[4]=",ExpressionUUID->"6627b7b0-62a2-443d-be3e-b7b1cb077a34"]
}, Open ]],
Cell["\<\
We\[CloseCurlyQuote]ll show how to convert any recursive function into an \
anonymous version of itself. Furthermore, to sweeten the deal, we\
\[CloseCurlyQuote]ll show how to convert expensive anonymous recursive \
functions into cheap anonymous recursive functions. We\[CloseCurlyQuote]ll do \
it in Mathematica and talk about doing it in Scheme and Python.\
\>", "Text",
CellChangeTimes->{{3.8761325051383944`*^9,
3.8761325854349117`*^9}},ExpressionUUID->"1b9adf9f-8750-45b6-abac-\
744f2e84db48"]
}, Closed]],
Cell[CellGroupData[{
Cell["Anonymous Functions", "Section",
CellChangeTimes->{{3.87596659867258*^9,
3.8759666039088497`*^9}},ExpressionUUID->"52109211-66fd-4fe4-8805-\
bd5da1976f54"],
Cell[TextData[{
"We already know how to define functions that don't have names: lambda \
expressions. Mathematica has a concise notation. Here is one that computes \
its argument, ",
StyleBox["x", "Input"],
", times ",
StyleBox["(x+1)", "Input"],
", its argument plus one: "
}], "Text",
CellChangeTimes->{{3.875752032257053*^9, 3.8757521502296743`*^9}, {
3.875752201127811*^9, 3.875752303006906*^9}, {3.875752384576346*^9,
3.875752394501297*^9}, {3.8759493237354918`*^9, 3.875949345827779*^9}, {
3.8759493859659557`*^9, 3.875949418311593*^9}, {3.8759494521398573`*^9,
3.87594952370527*^9}, {3.875949564795478*^9, 3.8759495908427896`*^9}, {
3.875975939948752*^9, 3.875975946819064*^9}, {3.8761326140836687`*^9,
3.876132627168042*^9}},ExpressionUUID->"02974c69-f558-4585-a116-\
18f5140034c3"],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{"x", "\[Function]",
RowBox[{"x", "*",
RowBox[{"(",
RowBox[{"x", "+", "1"}], ")"}]}]}]], "Input",
CellChangeTimes->{{3.87575231461078*^9, 3.8757523262078876`*^9}, {
3.8757524000841007`*^9, 3.875752403410125*^9}},
CellLabel->"In[5]:=",ExpressionUUID->"b23c1d37-f57f-42bc-ad0b-24f050eb549a"],
Cell[BoxData[
RowBox[{"Function", "[",
RowBox[{"x", ",",
RowBox[{"x", " ",
RowBox[{"(",
RowBox[{"x", "+", "1"}], ")"}]}]}], "]"}]], "Output",
CellChangeTimes->{3.875752339150894*^9, 3.87575240410194*^9,
3.876039809343498*^9, 3.8760408179378033`*^9, 3.876138833363241*^9,
3.876146419896845*^9, 3.8761467817572813`*^9, 3.8761567491320667`*^9,
3.8762099988038282`*^9, 3.876231757076663*^9},
CellLabel->"Out[5]=",ExpressionUUID->"2a8177ab-5bd4-4d5a-8e6a-c0996b0980d1"]
}, Open ]],
Cell[CellGroupData[{
Cell["Notation", "Subsection",
CellChangeTimes->{{3.8758940367645206`*^9,
3.875894038238222*^9}},ExpressionUUID->"95463c69-5220-462f-bf90-\
ea125a5dfd89"],
Cell[TextData[{
"That is a lambda expression of one argument, namely ",
StyleBox["x", "Input"],
". Read it as \[OpenCurlyDoubleQuote]the function of ",
Cell[BoxData[
FormBox["x", TraditionalForm]],ExpressionUUID->
"95b8e2bc-78c3-41af-85a0-7b34213e10a9"],
" that produces ",
Cell[BoxData[
FormBox["x", TraditionalForm]],ExpressionUUID->
"bc8a50b3-285c-41c6-987a-9d5e6f535211"],
" times ",
Cell[BoxData[
FormBox[
RowBox[{"(",
RowBox[{"x", "+", "1"}], ")"}], TraditionalForm]],ExpressionUUID->
"7f78c023-2dc2-4b40-ae86-6922e4179305"],
", or ",
Cell[BoxData[
FormBox[
RowBox[{"x", "(",
RowBox[{"x", "+", "1"}], ")"}], TraditionalForm]],ExpressionUUID->
"66f23e05-cc05-4cdc-b2bc-46714df13d5d"],
".\[CloseCurlyDoubleQuote] The star for multiplication is optional in \
Mathematica, so you can write ",
StyleBox["x*(x+1)", "Input"],
" as ",
StyleBox["x(x+1)", "Input"],
". In Scheme or Python, you must write the star."
}], "Text",
CellChangeTimes->{{3.8757523456742363`*^9, 3.875752372692271*^9}, {
3.87575241449815*^9, 3.8757524333116302`*^9}, {3.8758905735347548`*^9,
3.875890623420122*^9}, {3.875893820290018*^9, 3.875893844809401*^9}, {
3.875894051240534*^9, 3.8758940546269407`*^9}, {3.875949612342842*^9,
3.8759497733094053`*^9}, {3.875966621634473*^9, 3.875966621827832*^9}, {
3.87597602578823*^9, 3.8759760631845837`*^9}, {3.876132673325836*^9,
3.876132686868585*^9}, {3.876132731197155*^9,
3.876132749233069*^9}},ExpressionUUID->"bb10294e-da1d-48b9-b1b9-\
da85c84e60c4"],
Cell[TextData[{
"We know how to apply such a lambda expression to an actual argument, say, \
to 6: wrap the lambda expression in parentheses and follow it with an ",
StyleBox["@", "Input"],
" sign:"
}], "Text",
CellChangeTimes->{{3.8757523456742363`*^9, 3.875752372692271*^9}, {
3.87575241449815*^9, 3.8757524333116302`*^9}, {3.8758905735347548`*^9,
3.875890623420122*^9}, {3.875893820290018*^9, 3.875893844809401*^9}, {
3.875894051240534*^9, 3.8758940546269407`*^9}, {3.875949612342842*^9,
3.8759497733094053`*^9}, {3.875966621634473*^9, 3.875966621827832*^9}, {
3.87597602578823*^9, 3.8759760731601067`*^9}, {3.876132759654827*^9,
3.876132763119193*^9}},ExpressionUUID->"8cab5101-bb3c-4322-87b0-\
ccbcf6501a08"],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{
RowBox[{"(",
RowBox[{"x", "\[Function]",
RowBox[{"x",
RowBox[{"(",
RowBox[{"x", "+", "1"}], ")"}]}]}], ")"}], "@", "6"}]], "Input",
CellChangeTimes->{{3.875752437539855*^9, 3.875752459361912*^9}},
CellLabel->"In[6]:=",ExpressionUUID->"adc58a46-f013-4993-85fa-5b69b6e8fad1"],
Cell[BoxData["42"], "Output",
CellChangeTimes->{3.875752479825653*^9, 3.876039809349579*^9,
3.876040817942012*^9, 3.876138833368346*^9, 3.87614641990672*^9,
3.8761467817626247`*^9, 3.8761567491432133`*^9, 3.876209998813861*^9,
3.87623175707977*^9},
CellLabel->"Out[6]=",ExpressionUUID->"27b2fcdc-eae7-44c3-9502-dd5d827e990f"]
}, Open ]],
Cell["\<\
Or, write the function application with square brackets like this:\
\>", "Text",
CellChangeTimes->{{3.875752482312272*^9, 3.875752538746085*^9}, {
3.875890640613958*^9, 3.875890650922037*^9}, {3.875949783960093*^9,
3.8759497872061*^9}},ExpressionUUID->"211b7dcc-fb0d-41b5-b46b-20ef7b4b7ee1"],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{
RowBox[{"(",
RowBox[{"x", "\[Function]",
RowBox[{"x",
RowBox[{"(",
RowBox[{"x", "+", "1"}], ")"}]}]}], ")"}], "[", "6", "]"}]], "Input",
CellChangeTimes->{{3.8757525440391808`*^9, 3.875752569035527*^9}},
CellLabel->"In[7]:=",ExpressionUUID->"ad6e14a3-f34d-4356-a855-a578b1fafb5c"],
Cell[BoxData["42"], "Output",
CellChangeTimes->{{3.87575256022471*^9, 3.875752570265395*^9},
3.876039809361198*^9, 3.876040817957205*^9, 3.876138833379039*^9,
3.876146419913425*^9, 3.8761467817730703`*^9, 3.876156749150028*^9,
3.876209998822543*^9, 3.876231757088962*^9},
CellLabel->"Out[7]=",ExpressionUUID->"709447c0-098b-4aa2-b533-b3e14b381b75"]
}, Open ]],
Cell[TextData[{
"The meaning is exactly the same. ",
StyleBox["x@y", "Input"],
" means the same as ",
StyleBox["x[y]", "Input"],
", no matter what ",
StyleBox["x", "Input"],
" and ",
StyleBox["y", "Input"],
" mean. We choose one or the other at will to satisfy subjective aesthetics."
}], "Text",
CellChangeTimes->{{3.875752574345461*^9, 3.875752611721991*^9}, {
3.87589066008311*^9, 3.875890661938134*^9}, {3.876132776656464*^9,
3.876132812966752*^9}, {3.876135583754128*^9,
3.876135584748054*^9}},ExpressionUUID->"5c638a07-2602-4ab5-98fc-\
b306e9105a13"],
Cell[TextData[{
"In the following, Script letters like \[ScriptCapitalD], \[ScriptCapitalE], \
\[ScriptCapitalF], \[ScriptCapitalL], and \[ScriptCapitalY], are ",
StyleBox["notional names",
FontWeight->"Bold",
FontSlant->"Italic"],
": non-denotable names, names we can\[CloseCurlyQuote]t write in our \
programming language, but names of denotable things we need to think about \
and don\[CloseCurlyQuote]t want to keep writing out verbatim over and over \
again. For example, we\[CloseCurlyQuote]ll see the following symbol-blizzard \
over and over again:"
}], "Text",
CellChangeTimes->{{3.87613559056726*^9, 3.876135710774794*^9}, {
3.8761358131175957`*^9, 3.876135818920385*^9}, {3.8761368158931303`*^9,
3.8761370605645514`*^9}},ExpressionUUID->"81fbdc01-7a9c-413f-ae9e-\
9279bb3f8174"],
Cell[TextData[{
" ",
StyleBox["d\[Function](g\[Function]g@g)[sf\[Function]d[m\[Function]sf[sf]@m]]\
", "Input"]
}], "Text",
CellChangeTimes->{{3.87613559056726*^9, 3.876135710774794*^9}, {
3.8761358131175957`*^9, 3.876135818920385*^9}, {3.8761368158931303`*^9,
3.87613706971231*^9}},ExpressionUUID->"8bc711a4-0012-4b19-8c54-\
616889c22cd2"],
Cell["\<\
That's a literal, denotable expression that we'll send to our server as part \
of other expressions. But it's too much to look at while thinking, so we'll \
just call it \[ScriptCapitalY] for the sake of discussion. In fact, \
explaining that expression is the whole point of this article. It\
\[CloseCurlyQuote]s a gadget that makes anonymous recursive functions and \
passes them into domain code for application; twisty!\
\>", "Text",
CellChangeTimes->{{3.87613559056726*^9, 3.876135710774794*^9}, {
3.8761358131175957`*^9, 3.876135818920385*^9}, {3.8761368158931303`*^9,
3.876137051958192*^9}, {3.876137082085371*^9, 3.876137199337034*^9}, {
3.876207449572706*^9,
3.87620747354596*^9}},ExpressionUUID->"b94e8a04-586f-49ac-8bea-\
129870008864"]
}, Open ]]
}, Closed]],
Cell[CellGroupData[{
Cell["Recursion as Squaring the Square Root", "Section",
CellChangeTimes->{{3.875951506789247*^9,
3.875951516306856*^9}},ExpressionUUID->"27c3884a-a0d8-4a75-8112-\
2af65ae2c2a3"],
Cell[TextData[{
"It turns out we can evaluate anonymous recursive functions in one shot. We\
\[CloseCurlyQuote]ll do it by ",
StyleBox["taking the square root ",
FontWeight->"Bold",
FontSlant->"Italic"],
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"abea1d14-1833-43a8-b99d-36e8dd1e9d3c"],
StyleBox[" of the function \[ScriptCapitalF] that we want",
FontWeight->"Bold",
FontSlant->"Italic"],
", in a notional space where squaring the function ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"596f88c2-48c4-4236-983d-8ad21404c0c9"],
" is applying ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"dcbef937-a506-4718-8d6f-0702f1b2ea10"],
" to itself. For example, we want ",
StyleBox["fact", "Input"],
", but the server doesn\[CloseCurlyQuote]t let us define the name ",
StyleBox["fact", "Input"],
". But the server does let us define temporary names that go away in one \
shot. Those names are the ",
StyleBox["formal parameters",
FontSlant->"Italic"],
" of lambda expressions. So if we can define ",
Cell[BoxData[
FormBox[
SqrtBox["fact"], TraditionalForm]],ExpressionUUID->
"7afcf994-0b73-406b-a389-0d7d768c0e45"],
" and then apply it to itself -- square it -- we get the same effect as ",
StyleBox["fact", "Input"],
". "
}], "Text",
CellChangeTimes->{{3.8759498151177588`*^9, 3.87595011841362*^9}, {
3.875950152932148*^9, 3.875950694108616*^9}, {3.875950767648759*^9,
3.875951031633031*^9}, {3.8759511313982*^9, 3.875951272153451*^9}, {
3.8759513665243683`*^9, 3.8759515023097897`*^9}, {3.875951537362299*^9,
3.8759520229146833`*^9}, {3.875952057050878*^9, 3.8759520581925917`*^9}, {
3.875966663426443*^9, 3.875966709015279*^9}, {3.87596677847677*^9,
3.875966869418707*^9}, {3.875975202129072*^9, 3.875975210465087*^9}, {
3.876132836546885*^9, 3.876132955098763*^9}, {3.876133092139835*^9,
3.876133095826929*^9}, {3.876133135646656*^9, 3.876133266541616*^9}, {
3.876133302191669*^9, 3.876133307833406*^9}, {3.87613334341333*^9,
3.876133398470317*^9}, {3.8761337733707333`*^9, 3.8761338049164667`*^9}, {
3.8761338585933723`*^9, 3.876133870177917*^9}, {3.876207486467802*^9,
3.876207576627172*^9}},ExpressionUUID->"62525133-ca64-4044-adc0-\
bb40c53976b1"],
Cell[TextData[{
"More generally, for any function \[ScriptCapitalF], pass ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"cd4867d1-03d9-483e-9434-42c5f75e6e4c"],
" as an actual argument to ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"3d95cc86-22e9-4dca-9c17-17b18c3afdd2"],
". When ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"35e94bd6-72a1-4a53-b404-356c6276c641"],
" is invoked, bind the actual argument ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"6866b52c-28d9-437f-bfe1-6821402612d9"],
" to the parameter ",
StyleBox["sf", "Input"],
". In the body of ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"fb8539ee-f7fd-478a-9208-aaf3ddd9ee16"],
", refer to \[ScriptCapitalF] by the expression ",
StyleBox["sf[sf]", "Input"],
Cell[BoxData[
FormBox[
RowBox[{"=",
RowBox[{
RowBox[{
SqrtBox["\[ScriptCapitalF]"], "[",
SqrtBox["\[ScriptCapitalF]"], "]"}], "=",
RowBox[{
SuperscriptBox[
RowBox[{"(",
SqrtBox[
RowBox[{"\[ThinSpace]", "\[ScriptCapitalF]"}]], "\[ThinSpace]",
")"}], "2"], "=", " ", "\[ScriptCapitalF]"}]}]}], TraditionalForm]],
ExpressionUUID->"cc164630-4771-4c12-aebb-ed16cfe05f46"],
"; square the square root ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"90c8ddc6-fa3d-4f42-adf6-9911a51097a0"],
" to get the recursive function \[ScriptCapitalF] that we want. What a \
great trick! Turns out we can easily compute ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"74589c11-9d13-453a-b93b-25257175e5c0"],
"for any function \[ScriptCapitalF]. We do ",
StyleBox["fact", "Input"],
" as an example, first, then generalize."
}], "Text",
CellChangeTimes->CompressedData["
1:eJxTTMoPSmViYGAQBmIQve7I43knH7xxTLA5ewREa1yRPQmiT1Qe5jkFpBcd
+iIKok85fjED0Xz7cpxBtNBLllAQveD4hQQQfeblyUIQ/WW6dhmI1khpnw2i
zc0/7gDRkxQ2XADRPk+db4L1bbO/BaLdTpd9uQik9xhc+AaireTX/gLRauqO
TJeA9KviOLZrQLqu5okyiF44OUsTRP/SUdYG0fvyRMtAdKuTWiOIVul+2Qai
LW6EdIPoa0/jgpUfvnH8wPoxHkTzXn6dBqJLrkDoKx90KkD0uoiMKhDNVWTa
BKJPaRp1g2i15A/17kD6V/ilNhANABPVthQ=
"],ExpressionUUID->"1fc70bd3-f0b3-415d-8f56-abf565e13dc7"],
Cell[CellGroupData[{
Cell[TextData[{
"The Square Root of ",
StyleBox["Factorial",
FontSlant->"Italic"]
}], "Subsection",
CellChangeTimes->{{3.876133997490362*^9,
3.87613400354106*^9}},ExpressionUUID->"262893cc-da17-4717-8ae3-\
0773ae2df7d8"],
Cell[TextData[{
"To get the square root of factorial, just assume it exists and has a name, ",
StyleBox["sf", "Input"],
", in the only allowed place, as the parameter of a lambda expression, \
notionally called ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"498cf285-5d63-410d-b103-74a93d565394"],
". In the body of ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"55420885-a22b-4a51-96c2-bd407e97bfb6"],
", apply ",
StyleBox["sf[sf]", "Input"],
", the square of ",
StyleBox["sf", "Input"],
", wherever you want factorial, \[ScriptCapitalF]. What is the value of ",
StyleBox["sf", "Input"],
"? Just ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"b5d592f4-7c48-4b41-a251-9edd4b725423"],
" itself! So ",
Cell[BoxData[
FormBox[
RowBox[{
SqrtBox["\[ScriptCapitalF]"], "[",
SqrtBox["\[ScriptCapitalF]"], "]"}], TraditionalForm]],ExpressionUUID->
"27beb3ff-d0a6-4f59-924e-cb197472d76b"],
" must be factorial, and we can apply it to numerical arguments:"
}], "Text",
CellChangeTimes->{{3.8759498151177588`*^9, 3.87595011841362*^9}, {
3.875950152932148*^9, 3.875950694108616*^9}, {3.875950767648759*^9,
3.875951031633031*^9}, {3.8759511313982*^9, 3.8759512059908733`*^9}, {
3.875952283990959*^9, 3.8759522984085073`*^9}, {3.875952354060143*^9,
3.875952447711186*^9}, {3.875952974419922*^9, 3.8759529804870863`*^9}, {
3.8759530129967117`*^9, 3.875953081429677*^9}, {3.875975530044833*^9,
3.8759756163723993`*^9}, {3.875976340061605*^9, 3.875976452671773*^9}, {
3.875976486559819*^9, 3.875976542145916*^9}, {3.875976606237112*^9,
3.875976647244276*^9}, {3.87597670763535*^9, 3.87597672956987*^9}, {
3.875976866885113*^9, 3.875976869664228*^9}, {3.8761340705084333`*^9,
3.876134273563055*^9}, {3.876134309792894*^9, 3.8761344734764137`*^9}, {
3.876134561140066*^9, 3.8761345721879*^9}, 3.8762072738975477`*^9, {
3.8762077020139723`*^9,
3.8762077420578613`*^9}},ExpressionUUID->"d6306fa7-3c11-43a8-b4d4-\
0fd46b455a08"],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{
RowBox[{"(",
RowBox[{
RowBox[{"(",
RowBox[{
StyleBox["sf",
Background->RGBColor[1, 1, 0]], "\[Function]",
RowBox[{"n", "\[Function]",
RowBox[{"If", "[",
RowBox[{
RowBox[{"n", "<", "1"}], ",", "1", ",",
RowBox[{"n", " ",
RowBox[{
StyleBox[
RowBox[{
StyleBox[
RowBox[{"s",
StyleBox["f",
Background->RGBColor[1, 1, 0]]}]], "[", "sf", "]"}],
Background->RGBColor[1, 1, 0]], "[",
RowBox[{"n", "-", "1"}], "]"}]}]}], "]"}]}]}], ")"}], "@",
"\[IndentingNewLine]",
RowBox[{"(",
RowBox[{
StyleBox["sf",
Background->RGBColor[1, 1, 0]], "\[Function]",
RowBox[{"n", "\[Function]",
RowBox[{"If", "[",
RowBox[{
RowBox[{"n", "<", "1"}], ",", "1", ",",
RowBox[{"n", " ",
RowBox[{
StyleBox[
RowBox[{
StyleBox[
RowBox[{"s",
StyleBox["f",
Background->RGBColor[1, 1, 0]]}]], "[", "sf", "]"}],
Background->RGBColor[1, 1, 0]], "[",
RowBox[{"n", "-", "1"}], "]"}]}]}], "]"}]}]}], ")"}]}], ")"}], "@",
"6"}]], "Input",
CellChangeTimes->{{3.8757526606287937`*^9, 3.875752698582417*^9}, {
3.875953114662562*^9, 3.8759531184567537`*^9}, {3.875976764817629*^9,
3.8759767717024803`*^9}},
CellLabel->"In[8]:=",ExpressionUUID->"6aff6d0b-2d4b-42eb-a3bb-4f19bb80e53f"],
Cell[BoxData["720"], "Output",
CellChangeTimes->{{3.875752674576541*^9, 3.875752699710327*^9},
3.875953119111864*^9, 3.875976735569635*^9, 3.875976775590383*^9,
3.87603980938164*^9, 3.8760408179806557`*^9, 3.876134280070704*^9, {
3.8761344768794327`*^9, 3.876134502421924*^9}, 3.876138833384548*^9,
3.8761464199235773`*^9, 3.876146781778714*^9, 3.876156749161336*^9,
3.8762099988332233`*^9, 3.876231757093541*^9},
CellLabel->"Out[8]=",ExpressionUUID->"31ad22cc-764c-400f-9aa5-36fc18313cd8"]
}, Open ]],
Cell[TextData[{
"Before the final actual argument, ",
StyleBox["6", "Input"],
", and its application symbol, ",
StyleBox["@", "Input"],
", there is a lambda expression ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"926331f8-902c-4ca2-bc5c-90a995c7fb5e"],
" of one parameter ",
StyleBox["sf", "Input"],
" applied to a cut-and-paste copy of its whole self via another application \
symbol ",
StyleBox["@", "Input"],
". That self-application squares the function ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"0427be31-c334-48b8-b95d-6d8375f7676d"],
". Inside the recursive body -- inside the ",
StyleBox["If[...]", "Input"],
" part -- there is a similar self-application, ",
StyleBox["sf[sf]", "Input"],
", applied to a numerical argument, ",
StyleBox["[n-1]", "Input"],
". So we see that the external squaring, ",
StyleBox["((sf\[Function]...)@(sf\[Function]...))", "Input"],
" produces the same result as the internal squaring ",
StyleBox["sf[sf]", "Input"],
". "
}], "Text",
CellChangeTimes->{{3.875752830926454*^9, 3.875752835077785*^9}, {
3.875752866173807*^9, 3.875752928381714*^9}, {3.875752997966743*^9,
3.875753108532607*^9}, 3.875753185369327*^9, {3.875890728472142*^9,
3.8758908341663437`*^9}, {3.875893909566122*^9, 3.8758939704422493`*^9}, {
3.8758941195898533`*^9, 3.875894128037513*^9}, {3.875894213350182*^9,
3.8758942636416693`*^9}, {3.8758943192336473`*^9, 3.875894365325261*^9}, {
3.8759531427296267`*^9, 3.87595325638822*^9}, {3.875965955774766*^9,
3.875966169906784*^9}, {3.8759671470741653`*^9, 3.875967252215757*^9}, {
3.8759767931108847`*^9, 3.875976864230033*^9}, {3.876134583077095*^9,
3.8761346459691973`*^9}, {3.876134684473033*^9,
3.8761347042459583`*^9}},ExpressionUUID->"3c7cd9f7-125c-4bf6-8a55-\
4b0b3440fdea"],
Cell[TextData[{
"This is enough. Stop here if all you care about is a programming pattern \
for anonymous, remotable, recursive functions: just replace the body of the \
function, namely the ",
StyleBox["If[...]", "Input"],
" part, in both places where it occurs, with the body of your desired \
recursive function, and call your function recursively via the \
self-application syntax ",
StyleBox["sf[sf]", "Input"],
". We\[CloseCurlyQuote]ll show another example, ",
StyleBox["fib", "Input"],
", later."
}], "Text",
CellChangeTimes->{{3.875752830926454*^9, 3.875752835077785*^9}, {
3.875752866173807*^9, 3.875752928381714*^9}, {3.875752997966743*^9,
3.875753108532607*^9}, 3.875753185369327*^9, {3.875890728472142*^9,
3.8758908341663437`*^9}, {3.875953272956155*^9, 3.875953288007963*^9}, {
3.875967262362904*^9, 3.875967288972953*^9}, 3.8759706446364393`*^9, {
3.875976882495142*^9, 3.87597689110715*^9}, {3.876134747502763*^9,
3.87613475330055*^9}, {3.876134834824012*^9,
3.8761348360927353`*^9}},ExpressionUUID->"81a5aae0-3ada-4118-bdce-\
9cfe2b487c6f"],
Cell[TextData[{
"However, there are worthwhile improvements. We can automate the programming \
pattern. We can write a general function \[ScriptCapitalY] that squares the \
square root of ",
StyleBox["any",
FontSlant->"Italic"],
" function \[ScriptCapitalF]."
}], "Text",
CellChangeTimes->{{3.875753240311246*^9, 3.8757532426278467`*^9}, {
3.875894378187549*^9, 3.8758943912777777`*^9}, {3.8759533245623627`*^9,
3.875953492071488*^9}, {3.875976935262492*^9, 3.875976937146491*^9}, {
3.876134841349161*^9,
3.876134889615233*^9}},ExpressionUUID->"5c7e3a6d-a26f-477c-b200-\
7cfe36472ee6"]
}, Open ]]
}, Open ]],
Cell[CellGroupData[{
Cell["\<\
Four Improvements: Two Abstractions, One Model, and Packaging\
\>", "Section",ExpressionUUID->"12a60a65-726b-44f3-b242-9be81a493e6e"],
Cell[TextData[{
"To refresh the main idea: we have a square root ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"20ea0a92-dcd5-46d2-a509-53c98cf928fd"],
", that, when squared, produces the recursive ",
StyleBox["domain function",
FontWeight->"Bold",
FontSlant->"Italic"],
" \[ScriptCapitalF] of the ",
StyleBox["domain parameters",
FontWeight->"Bold",
FontSlant->"Italic"],
"; \[ScriptCapitalF] does the real work we want. "
}], "Text",
CellChangeTimes->{
3.875751297095121*^9, {3.875893679886125*^9, 3.875893684558876*^9}, {
3.875894623979939*^9, 3.875894637093479*^9}, {3.8759686345190487`*^9,
3.87596864602382*^9}, {3.875968686825247*^9, 3.875968752944772*^9}, {
3.875968784465831*^9, 3.875968790489154*^9}, {3.8759688490587473`*^9,
3.875968851180005*^9}, {3.8759693426823387`*^9, 3.875969353246682*^9}, {
3.875969383439769*^9, 3.8759694216558723`*^9}, {3.875970727443735*^9,
3.875970772751371*^9}, {3.875970803018442*^9, 3.8759708054235477`*^9}, {
3.875970876507608*^9, 3.875970904869075*^9}, {3.875976956679798*^9,
3.8759769628964977`*^9}, {3.876134898059333*^9, 3.876135080919333*^9}, {
3.876207871362135*^9,
3.8762078823030443`*^9}},ExpressionUUID->"cb918ae4-e25d-4dbf-ae15-\
5ba2ce0bf6f4"],
Cell[TextData[{
"Let's make a ",
StyleBox["combinator",
FontWeight->"Bold",
FontSlant->"Italic"],
" (a function of a function) that can convert ",
StyleBox["any",
FontSlant->"Italic"],
" function into a new function that receives its self application, the \
recursive function ",
StyleBox["f=sf[sf]", "Input"],
", as its first argument. This is a twist on the prior development. We want ",
StyleBox["sf[sf]", "Input"],
" as the value of the first parameter ",
StyleBox["f", "Input"],
". We want to write ",
StyleBox["((...)[f\[Function]n\[Function]...])@6", "Input"],
" in our example, with ",
StyleBox["f", "Input"],
" as the domain function ",
StyleBox["sf[sf]", "Input"],
" and ",
StyleBox["n", "Input"],
" as the domain parameter. We must solve for ",
StyleBox["(...)", "Input"],
"."
}], "Text",
CellChangeTimes->{{3.875968941057325*^9, 3.875968988609809*^9}, {
3.875969026876877*^9, 3.87596904338936*^9}, {3.875969141256586*^9,
3.875969252702017*^9}, 3.8759693229458313`*^9, {3.875969466975835*^9,
3.875969513353014*^9}, {3.8759769997330637`*^9, 3.875977066571773*^9}, {
3.87613510646485*^9, 3.8761351106783457`*^9}, {3.876135151103304*^9,
3.876135226350602*^9}, {3.876139326332052*^9, 3.876139327154339*^9}, {
3.876207907875594*^9,
3.8762080379943666`*^9}},ExpressionUUID->"2271a2b2-4102-45eb-a85f-\
fcc375a19c17"],
Cell[TextData[{
"Solve in two steps: first, start with the prior development, in which ",
StyleBox["sf", "Input"],
" is the parameter in a cut-and-paste squaring of ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"7ee785f6-2bff-4fc3-a2dd-0e140377057f"],
". Inside the domain code -- inside ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],ExpressionUUID->
"724b5c0e-c7c2-408e-9d35-383ba7f98125"],
" -- replace the square ",
StyleBox["sf[sf]", "Input"],
" by the parameter ",
StyleBox["f", "Input"],
" of a new anonymous function of ",
StyleBox["f", "Input"],
". Apply the new anonymous function of ",
StyleBox["f", "Input"],
" to the actual argument ",
StyleBox["sf[sf]", "Input"],
". "
}], "Text",
CellChangeTimes->{{3.8759770812044697`*^9, 3.875977121709116*^9}, {
3.875977166068787*^9, 3.8759773399930487`*^9}, {3.8761352586406803`*^9,
3.876135419003484*^9}, {3.876135478283821*^9, 3.8761355614866867`*^9},
3.87613576070566*^9, {3.876208049120565*^9,
3.8762081383977737`*^9}},ExpressionUUID->"dee1cc73-ca42-4d1e-aca7-\
5d9cf4561b12"],
Cell[TextData[{
"That's what ",
StyleBox["abstraction",
FontWeight->"Bold",
FontSlant->"Italic"],
" means in general: replacing an expression \[ScriptCapitalE] with a \
parameter ",
StyleBox["e", "Input"],
" of a new anonymous function, then applying that new function to \
\[ScriptCapitalE] as an actual argument which becomes the value of the \
parameter ",
StyleBox["e", "Input"],
". "
}], "Text",
CellChangeTimes->{{3.8759770812044697`*^9, 3.875977121709116*^9}, {
3.875977166068787*^9, 3.8759773399930487`*^9}, {3.8761352586406803`*^9,
3.876135419003484*^9}, {3.876135478283821*^9, 3.8761355614866867`*^9},
3.87613576070566*^9, {3.876208049120565*^9,
3.8762081904033937`*^9}},ExpressionUUID->"1e400640-3cd0-4f90-9db7-\
004898999b22"],
Cell[TextData[{
"In the second step, abstract the domain code into a parameter ",
StyleBox["d", "Input"],
" of the final, general combinator \[ScriptCapitalY] (a notional name only) \
so that ",
StyleBox["we write the domain code only once",
FontSlant->"Italic"],
". "
}], "Text",
CellChangeTimes->{{3.875969590351989*^9, 3.875969595102777*^9}, {
3.87597735108322*^9, 3.875977403420147*^9}, {3.876135794334737*^9,
3.876135800105279*^9}, {3.876135834995262*^9, 3.876135856240663*^9}, {
3.8762082465716257`*^9,
3.876208265854491*^9}},ExpressionUUID->"589a1e3c-3e40-4316-88f7-\
2a0628d40107"],
Cell["Here are all the improvements, spelled out for factorial:", "Text",
CellChangeTimes->{{3.875969590351989*^9, 3.875969595102777*^9}, {
3.87597735108322*^9, 3.875977403420147*^9}, {3.876135794334737*^9,
3.876135800105279*^9}, {3.876135834995262*^9, 3.876135856240663*^9}, {
3.8762082465716257`*^9,
3.876208260415159*^9}},ExpressionUUID->"2bc71a78-a671-4493-975b-\
e00dc7d9ca6f"],
Cell[CellGroupData[{
Cell["Step 1: Abstract the Internal Self-Application", "Subsection",
CellChangeTimes->{{3.8758912591598997`*^9,
3.875891261699935*^9}},ExpressionUUID->"a3b69a91-3eee-42e0-9dde-\
a14c74431e62"],
Cell[TextData[{
"Looking at the body of ",
Cell[BoxData[
FormBox[
SqrtBox["\[ScriptCapitalF]"], TraditionalForm]],
FormatType->TraditionalForm,ExpressionUUID->
"9bf74d22-4e80-4121-9688-236ee371469b"],
", namely the ",
StyleBox["If[...]", "Input"],
" part of"
}], "Text",
CellChangeTimes->{{3.875969613159622*^9, 3.875969615672657*^9}, {
3.875977420694866*^9, 3.875977434375744*^9}, {3.876139443416376*^9,
3.87613945154788*^9}},ExpressionUUID->"3dfcf1d3-f45e-4a4b-b655-\
1fedef0d8175"],
Cell[BoxData[
RowBox[{
StyleBox[
RowBox[{"sf", "\[Function]",
RowBox[{"n", "\[Function]",
RowBox[{"If", "[",
RowBox[{
RowBox[{"n", "<", "1"}], ",", "1", ",",
RowBox[{"n", " ",
RowBox[{
RowBox[{"sf", "[", "sf", "]"}], "[",
RowBox[{"n", "-", "1"}], "]"}]}]}], "]"}]}]}], "Input"], ",",
" "}]], "DisplayFormula",
CellChangeTimes->{{3.8759696039178457`*^9, 3.8759696046889143`*^9}, {
3.875977438059353*^9,
3.875977441539665*^9}},ExpressionUUID->"f629143a-79f2-4ac0-be16-\
497d622593ca"],
Cell[TextData[{
"the first task is to abstract the internal self-application ",
StyleBox["sf[sf]", "Input"],
" into a parameter ",
StyleBox["f", "Input"],
" of a new abstracted function of ",
StyleBox["f", "Input"],
" applied to ",
StyleBox["sf[sf]", "Input"],
" (or to ",
StyleBox["sf@sf", "Input"],
", same thing). This is exactly as we had before, only with ",
StyleBox["f", "Input"],
" standing in for s",
StyleBox["f[sf]", "Input"],
". "
}], "Text",
CellChangeTimes->{{3.875891279600771*^9, 3.875891281401867*^9}, {
3.875969631657652*^9, 3.875969634464252*^9}, {3.875977459780801*^9,
3.8759775024370317`*^9}, {3.875978081067724*^9, 3.8759780926492357`*^9}, {
3.875978158713472*^9, 3.8759781766808367`*^9}, {3.875978541582299*^9,
3.875978562836113*^9}, {3.8759786555350924`*^9, 3.8759786797204523`*^9}, {
3.8759787926448812`*^9, 3.8759788228849363`*^9}, {3.875979250858378*^9,
3.875979251561734*^9}, {3.8762082748014193`*^9,
3.8762083418743258`*^9}},ExpressionUUID->"0e85c113-7ca4-4401-823e-\
d23eaa731910"],
Cell[TextData[{
"The fragment highlighted in yellow, below, is the new abstracted function \
of ",
StyleBox["f", "Input"],
". However, this new abstraction fails to terminate even before applied to a \
numerical argument:"
}], "Text",
CellChangeTimes->{{3.875891279600771*^9, 3.875891281401867*^9}, {
3.875969631657652*^9, 3.875969634464252*^9}, {3.875977459780801*^9,
3.8759775024370317`*^9}, {3.875978081067724*^9, 3.8759780926492357`*^9}, {
3.875978158713472*^9, 3.8759781766808367`*^9}, {3.875978541582299*^9,
3.875978562836113*^9}, {3.8759786555350924`*^9, 3.8759786797204523`*^9}, {
3.8759787926448812`*^9, 3.875978830847343*^9}, {3.8761358844121313`*^9,
3.876135912361343*^9}, {3.876208351491416*^9,
3.8762083599210167`*^9}},ExpressionUUID->"031ba252-837e-4e3d-897a-\
9646a6693c95"],
Cell[CellGroupData[{
Cell[BoxData[
RowBox[{
RowBox[{
RowBox[{"(",
RowBox[{"sf", "\[Function]",
StyleBox[
RowBox[{"(",
RowBox[{
RowBox[{"(",
RowBox[{"f", "\[Function]",
RowBox[{"n", "\[Function]",
RowBox[{"If", "[",
RowBox[{
RowBox[{"n", "<", "1"}], ",", "1", ",",
RowBox[{"n", " ",
RowBox[{"f", "[",
RowBox[{"n", "-", "1"}], "]"}]}]}], "]"}]}]}], ")"}], "[",
RowBox[{"sf", "@", "sf"}], "]"}], ")"}],
Background->RGBColor[1, 1, 0]]}], " ", ")"}], "@",
RowBox[{"(*", " ",
RowBox[{"sf", " ", "is", " ", "still", " ", "in", " ",
RowBox[{"scope", "!"}]}], " ", "*)"}], "\[IndentingNewLine]",
RowBox[{"(",
RowBox[{"sf", "\[Function]",