-
Notifications
You must be signed in to change notification settings - Fork 0
/
PCM20210729_SICP_1.1.6_Conditional_Expressions_and_Predicates
2128 lines (1720 loc) · 69.3 KB
/
PCM20210729_SICP_1.1.6_Conditional_Expressions_and_Predicates
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.20.0
using Markdown
using InteractiveUtils
# ╔═╡ 69beb4e8-635b-4366-b81f-0703ad9acbe8
begin
using Pluto
using Plots
using GraphRecipes
#----------------------------------------------------------------
println("pkgversion(Pluto) = ", pkgversion(Pluto))
println("pkgversion(Plots) = ", pkgversion(Plots))
println("pkgversion(GraphRecipes) = ", pkgversion(GraphRecipes))
end # begin
# ╔═╡ 4ba04c25-a29b-4bf0-be10-be3f20279f28
md"
===================================================================================
#### SICP: [1.1.6 Conditional Expressions and Predicates](https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-10.html#%_sec_1.1.6)
##### file: PCM20210729\_SICP\_1.1.6\_Conditional\_Expressions\_and_Predicates.jl
##### Julia/Pluto.jl-code (1.11.2/0.20.3) by PCM *** 2024/12/29 ***
===================================================================================
"
# ╔═╡ e8d5627a-1e6a-48a4-ad50-6013870b8890
md"
##### 0. Introduction
Up to now problem solving and evaluation of expressions could *not* be *situation dependent*. We need constructs controlling the evaluation process. This can be achieved e.g. by a *ternary* *nonstrict* expression: $<predicate>?<argument\ expression>:<argument\ expression>$. *Nonstrict* means that only *some* arguments of the *operator* are evaluated. All *operators* (like $+, -, *, /,...$) presented before were of the *strict* kind.
"
# ╔═╡ 0ed8205c-0845-4d51-a721-21b6a9131928
md"
---
##### 1. Topics
- *case-based* reasoning and problem-solving
- *conditional ternary* expression: <predicate> ? <expression> : <expression>
- *conditional* expressions: $if...elseif...else...end$
- *function* $abs$
- *predicates*: <expr1> < <expr2>, <expr1> > <expr2>, .<=., .=>., .==.
- *nonstrict* and *strict* expression evaluation
- building constructs $and, or, no$ of a *domain specific language (DSL)*
- *one-line* definition of *n-ary, nonstrict* predicate: $and(preds...) = all(preds)$
- *one-line* definition of *n-ary, nonstrict* predicate: $or(preds...) = any(preds)$
- *slurping* parameter and *evaluation* of slurped arguments
- *chaining* of comparisons
- *simple* and *compound* comparisons
- *binding*, *re*binding
- *local scope* with $let <binding>...<expression>...end$
- *nested* $if$s and ternary conditionals
"
# ╔═╡ 65d74436-be9a-49b7-b5c9-21cb7b7cdae9
md"
---
##### 2. Libraries
"
# ╔═╡ 33f31484-b07f-4550-a829-37f1d4f7feba
md"
##### 3. SICP-Scheme-like *functional* Julia: Conditional Expressions
###### 3.1 The *ternary* conditional expression $<predicate> ? <expression> : <expression>$
"
# ╔═╡ 8287786a-0c31-4d58-83fe-ff4d75513ebe
md"
A very simple example for *case-based* problem solving and code is the $abs$-function. The mathematical definition is:
$|x| = \cases{\;\;\; x \;\text{ if } x \gt 0 \cr \;\;\; 0 \;\text{ if } x = 0 \cr -x \;\text{ if } x < 0}$
$\;$
$\;$
$\;$
The *generic* Julia-function $my\_abs$ is a nearly exact implementation of the *mathematical* definition.
$\;$
"
# ╔═╡ 638667fc-0381-47a5-9288-e10b973e10b7
my_abs(x) =
x > 0 ? x : # case 1 : <predicate1> ? <expression1>
x == 0 ? x : # case 2 : <predicate2> ? <expression2>
x < 0 ? -x : # case 3 : <predicate3> ? <expression3>
"unidentified case" # <expression3> := <String>
# ╔═╡ c0df9843-2a0c-4c00-a3ee-78a153bde39f
my_abs( +4.9), my_abs( -4.9) # Float arguments
# ╔═╡ 6732406a-98cf-45ad-aec8-4994483d023d
my_abs( 5), my_abs( -6) # Int(eger) arguments
# ╔═╡ eadc4d5f-786b-4bec-afbf-fc3857df6a5b
my_abs(-0), my_abs(0), my_abs(+0) # Int(eger) arguments
# ╔═╡ 93ac3435-1b97-4a36-8868-69a40e6bfe67
my_abs(-0.0), my_abs(0.0), my_abs(+0.0) # Float arguments
# ╔═╡ 901be490-8e87-4a68-8908-1228ed928017
md"
A one-liner $my\_abs2(x)$
"
# ╔═╡ 06d15eb0-0c31-41a0-8df9-ed7cc8a7c866
my_abs2(x) = x >= 0 ? x : -x
# ╔═╡ f8fc4282-dc86-47f4-a546-dbc91f3ebefb
my_abs2( +4.9), my_abs2( -4.9) # Float arguments
# ╔═╡ bbff83b4-6c20-462d-802f-fc2fac7fb61d
my_abs2(-0), my_abs2(0), my_abs2(+0) # Int(eger) arguments
# ╔═╡ 7c6c3385-9bc0-4a4d-8580-f3755ed00bad
my_abs2(-0.0), my_abs2(0.0), my_abs2(+0.0) # Float arguments
# ╔═╡ 543001ec-12e9-455b-a146-6065fdbbc956
md"
---
###### 3.2 *conditional* expression $if$ with $elseif$
$if <predicate> <expression>$
$elseif <predicate> <expression>$
$else <expression>$
$end \# if$
"
# ╔═╡ 9765aedd-b5cb-4a57-b8bb-0cd3faf73b38
my_abs3(x) =
if x < 0
-x
elseif x == 0
x
else
x
end # if
# ╔═╡ f5c64207-2e90-4b55-bd8e-2e98ee3577e2
my_abs3( +4.9), my_abs3( -4.9) # Float arguments
# ╔═╡ 75886de3-c6ce-4992-a214-fafb6934c72f
my_abs3(-0), my_abs3(0), my_abs3(+0) # Int(eger) arguments
# ╔═╡ 4bf2ca36-c48d-471b-97e7-db2fb67ea155
my_abs3(-0.0), my_abs3(0.0), my_abs3(+0.0) # Float arguments
# ╔═╡ 217cb17e-2920-4732-a6c3-ba893349dc82
md"
---
###### 3.3 *conditional* expression $if$ without $elseif$
$if <predicate> <expression>$
$else <expression>$
$end \# if$
"
# ╔═╡ 50969205-37b7-4d35-8fa9-fa151b11632d
my_abs4(x) =
if x < 0
-x
else
x
end # if
# ╔═╡ e1ef77b1-03a2-478b-8fbd-17556c5e51bd
my_abs4(4.9), my_abs4(-4.9) # Float arguments
# ╔═╡ 49ac622a-3846-4096-ae67-7380363d395d
my_abs4(-0), my_abs4(0), my_abs4(+0) # Int(eger) arguments
# ╔═╡ 72a7154a-699b-483a-a583-f212a8bf6680
my_abs4(-0.0), my_abs4(0.0), my_abs4(+0.0) # Float arguments
# ╔═╡ 7efcf92c-963e-428e-9393-547bd58a7eea
md"
---
###### 3.4 Boolean *prefix* operator $and$ based on Julian built-in *prefix* (*shortcut*) function $all$
Julia has unlike Scheme *no prefix* *n-nary* $and(<predicate>,...)$. So we have to define it on basis of *prefix* operator $all(.)$.
"
# ╔═╡ 2cc97547-8c49-41de-a070-71ad029961fb
md"
###### *One-line* function definition $and(preds...)$ with *slurping* parameter $preds$
$and(preds...) = all(preds)$
$\;$
$\text{ with slurping and spitting parameter}\ preds$
$\;$
"
# ╔═╡ 51f29cdc-23be-4407-8c2b-cc74273cdd31
and(preds...) = all(preds) # slurping preds... and evaluation of preds
# ╔═╡ 6b63f673-c09c-4f34-bf38-c3046dbc1c66
# what is slurping ?
foo(xs...) = xs # slurping 'xs...' and evaluation of xs
# ╔═╡ 4a32fcb0-4c11-4fc0-9f27-442d5a588056
foo(1, 2, 3, 4, 5) # slurping 'xs...' and evaluation of xs
# ╔═╡ cb17e18f-bf9b-4239-81af-fe967c076baa
and()
# ╔═╡ 2fe9e82e-f7db-4ab6-82a9-545887ade481
and(5 < 10)
# ╔═╡ 709bb974-62f9-4380-83d2-bb4683a55bfd
and(5 > 10)
# ╔═╡ 87188de5-649c-47a1-b145-38f2972603b1
and(true, true)
# ╔═╡ 6945bf45-5900-4f33-afb5-68f1fabe56cb
and(true, true, false)
# ╔═╡ 6fed09e8-9b59-404a-be30-004d67ccc45a
and(true, true, true, true, true)
# ╔═╡ 8d912170-ee2a-4b00-8c18-ac5ce7a60796
and(true, Inf < 0)
# ╔═╡ 621d8efc-315f-4338-8a43-1dbb71683fe5
and(true, Inf > 0)
# ╔═╡ 15c98aad-f3c8-4c36-b00c-c534cbd51348
and(5 > 2, 10 < 2)
# ╔═╡ 25fcb287-2079-4851-88d6-9231514990e1
and(5 > 2, 10 > 2) # chaining of comparisons
# ╔═╡ b3a9897f-e87a-4b88-9fac-8f58e56bf6e2
and(1 < 2, 2 < 4, 5 < 10.0) # chaining of comparisons
# ╔═╡ 848fd3c8-d2df-4e9c-985e-8093f2cfced9
md"
---
###### 3.5 Boolean *prefix* operator $or$ based on Julian built-in *prefix* (*shortcut*) function $any$
Julia has unlike Scheme *no prefix* *n-nary* $or(<predicate>,...)$. So we have to define it on basis of *prefix* operator $any(.)$.
"
# ╔═╡ becfda9b-4771-4493-9e40-2dcd6a12f317
md"
###### *One-line* function definition $or(preds...)$ with *slurping* parameter $preds$
$or(preds...) = any(preds)$
$\;$
$\text{ with slurping and spitting parameter}\ preds$
$\;$
"
# ╔═╡ 2bd6bba2-bdf8-48f0-8994-2e931b207835
or(preds...) = any(preds) # slurping preds... and evaluation of preds
# ╔═╡ e544d1e9-7969-4833-9b6b-c95da1dd31f0
or()
# ╔═╡ aa860d9a-187b-4777-ba0d-0cc2f4ae3d65
or(true)
# ╔═╡ 8ccb4cad-5cae-4ee4-9465-fb9a4e77de49
or(false)
# ╔═╡ 42c5e112-db6f-4874-a227-5a06d8054102
or(true, false)
# ╔═╡ 3126ae7b-3971-425e-ab83-cf32ae783f90
or(5 > 2, 10 < 2)
# ╔═╡ 769f6ef3-e6e6-4d20-8e20-86ad08726849
or(5 < 2, 10 < 2)
# ╔═╡ 992cf28b-0d37-41ac-8f72-16901f943351
or(5 < 2, 10 > 2)
# ╔═╡ c6bfa357-861d-4e1c-b4b9-c0f26ddf4bac
or(2 > 4, 5 > 10.0, 1 < 2) # chaining of comparisons
# ╔═╡ 3326de13-109e-4b05-bbde-0b2ff47bdc3c
md"
###### 3.6 Function $not(<boolean\ expression>)$
"
# ╔═╡ 69f36630-a57f-4c63-8e01-f38b0a1649a4
# not(x) = !(x) # redefinition as function defintion
# ╔═╡ 4ce559c3-8662-4679-a68a-6ffb9b528eee
not = ! # function definition by binding
# ╔═╡ a7e1951f-bf97-4966-b93b-104c7b165f67
not(true)
# ╔═╡ d41e6ce1-1192-495a-8bfd-74936101efa3
not(false)
# ╔═╡ 4188358b-3a15-4bae-addc-54da9bfc87b8
md"
###### 3.7 compound predicate $$x \ge y := (x > y) \lor (x = y)$$
"
# ╔═╡ ce79a92e-9bb9-48cd-834c-34eb61c67d18
geEq1(x, y) = or(x > y, x == y)
# ╔═╡ 91eeb0b4-c921-4672-8bee-1d18b2c3c13c
geEq1(5, 3)
# ╔═╡ 234fcd0f-cebc-4adb-8730-3cd2fad15ba0
geEq1(3, 3)
# ╔═╡ 081df546-68eb-4609-8671-e1a6395d9bb9
geEq1(2, 3)
# ╔═╡ e40e61d9-692e-4838-a84d-11c51911e3d4
md"
###### compound predicate $$x \ge y := (x \not \lt y)$$
"
# ╔═╡ 7c2f185f-e363-4a8e-8b52-80fef2622aa7
geEq2(x, y) = not(x < y)
# ╔═╡ a96202d4-6f52-40cc-a421-e81bb98c363b
geEq2(5, 3)
# ╔═╡ 5907313d-43b1-4c67-84dd-ea0f5c1f3da8
geEq2(3, 3)
# ╔═╡ b153aba7-acee-4b0e-84e7-1e8aa6f5eea9
geEq2(3, 5)
# ╔═╡ 9326271a-ce21-4254-ab26-a42f87d18bc5
md"
---
##### 4. *Idiomatic* Julia ...
"
# ╔═╡ 9d45ab98-09be-43a7-971e-c88434ab3571
md"
###### 4.1 *Binary, infix, nonstrict (shortcut)* operator $\&\&$
"
# ╔═╡ 398325d0-5ec5-4aec-bf8e-098cfd83f0bb
5 > 2 && 10 < 2
# ╔═╡ 2a03f956-6b7a-490e-8dc9-62c14823610b
5 > 2 && 10 > 2 # chaining of comparisons
# ╔═╡ bec32b16-af88-49a0-8b55-7098a460eab2
md"
###### 4.2 *Binary, infix, nonstrict (shortcut)* operator $||$
"
# ╔═╡ 6f14607a-a507-4918-bc32-1588867114f5
5 > 2 || 10 < 2
# ╔═╡ 302fc1e2-980d-4170-83a0-d74f2e5bda4b
5 > 2 || 10 > 2
# ╔═╡ a6208b49-76db-4742-89a5-019b020e2770
md"
###### 4.3 $geEq$ based on built-in *prefix* $!$ and *infix* $<$
"
# ╔═╡ adb0c3c3-97b9-45f1-ae42-e05539dbc427
geEq3(x, y) = !(x < y)
# ╔═╡ e668030b-8d70-4bd2-887c-1bafb6fe5928
geEq3(5, 3)
# ╔═╡ 5decbbfe-402e-472a-9e22-402f7178d3d0
geEq3(3, 3)
# ╔═╡ 6f5a6658-4128-4829-be58-4831b1496d0b
geEq3(3, 5)
# ╔═╡ b3c6269f-e400-454c-8078-a5bd063d9031
md"
###### 4.4 $geEq$ based on built-in *prefix* $\text{!<}$
"
# ╔═╡ 18c20c8c-842a-4f03-b3a7-0d5442ae905e
geEq4(x, y) = !<(x, y)
# ╔═╡ d91629d0-79e1-4ddd-9a28-3bc1a9948ff5
geEq4(5, 3)
# ╔═╡ c77e9bd1-5964-411f-831c-9b76b05ff640
geEq4(3, 3)
# ╔═╡ 93fb8d81-c942-420d-ab91-8371a4af3062
geEq4(3, 5)
# ╔═╡ 6dc41f11-c3da-46e9-803f-36ae73ea4c9d
md"
###### 4.5 $geEq$ based on built-in *infix* $\text{||}, >, ==$
"
# ╔═╡ fad8b34d-30e1-4ff8-a180-59efde3925fa
geEq5(x, y) = x > y || x == y
# ╔═╡ ad41d505-3803-420f-a077-5f147e32b83e
geEq5(3, 5)
# ╔═╡ 2a1fbc65-f991-46e3-8057-35f8085fc394
geEq5(5, 5)
# ╔═╡ d2a400fa-a179-4ae5-94af-8e1af14ae116
geEq5(7, 5)
# ╔═╡ ce089a85-b554-4626-90d6-7804c56672c6
md"
###### 4.6 *infix* operator $\&\&$ and *chaining* comparisons with $<, >$
$(5 < 2) \land (2 < 10) == 5 < 2 < 10$
"
# ╔═╡ 96004b6e-d0f7-4afa-8ee2-f61aa84af474
(2 < 5) && (5 < 10)
# ╔═╡ b00ca9fe-70fa-4d24-808f-581965d76df6
2 < 5 < 10
# ╔═╡ cedbf13f-be78-43d7-879a-63971f02c8f5
((2 < 5) && (5 < 10) ) == (2 < 5 < 10) # '=='
# ╔═╡ f6ee94f3-a049-44a1-91ba-bb6daf3d0140
((2 < 5) && (5 < 10) ) === (2 < 5 < 10) # '==='
# ╔═╡ be1bb1e0-52f5-4158-9625-aa9f900b3d02
5 < 6 < 10
# ╔═╡ c1d0f438-b1d0-44d3-8836-858fcb229935
md"
---
##### 5. Example: Truth of Implication
This is an exercise how to *nest* conditional expressions.
$\forall x>0, y>0: (x^2 \lt y^2) \Longrightarrow (x \lt y)$
$\;$
"
# ╔═╡ b43b42e0-ee4d-41f2-b975-6b8bc2ce961e
md"
---
###### 5.1 Case 1 (both $x,y$ positive and $x < y$) : $x = 2, y = 3$
"
# ╔═╡ 91d1967b-5fc1-42db-83f2-65858a04f748
let x = 2; y = 3 # local bindings
#----------------------------------------
if x^2 < y^2 # predicate1
#-----------------------------------
if x < y # predicate2
true # expression1
else
false # expression2
end # if
#-----------------------------------
else
if x > y # predicate3
true # expression4
else
false # expression5
end # if
end # if
#----------------------------------------
end # let
# ╔═╡ 75954cb0-5008-4d7f-9922-6c3fdc508d02
md"
---
###### 5.2 Case 2 (both $x,y$ positive and $x > y$) : $x = 3, y = 2$
"
# ╔═╡ f96d984e-8e5b-4728-9151-abf2b922bba4
let x = 3; y = 2 # local bindings
#----------------------------------------
if x^2 < y^2 # predicate1
#-----------------------------------
if x < y # predicate2
true # expression1
else
false # expression2
end # if
#-----------------------------------
else
if x < y # predicate3
false # expression4
else
true # expression5
end # if
end # if
#----------------------------------------
end # let
# ╔═╡ d49df15c-7e6c-499b-83ce-4c73e0fed250
md"
---
###### 5.3 Case 3 (both $x,y$ positive and $x < y$) : $x = 2, y = 3$
"
# ╔═╡ f6bb9860-73c8-4d45-9eb9-76bbf9e4674e
let x = 2; y = 3
#------------------------------------------
x^2 < y^2 ? (x < y ? true : false) :
(x < y ? false : true)
#------------------------------------------
end # let
# ╔═╡ 3809159f-6ba5-491e-ad5f-acbbd0353a03
md"
---
###### 5.4 Case 4 (both $x,y$ positive and $x > y$) : $x = 3, y = 2$
"
# ╔═╡ dbc6f577-b2d1-4396-af18-e5066af805d1
let x = 3; y = 2
#------------------------------------------
x^2 < y^2 ? (x < y ? true : false) :
(x < y ? false : true)
#------------------------------------------
end # let
# ╔═╡ dca8d843-b36f-44f9-8b3c-71271c716c60
md"
---
##### 6. Summary
We demonstrated how to define a small *domain specific language* (*DSL*) consisting of *conditional predicates* $and, or, not$. The behavior of these predicates was defined by using Julia's *built-in*s $all, any, \&\&, ||, !, <, >, <=, >=, ==$. It was possible to define *n-ary* predicates $and, or$ by *slurping* parameters.
$\;$
"
# ╔═╡ 9a5d6d10-27d7-4cac-a950-6e5668955067
md"
---
##### 7. References
- **Abelson, H., Sussman, G.J. & Sussman, J.**, Structure and Interpretation of Computer Programs, Cambridge, Mass.: MIT Press, (2/e), 1996, [https://sarabander.github.io/sicp/](https://sarabander.github.io/sicp/), last visit 2022/08/23
- **Arens, T., Hettlich, F., Karpfinger, Chr., Kockelkorn, U., Lichtenegger, K., & Stachel, H.,** Mathematik, 4/e, Heidelberg, Springer Spektrum, [https://doi.org/10.1007/978-3-662-56741-8](https://doi.org/10.1007/978-3-662-56741-8)
"
# ╔═╡ e89faf5f-04a8-44c3-a941-381d41782d40
md"
---
##### end of ch. 1.1.6
===================================================================================
This is a **draft** under the [Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)](https://creativecommons.org/licenses/by-nc-sa/4.0/) license. Comments, suggestions for improvement and bug reports are welcome: **claus.moebus(@)uol.de**
===================================================================================
"
# ╔═╡ 00000000-0000-0000-0000-000000000001
PLUTO_PROJECT_TOML_CONTENTS = """
[deps]
GraphRecipes = "bd48cda9-67a9-57be-86fa-5b3c104eda73"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Pluto = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
[compat]
GraphRecipes = "~0.5.13"
Plots = "~1.40.8"
Pluto = "~0.20.3"
"""
# ╔═╡ 00000000-0000-0000-0000-000000000002
PLUTO_MANIFEST_TOML_CONTENTS = """
# This file is machine-generated - editing it directly is not advised
julia_version = "1.11.2"
manifest_format = "2.0"
project_hash = "bb715c7a4c4df1b360252d689155579af0186e87"
[[deps.AbstractTrees]]
git-tree-sha1 = "2d9c9a55f9c93e8887ad391fbae72f8ef55e1177"
uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
version = "0.4.5"
[[deps.Adapt]]
deps = ["LinearAlgebra", "Requires"]
git-tree-sha1 = "50c3c56a52972d78e8be9fd135bfb91c9574c140"
uuid = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
version = "4.1.1"
weakdeps = ["StaticArrays"]
[deps.Adapt.extensions]
AdaptStaticArraysExt = "StaticArrays"
[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.2"
[[deps.ArnoldiMethod]]
deps = ["LinearAlgebra", "Random", "StaticArrays"]
git-tree-sha1 = "d57bd3762d308bded22c3b82d033bff85f6195c6"
uuid = "ec485272-7323-5ecc-a04f-4719b315124d"
version = "0.4.0"
[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
version = "1.11.0"
[[deps.AxisAlgorithms]]
deps = ["LinearAlgebra", "Random", "SparseArrays", "WoodburyMatrices"]
git-tree-sha1 = "01b8ccb13d68535d73d2b0c23e39bd23155fb712"
uuid = "13072b0f-2c55-5437-9ae7-d433b7a33950"
version = "1.1.0"
[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
version = "1.11.0"
[[deps.BitFlags]]
git-tree-sha1 = "0691e34b3bb8be9307330f88d1a3c3f25466c24d"
uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.9"
[[deps.Bzip2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "8873e196c2eb87962a2048b3b8e08946535864a1"
uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0"
version = "1.0.8+2"
[[deps.Cairo_jll]]
deps = ["Artifacts", "Bzip2_jll", "CompilerSupportLibraries_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "JLLWrappers", "LZO_jll", "Libdl", "Pixman_jll", "Xorg_libXext_jll", "Xorg_libXrender_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "009060c9a6168704143100f36ab08f06c2af4642"
uuid = "83423d85-b0ee-5818-9007-b63ccbeb887a"
version = "1.18.2+1"
[[deps.ChainRulesCore]]
deps = ["Compat", "LinearAlgebra"]
git-tree-sha1 = "3e4b134270b372f2ed4d4d0e936aabaefc1802bc"
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
version = "1.25.0"
weakdeps = ["SparseArrays"]
[deps.ChainRulesCore.extensions]
ChainRulesCoreSparseArraysExt = "SparseArrays"
[[deps.CodecZlib]]
deps = ["TranscodingStreams", "Zlib_jll"]
git-tree-sha1 = "bce6804e5e6044c6daab27bb533d1295e4a2e759"
uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
version = "0.7.6"
[[deps.ColorSchemes]]
deps = ["ColorTypes", "ColorVectorSpace", "Colors", "FixedPointNumbers", "PrecompileTools", "Random"]
git-tree-sha1 = "c785dfb1b3bfddd1da557e861b919819b82bbe5b"
uuid = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
version = "3.27.1"
[[deps.ColorTypes]]
deps = ["FixedPointNumbers", "Random"]
git-tree-sha1 = "b10d0b65641d57b8b4d5e234446582de5047050d"
uuid = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
version = "0.11.5"
[[deps.ColorVectorSpace]]
deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "Requires", "Statistics", "TensorCore"]
git-tree-sha1 = "a1f44953f2382ebb937d60dafbe2deea4bd23249"
uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4"
version = "0.10.0"
[deps.ColorVectorSpace.extensions]
SpecialFunctionsExt = "SpecialFunctions"
[deps.ColorVectorSpace.weakdeps]
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
[[deps.Colors]]
deps = ["ColorTypes", "FixedPointNumbers", "Reexport"]
git-tree-sha1 = "64e15186f0aa277e174aa81798f7eb8598e0157e"
uuid = "5ae59095-9a9b-59fe-a467-6f913c188581"
version = "0.13.0"
[[deps.Compat]]
deps = ["TOML", "UUIDs"]
git-tree-sha1 = "8ae8d32e09f0dcf42a36b90d4e17f5dd2e4c4215"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "4.16.0"
weakdeps = ["Dates", "LinearAlgebra"]
[deps.Compat.extensions]
CompatLinearAlgebraExt = "LinearAlgebra"
[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "1.1.1+0"
[[deps.ConcurrentUtilities]]
deps = ["Serialization", "Sockets"]
git-tree-sha1 = "ea32b83ca4fefa1768dc84e504cc0a94fb1ab8d1"
uuid = "f0e56b4a-5159-44fe-b623-3e5288b988bb"
version = "2.4.2"
[[deps.Configurations]]
deps = ["ExproniconLite", "OrderedCollections", "TOML"]
git-tree-sha1 = "4358750bb58a3caefd5f37a4a0c5bfdbbf075252"
uuid = "5218b696-f38b-4ac9-8b61-a12ec717816d"
version = "0.17.6"
[[deps.ConstructionBase]]
git-tree-sha1 = "76219f1ed5771adbb096743bff43fb5fdd4c1157"
uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
version = "1.5.8"
[deps.ConstructionBase.extensions]
ConstructionBaseIntervalSetsExt = "IntervalSets"
ConstructionBaseLinearAlgebraExt = "LinearAlgebra"
ConstructionBaseStaticArraysExt = "StaticArrays"
[deps.ConstructionBase.weakdeps]
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
[[deps.Contour]]
git-tree-sha1 = "439e35b0b36e2e5881738abc8857bd92ad6ff9a8"
uuid = "d38c429a-6771-53c6-b99e-75d170b6e991"
version = "0.6.3"
[[deps.DataAPI]]
git-tree-sha1 = "abe83f3a2f1b857aac70ef8b269080af17764bbe"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.16.0"
[[deps.DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "1d0a14036acb104d9e89698bd408f63ab58cdc82"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.20"
[[deps.DataValueInterfaces]]
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
version = "1.0.0"
[[deps.Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
version = "1.11.0"
[[deps.Dbus_jll]]
deps = ["Artifacts", "Expat_jll", "JLLWrappers", "Libdl"]
git-tree-sha1 = "fc173b380865f70627d7dd1190dc2fce6cc105af"
uuid = "ee1fde0b-3d02-5ea6-8484-8dfef6360eab"
version = "1.14.10+0"
[[deps.DelimitedFiles]]
deps = ["Mmap"]
git-tree-sha1 = "9e2f36d3c96a820c678f2f1f1782582fcf685bae"
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
version = "1.9.1"
[[deps.Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
version = "1.11.0"
[[deps.DocStringExtensions]]
deps = ["LibGit2"]
git-tree-sha1 = "2fb1e02f2b635d0845df5d7c167fec4dd739b00d"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.9.3"
[[deps.Downloads]]
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
version = "1.6.0"
[[deps.EarCut_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "e3290f2d49e661fbd94046d7e3726ffcb2d41053"
uuid = "5ae413db-bbd1-5e63-b57d-d24a61df00f5"
version = "2.2.4+0"
[[deps.EpollShim_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "8a4be429317c42cfae6a7fc03c31bad1970c310d"
uuid = "2702e6a9-849d-5ed8-8c21-79e8b8f9ee43"
version = "0.0.20230411+1"
[[deps.ExceptionUnwrapping]]
deps = ["Test"]
git-tree-sha1 = "d36f682e590a83d63d1c7dbd287573764682d12a"
uuid = "460bff9d-24e4-43bc-9d9f-a8973cb893f4"
version = "0.1.11"
[[deps.Expat_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "e51db81749b0777b2147fbe7b783ee79045b8e99"
uuid = "2e619515-83b5-522b-bb60-26c02a35a201"
version = "2.6.4+1"
[[deps.ExpressionExplorer]]
git-tree-sha1 = "7005f1493c18afb2fa3bdf06e02b16a9fde5d16d"
uuid = "21656369-7473-754a-2065-74616d696c43"
version = "1.1.0"
[[deps.ExproniconLite]]
git-tree-sha1 = "4c9ed87a6b3cd90acf24c556f2119533435ded38"
uuid = "55351af7-c7e9-48d6-89ff-24e801d99491"
version = "0.10.13"
[[deps.Extents]]
git-tree-sha1 = "81023caa0021a41712685887db1fc03db26f41f5"
uuid = "411431e0-e8b7-467b-b5e0-f676ba4f2910"
version = "0.1.4"
[[deps.FFMPEG]]
deps = ["FFMPEG_jll"]
git-tree-sha1 = "53ebe7511fa11d33bec688a9178fac4e49eeee00"
uuid = "c87230d0-a227-11e9-1b43-d7ebe4e7570a"
version = "0.4.2"
[[deps.FFMPEG_jll]]
deps = ["Artifacts", "Bzip2_jll", "FreeType2_jll", "FriBidi_jll", "JLLWrappers", "LAME_jll", "Libdl", "Ogg_jll", "OpenSSL_jll", "Opus_jll", "PCRE2_jll", "Zlib_jll", "libaom_jll", "libass_jll", "libfdk_aac_jll", "libvorbis_jll", "x264_jll", "x265_jll"]
git-tree-sha1 = "466d45dc38e15794ec7d5d63ec03d776a9aff36e"
uuid = "b22a6f82-2f65-5046-a5b2-351ab43fb4e5"
version = "4.4.4+1"
[[deps.FileWatching]]
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
version = "1.11.0"
[[deps.FixedPointNumbers]]
deps = ["Statistics"]
git-tree-sha1 = "05882d6995ae5c12bb5f36dd2ed3f61c98cbb172"
uuid = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
version = "0.8.5"
[[deps.Fontconfig_jll]]
deps = ["Artifacts", "Bzip2_jll", "Expat_jll", "FreeType2_jll", "JLLWrappers", "Libdl", "Libuuid_jll", "Zlib_jll"]
git-tree-sha1 = "db16beca600632c95fc8aca29890d83788dd8b23"
uuid = "a3f928ae-7b40-5064-980b-68af3947d34b"
version = "2.13.96+0"
[[deps.Format]]
git-tree-sha1 = "9c68794ef81b08086aeb32eeaf33531668d5f5fc"
uuid = "1fa38f19-a742-5d3f-a2b9-30dd87b9d5f8"
version = "1.3.7"
[[deps.FreeType2_jll]]
deps = ["Artifacts", "Bzip2_jll", "JLLWrappers", "Libdl", "Zlib_jll"]
git-tree-sha1 = "786e968a8d2fb167f2e4880baba62e0e26bd8e4e"
uuid = "d7e528f0-a631-5988-bf34-fe36492bcfd7"
version = "2.13.3+1"
[[deps.FriBidi_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "1ed150b39aebcc805c26b93a8d0122c940f64ce2"
uuid = "559328eb-81f9-559d-9380-de523a88c83c"
version = "1.0.14+0"
[[deps.FuzzyCompletions]]
deps = ["REPL"]
git-tree-sha1 = "be713866335f48cfb1285bff2d0cbb8304c1701c"
uuid = "fb4132e2-a121-4a70-b8a1-d5b831dcdcc2"
version = "0.5.5"
[[deps.GLFW_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libglvnd_jll", "Xorg_libXcursor_jll", "Xorg_libXi_jll", "Xorg_libXinerama_jll", "Xorg_libXrandr_jll", "libdecor_jll", "xkbcommon_jll"]
git-tree-sha1 = "532f9126ad901533af1d4f5c198867227a7bb077"
uuid = "0656b61e-2033-5cc2-a64a-77c0f6c09b89"
version = "3.4.0+1"
[[deps.GR]]
deps = ["Artifacts", "Base64", "DelimitedFiles", "Downloads", "GR_jll", "HTTP", "JSON", "Libdl", "LinearAlgebra", "Preferences", "Printf", "Qt6Wayland_jll", "Random", "Serialization", "Sockets", "TOML", "Tar", "Test", "p7zip_jll"]
git-tree-sha1 = "ee28ddcd5517d54e417182fec3886e7412d3926f"
uuid = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
version = "0.73.8"
[[deps.GR_jll]]
deps = ["Artifacts", "Bzip2_jll", "Cairo_jll", "FFMPEG_jll", "Fontconfig_jll", "FreeType2_jll", "GLFW_jll", "JLLWrappers", "JpegTurbo_jll", "Libdl", "Libtiff_jll", "Pixman_jll", "Qt6Base_jll", "Zlib_jll", "libpng_jll"]
git-tree-sha1 = "f31929b9e67066bee48eec8b03c0df47d31a74b3"
uuid = "d2c73de3-f751-5644-a686-071e5b155ba9"
version = "0.73.8+0"
[[deps.GeoFormatTypes]]
git-tree-sha1 = "59107c179a586f0fe667024c5eb7033e81333271"
uuid = "68eda718-8dee-11e9-39e7-89f7f65f511f"
version = "0.4.2"
[[deps.GeoInterface]]
deps = ["Extents", "GeoFormatTypes"]
git-tree-sha1 = "826b4fd69438d9ce4d2b19de6bc2f970f45f0f88"
uuid = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
version = "1.3.8"
[[deps.GeometryBasics]]
deps = ["EarCut_jll", "Extents", "GeoInterface", "IterTools", "LinearAlgebra", "StaticArrays", "StructArrays", "Tables"]
git-tree-sha1 = "b62f2b2d76cee0d61a2ef2b3118cd2a3215d3134"
uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
version = "0.4.11"
[[deps.GeometryTypes]]
deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "StaticArrays"]
git-tree-sha1 = "d796f7be0383b5416cd403420ce0af083b0f9b28"
uuid = "4d00f742-c7ba-57c2-abde-4428a4b178cb"
version = "0.8.5"
[[deps.Gettext_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "9b02998aba7bf074d14de89f9d37ca24a1a0b046"
uuid = "78b55507-aeef-58d4-861c-77aaff3498b1"
version = "0.21.0+0"
[[deps.Glib_jll]]
deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE2_jll", "Zlib_jll"]
git-tree-sha1 = "48b5d4c75b2c9078ead62e345966fa51a25c05ad"
uuid = "7746bdde-850d-59dc-9ae8-88ece973131d"
version = "2.82.2+1"
[[deps.GraphRecipes]]
deps = ["AbstractTrees", "GeometryTypes", "Graphs", "InteractiveUtils", "Interpolations", "LinearAlgebra", "NaNMath", "NetworkLayout", "PlotUtils", "RecipesBase", "SparseArrays", "Statistics"]
git-tree-sha1 = "10920601dc51d2231bb3d2111122045efed8def0"
uuid = "bd48cda9-67a9-57be-86fa-5b3c104eda73"
version = "0.5.13"
[[deps.Graphite2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"]
git-tree-sha1 = "01979f9b37367603e2848ea225918a3b3861b606"
uuid = "3b182d85-2403-5c21-9c21-1e1f0cc25472"
version = "1.3.14+1"
[[deps.Graphs]]
deps = ["ArnoldiMethod", "Compat", "DataStructures", "Distributed", "Inflate", "LinearAlgebra", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics"]
git-tree-sha1 = "1dc470db8b1131cfc7fb4c115de89fe391b9e780"
uuid = "86223c79-3864-5bf0-83f7-82e725a168b6"
version = "1.12.0"
[[deps.Grisu]]
git-tree-sha1 = "53bb909d1151e57e2484c3d1b53e19552b887fb2"
uuid = "42e2da0e-8278-4e71-bc24-59509adca0fe"
version = "1.0.2"
[[deps.HTTP]]
deps = ["Base64", "CodecZlib", "ConcurrentUtilities", "Dates", "ExceptionUnwrapping", "Logging", "LoggingExtras", "MbedTLS", "NetworkOptions", "OpenSSL", "PrecompileTools", "Random", "SimpleBufferStream", "Sockets", "URIs", "UUIDs"]
git-tree-sha1 = "6c22309e9a356ac1ebc5c8a217045f9bae6f8d9a"
uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3"
version = "1.10.13"
[[deps.HarfBuzz_jll]]
deps = ["Artifacts", "Cairo_jll", "Fontconfig_jll", "FreeType2_jll", "Glib_jll", "Graphite2_jll", "JLLWrappers", "Libdl", "Libffi_jll"]
git-tree-sha1 = "401e4f3f30f43af2c8478fc008da50096ea5240f"
uuid = "2e76f6c2-a576-52d4-95c1-20adfe4de566"
version = "8.3.1+0"
[[deps.HypertextLiteral]]
deps = ["Tricks"]
git-tree-sha1 = "7134810b1afce04bbc1045ca1985fbe81ce17653"
uuid = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2"
version = "0.9.5"
[[deps.Inflate]]
git-tree-sha1 = "d1b1b796e47d94588b3757fe84fbf65a5ec4a80d"
uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9"
version = "0.1.5"
[[deps.InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
version = "1.11.0"
[[deps.Interpolations]]
deps = ["Adapt", "AxisAlgorithms", "ChainRulesCore", "LinearAlgebra", "OffsetArrays", "Random", "Ratios", "Requires", "SharedArrays", "SparseArrays", "StaticArrays", "WoodburyMatrices"]
git-tree-sha1 = "88a101217d7cb38a7b481ccd50d21876e1d1b0e0"
uuid = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
version = "0.15.1"
weakdeps = ["Unitful"]
[deps.Interpolations.extensions]
InterpolationsUnitfulExt = "Unitful"
[[deps.IrrationalConstants]]
git-tree-sha1 = "630b497eafcc20001bba38a4651b327dcfc491d2"
uuid = "92d709cd-6900-40b7-9082-c6be49f344b6"
version = "0.2.2"