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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
:: Abstract Reduction Systems and Idea of {K}nuth {B}endix Completion
:: Algorithm
:: http://creativecommons.org/licenses/by-sa/3.0/.

environ

 vocabularies RELAT_1, XBOOLE_0, FUNCT_1, REWRITE1, TDGROUP, ABSRED_0,
      ZFMISC_1, FINSEQ_1, ARYTM_1, SUBSET_1, NUMBERS, STRUCT_0, NAT_1, ARYTM_3,
      CARD_1, XXREAL_0, ZFREFLE1, TARSKI, UNIALG_1, GROUP_1, MSUALG_6, FUNCT_2,
      INCPROJ, EQREL_1, MSUALG_1, PARTFUN1, UNIALG_2, FUNCT_4, PBOOLE, FUNCT_7,
      FINSEQ_2, FUNCOP_1, ORDINAL1, MESFUNC1;
 notations TARSKI, XBOOLE_0, ZFMISC_1, ENUMSET1, NUMBERS, XCMPLX_0, XXREAL_0,
      RELAT_1, RELSET_1, FUNCT_1, SUBSET_1, PARTFUN1, FUNCT_2, FUNCOP_1,
      EQREL_1, ORDINAL1, BINOP_1, FINSEQ_1, FINSEQ_2, NAT_1, FINSEQ_4, FUNCT_7,
      MARGREL1, STRUCT_0, PBOOLE, UNIALG_1, PUA2MSS1, REWRITE1;
 constructors RELAT_1, RELSET_1, FUNCT_2, STRUCT_0, REWRITE1, XCMPLX_0,
      XXREAL_0, NAT_1, FINSEQ_5, ENUMSET1, BINOP_1, FINSEQ_1, FINSEQ_4,
      FUNCT_7, CARD_1, XXREAL_1, UNIALG_1, PUA2MSS1, REALSET1, MARGREL1,
      EQREL_1, NUMBERS, XBOOLE_0, ZFMISC_1, SUBSET_1, FUNCT_1, PARTFUN1;
 registrations SUBSET_1, XBOOLE_0, RELSET_1, ORDINAL1, NAT_1, REWRITE1,
      XXREAL_0, XCMPLX_0, STRUCT_0, AOFA_A00, FUNCT_2, FINSEQ_1, PARTFUN1,
      FUNCOP_1, FINSEQ_2, CARD_1, MARGREL1, UNIALG_1, PUA2MSS1, RELAT_1;
 requirements BOOLE, SUBSET, NUMERALS, ARITHM, REAL;
 definitions MARGREL1, STRUCT_0, UNIALG_1, REWRITE1;
 equalities EQREL_1;
 theorems ZFMISC_1, NAT_1, FINSEQ_3, FINSEQ_5, REWRITE1, IDEA_1, XBOOLE_0,
      RELAT_1, FUNCT_1, FUNCT_2, TARSKI, SUBSET_1, ENUMSET1, SETWISEO,
      ORDINAL1, SEQ_4, MARGREL1, RELSET_1, FINSEQ_1, PARTFUN1, FINSEQ_2,
      GRFUNC_1, FUNCOP_1, FUNCT_7, PUA2MSS1, COMPUT_1;
 schemes NAT_1, RECDEF_1, RELSET_1;

begin :: Reduction and Convertibility

definition
  struct(1-sorted) ARS(#
    carrier -> set,
    reduction -> Relation of the carrier
  #);
end;

registration
  let A be non empty set, r be Relation of A;
  cluster ARS(#A, r#) -> non empty;
  coherence;
end;

registration
  cluster non empty strict for ARS;
  existence
  proof
    set A = the non empty set, r = the Relation of A;
    take X = ARS(#A,r#);
    thus X is non empty;
    thus X is strict;
  end;
end;

definition
  let X be ARS;
  let x,y be Element of X;
  pred x ==> y means [x,y] in the reduction of X;
end;

notation
  let X be ARS;
  let x,y be Element of X;
  synonym y <== x for x ==> y;
end;

definition
  let X be ARS;
  let x,y be Element of X;
  pred x =01=> y means x = y or x ==> y;
  reflexivity;
  pred x =*=> y means the reduction of X reduces x,y;
  reflexivity by REWRITE1:12;
end;

reserve X for ARS, a,b,c,u,v,w,x,y,z for Element of X;

theorem
  a ==> b implies X is non empty;

theorem Th2:
  x ==> y implies x =*=> y by REWRITE1:15;

theorem Th3:
  x =*=> y & y =*=> z implies x =*=> z by REWRITE1:16;

scheme Star{X() -> ARS, P[object]}:
  for x,y being Element of X() st x =*=> y & P[x]
  holds P[y]
provided
A1: for x,y being Element of X() st x ==> y & P[x] holds P[y]
  proof
    let x,y be Element of X();
    given p being RedSequence of the reduction of X() such that
A2: p.1 = x & p.len p = y;
    assume
A0: P[x];
    defpred Q[Nat] means $1+1 in dom p implies P[p.($1+1)];
A3: Q[0] by A0,A2;
A4: for i being Nat st Q[i] holds Q[i+1]
    proof
      let i be Nat; reconsider j = i as Element of NAT by ORDINAL1:def 12;
      assume
B1:   Q[i] & i+1+1 in dom p; then
      i+1+1 <= len p & i+1 >= 1 by NAT_1:11,FINSEQ_3:25; then
B2:   j+1 in dom p by SEQ_4:134; then
      [p.(i+1), p.(i+1+1)] in the reduction of X() by B1,REWRITE1:def 2; then
      reconsider a = p.(i+1), b = p.(i+1+1) as Element of X() by ZFMISC_1:87;
      P[a] & a ==> b by B1,B2,REWRITE1:def 2;
      hence P[p.(i+1+1)] by A1;
    end;
A5: for i being Nat holds Q[i] from NAT_1:sch 2(A3,A4);
    len p >= 0+1 by NAT_1:13; then
    (ex i being Nat st len p = 1+i) &
    len p in dom p by NAT_1:10,FINSEQ_5:6;
    hence thesis by A2,A5;
end;

scheme Star1{X() -> ARS, P[object], a, b() -> Element of X()}:
  P[b()]
provided
A1: a() =*=> b() and
A2: P[a()] and
A3: for x,y being Element of X() st x ==> y & P[x] holds P[y]
  proof
    for x,y being Element of X() st x =*=> y & P[x] holds P[y] from Star(A3);
    hence thesis by A1,A2;
  end;

scheme StarBack{X() -> ARS, P[object]}:
  for x,y being Element of X() st x =*=> y & P[y]
  holds P[x]
provided
A1: for x,y being Element of X() st x ==> y & P[y] holds P[x]
  proof
    let x,y be Element of X();
    given p being RedSequence of the reduction of X() such that
A2: p.1 = x & p.len p = y;
    assume
A0: P[y];
    defpred Q[Nat] means (len p)-$1 in dom p implies P[p.((len p)-$1)];
A3: Q[0] by A0,A2;
A4: for i being Nat st Q[i] holds Q[i+1]
    proof
      let i be Nat; assume
B1:   Q[i] & (len p)-(i+1) in dom p; then
      reconsider k = (len p)-(i+1) as Element of NAT;
B4:   k >= 0+1 by B1,FINSEQ_3:25;
      i is Element of NAT &
      k+1 = (len p)-i by ORDINAL1:def 12; then
      k+1 <= len p by IDEA_1:3; then
B2:   k in dom p & k+1 in dom p by B4,SEQ_4:134; then
      [p.k, p.(k+1)] in the reduction of X() by REWRITE1:def 2; then
      reconsider a = p.k, b = p.(k+1) as Element of X() by ZFMISC_1:87;
      P[b] & a ==> b by B1,B2,REWRITE1:def 2;
      hence thesis by A1;
    end;
A5: for i being Nat holds Q[i] from NAT_1:sch 2(A3,A4);
    len p >= 0+1 by NAT_1:13; then
    len p-1 is Nat & (len p)-((len p)-1) = 1 & 1 in dom p
    by NAT_1:21,FINSEQ_5:6;
    hence thesis by A2,A5;
end;

scheme StarBack1{X() -> ARS, P[object], a, b() -> Element of X()}:
  P[a()]
provided
A1: a() =*=> b() and
A2: P[b()] and
A3: for x,y being Element of X() st x ==> y & P[y] holds P[x]
  proof
    for x,y being Element of X() st x =*=> y & P[y] holds P[x]
    from StarBack(A3);
    hence thesis by A1,A2;
  end;

definition
  let X be ARS;
  let x,y be Element of X;
  pred x =+=> y means ex z being Element of X st x ==> z & z =*=> y;
end;

theorem Th4:
  x =+=> y iff ex z st x =*=> z & z ==> y
  proof
    thus x =+=> y implies ex z st x =*=> z & z ==> y
    proof given z such that
A1:   x ==> z & z =*=> y;
      defpred P[Element of X] means ex u st x =*=> u & u ==> $1;
A2:   for y,z st y ==> z & P[y] holds P[z]
      proof
        let y,z; assume
A3:     y ==> z;
        given u such that
A4:     x =*=> u & u ==> y;
        take y;
        u =*=> y by A4,Th2;
        hence thesis by A3,A4,Th3;
      end;
A5:   for y,z st y =*=> z & P[y] holds P[z] from Star(A2);
      thus thesis by A1,A5;
    end;
    given z such that
A6: x =*=> z & z ==> y;
    defpred P[Element of X] means ex u st $1 ==> u & u =*=> y;
A2: for y,z st y ==> z & P[z] holds P[y]
    proof
      let x,z; assume
A3:   x ==> z;
      given u such that
A4:   z ==> u & u =*=> y;
      take z;
      z =*=> u by A4,Th2;
      hence thesis by A3,A4,Th3;
    end;
A5: for y,z st y =*=> z & P[z] holds P[y] from StarBack(A2);
    thus ex z st x ==> z & z =*=> y by A5,A6;
  end;

notation
  let X,x,y;
  synonym y <=01= x for x =01=> y;
  synonym y <=*= x for x =*=> y;
  synonym y <=+= x for x =+=> y;
end;

::  x ==> y implies x =+=> y;
::  x =+=> y implies x =*=> y;
::  x =+=> y & y =*=> z implies x =+=> z;
::  x =*=> y & y =+=> z implies x =+=> z;

definition
  let X,x,y;
  pred x <==> y means x ==> y or x <== y;
  symmetry;
end;

theorem
  x <==> y iff [x,y] in (the reduction of X)\/(the reduction of X)~
  proof
A1: x ==> y iff [x,y] in the reduction of X;
A2: x <== y iff [y,x] in the reduction of X;
    [y,x] in the reduction of X iff [x,y] in (the reduction of X)~
    by RELAT_1:def 7;
    hence thesis by A1,A2,XBOOLE_0:def 3;
  end;

definition
  let X,x,y;
  pred x <=01=> y means x = y or x <==> y;
  reflexivity;
  symmetry;
  pred x <=*=> y means x,y are_convertible_wrt the reduction of X;
  reflexivity by REWRITE1:26;
  symmetry by REWRITE1:31;
end;

theorem Th6:
  x <==> y implies x <=*=> y
  proof
    assume x ==> y or x <== y;
    hence x,y are_convertible_wrt the reduction of X by REWRITE1:29,31;
  end;

theorem Th7:
  x <=*=> y & y <=*=> z implies x <=*=> z by REWRITE1:30;

scheme Star2{X() -> ARS, P[object]}:
  for x,y being Element of X() st x <=*=> y & P[x]
  holds P[y]
provided
A1:  for x,y being Element of X() st x <==> y & P[x]
  holds P[y]
proof
    let x,y be Element of X();
    set R = the reduction of X();
    assume R\/R~ reduces x,y; then :: Only 2 expansions?
::    given p being RedSequence of R\/R~ such that
    consider p being RedSequence of R\/R~ such that
A2: p.1 = x & p.len p = y by REWRITE1:def 3;
    assume
A0: P[x];
    defpred Q[Nat] means $1+1 in dom p implies P[p.($1+1)];
A3: Q[0] by A0,A2;
A4: for i being Nat st Q[i] holds Q[i+1]
    proof
      let i be Nat; reconsider j = i as Element of NAT by ORDINAL1:def 12;
      assume
B1:   Q[i] & i+1+1 in dom p; then
B4:   i+1+1 <= len p & i+1 >= 1 by NAT_1:11,FINSEQ_3:25; then
      j+1 in dom p by SEQ_4:134; then
B3:   [p.(i+1), p.(i+1+1)] in R\/R~ by B1,REWRITE1:def 2; then
      reconsider a = p.(i+1), b = p.(i+1+1) as Element of X() by ZFMISC_1:87;
      [a,b] in R or [a,b] in R~ by B3,XBOOLE_0:def 3; then
      a ==> b or b ==> a by RELAT_1:def 7; then
      P[a] & a <==> b by B1,B4,SEQ_4:134;
      hence P[p.(i+1+1)] by A1;
    end;
A5: for i being Nat holds Q[i] from NAT_1:sch 2(A3,A4);
    len p >= 0+1 by NAT_1:13; then
    (ex i being Nat st len p = 1+i) &
    len p in dom p by NAT_1:10,FINSEQ_5:6;
    hence thesis by A2,A5;
end;

scheme Star2A{X() -> ARS, P[object], a, b() -> Element of X()}:
  P[b()]
provided
A1: a() <=*=> b() and
A2: P[a()] and
A3: for x,y being Element of X() st x <==> y & P[x] holds P[y]
  proof
    for x,y being Element of X() st x <=*=> y & P[x] holds P[y] from Star2(A3);
    hence thesis by A1,A2;
  end;

definition
  let X,x,y;
  pred x <=+=> y means: Def8: ex z st x <==> z & z <=*=> y;
  symmetry
  proof let x,y;
    given z such that
A1: x <==> z & z <=*=> y;
    defpred P[Element of X] means ex u st x <=*=> u & u <==> $1;
A2: for y,z st y <==> z & P[y] holds P[z]
    proof
      let y,z; assume
A3:   y <==> z;
      given u such that
A4:   x <=*=> u & u <==> y;
      take y;
      u <=*=> y by A4,Th6;
      hence thesis by A3,A4,Th7;
    end;
A5: for y,z st y <=*=> z & P[y] holds P[z] from Star2(A2);
    ex u st x <=*=> u & u <==> y by A1,A5;
    hence thesis;
  end;
end;

theorem Th8:
  x <=+=> y iff ex z st x <=*=> z & z <==> y
  proof
    x <=+=> y iff ex z st y <==> z & z <=*=> x by Def8;
    hence thesis;
  end;

theorem Lem1:
  x =01=> y implies x =*=> y by Th2;

theorem Lem2:
  x =+=> y implies x =*=> y
  proof
    assume
A1: x =+=> y;
    consider z such that
A2: x ==> z & z =*=> y by A1;
A3: x =*=> z by A2,Th2;
    thus x =*=> y by A2,A3,Th3;
  end;

theorem
  x ==> y implies x =+=> y;

theorem Lem3:
  x ==> y & y ==> z implies x =*=> z
  proof
    assume
A1: x ==> y;
    assume
A2: y ==> z;
A3: x =*=> y by A1,Th2;
A4: y =*=> z by A2,Th2;
    thus x =*=> z by A3,A4,Th3;
  end;

theorem Lem4:
  x ==> y & y =01=> z implies x =*=> z
  proof
    assume
A1: x ==> y;
    assume
A2: y =01=> z;
A3: x =*=> y by A1,Th2;
A4: y =*=> z by A2,Lem1;
    thus x =*=> z by A3,A4,Th3;
  end;

theorem Lem5:
  x ==> y & y =*=> z implies x =*=> z
  proof
    assume
A1: x ==> y;
    assume
A2: y =*=> z;
A3: x =*=> y by A1,Th2;
    thus x =*=> z by A3,A2,Th3;
  end;

theorem Lem5A:
  x ==> y & y =+=> z implies x =*=> z
  proof
    assume
A1: x ==> y;
    assume
A2: y =+=> z;
A3: x =*=> y by A1,Th2;
A4: y =*=> z by A2,Lem2;
    thus x =*=> z by A3,A4,Th3;
  end;

theorem
  x =01=> y & y ==> z implies x =*=> z
  proof
    assume
A1: x =01=> y;
    assume
A2: y ==> z;
A3: x =*=> y by A1,Lem1;
A4: y =*=> z by A2,Th2;
    thus x =*=> z by A3,A4,Th3;
  end;

theorem
  x =01=> y & y =01=> z implies x =*=> z
  proof
    assume
A1: x =01=> y;
    assume
A2: y =01=> z;
A3: x =*=> y by A1,Lem1;
A4: y =*=> z by A2,Lem1;
    thus x =*=> z by A3,A4,Th3;
  end;

theorem Lem8:
  x =01=> y & y =*=> z implies x =*=> z
  proof
    assume
A1: x =01=> y;
    assume
A2: y =*=> z;
A3: x =*=> y by A1,Lem1;
    thus x =*=> z by A3,A2,Th3;
  end;

theorem
  x =01=> y & y =+=> z implies x =*=> z
  proof
    assume
A1: x =01=> y;
    assume
A2: y =+=> z;
A3: x =*=> y by A1,Lem1;
A4: y =*=> z by A2,Lem2;
    thus x =*=> z by A3,A4,Th3;
  end;

theorem Lem10:
  x =*=> y & y ==> z implies x =*=> z
  proof
    assume
A1: x =*=> y;
    assume
A2: y ==> z;
A4: y =*=> z by A2,Th2;
    thus x =*=> z by A1,A4,Th3;
  end;

theorem Lem11:
  x =*=> y & y =01=> z implies x =*=> z
  proof
    assume
A1: x =*=> y;
    assume
A2: y =01=> z;
A4: y =*=> z by A2,Lem1;
    thus x =*=> z by A1,A4,Th3;
  end;

theorem Lem11A:
  x =*=> y & y =+=> z implies x =*=> z
  proof
    assume
A1: x =*=> y;
    assume
A2: y =+=> z;
A4: y =*=> z by A2,Lem2;
    thus x =*=> z by A1,A4,Th3;
  end;

theorem
  x =+=> y & y ==> z implies x =*=> z
  proof
    assume
A1: x =+=> y;
    assume
A2: y ==> z;
A3: x =*=> y by A1,Lem2;
A4: y =*=> z by A2,Th2;
    thus x =*=> z by A3,A4,Th3;
  end;

theorem
  x =+=> y & y =01=> z implies x =*=> z
  proof
    assume
A1: x =+=> y;
    assume
A2: y =01=> z;
A3: x =*=> y by A1,Lem2;
A4: y =*=> z by A2,Lem1;
    thus x =*=> z by A3,A4,Th3;
  end;

theorem
  x =+=> y & y =+=> z implies x =*=> z
  proof
    assume
A1: x =+=> y;
    assume
A2: y =+=> z;
A3: x =*=> y by A1,Lem2;
A4: y =*=> z by A2,Lem2;
    thus x =*=> z by A3,A4,Th3;
  end;

theorem
  x ==> y & y ==> z implies x =+=> z by Th2;


theorem
  x ==> y & y =01=> z implies x =+=> z by Lem1;

theorem
  x ==> y & y =+=> z implies x =+=> z by Lem2;

theorem
  x =01=> y & y ==> z implies x =+=> z by Lem1,Th4;

theorem
  x =01=> y & y =+=> z implies x =+=> z
  proof
    assume
A1: x =01=> y;
    assume
A2: y =+=> z;
    consider u such that
A3: y =*=> u & u ==> z by A2,Th4;
    thus x =+=> z by A3,A1,Lem8,Th4;
  end;

theorem
  x =*=> y & y =+=> z implies x =+=> z
  proof
    assume
A1: x =*=> y;
    assume
A2: y =+=> z;
    consider u such that
A3: y =*=> u & u ==> z by A2,Th4;
    thus x =+=> z by A3,A1,Th3,Th4;
  end;

theorem
  x =+=> y & y ==> z implies x =+=> z by Lem10;

theorem
  x =+=> y & y =01=> z implies x =+=> z by Lem11;

theorem
  x =+=> y & y =*=> z implies x =+=> z by Th3;

theorem
  x =+=> y & y =+=> z implies x =+=> z by Lem11A;

theorem Lem1A:
  x <=01=> y implies x <=*=> y by Th6;

theorem Lem2A:
  x <=+=> y implies x <=*=> y
  proof
    assume
A1: x <=+=> y;
    consider z such that
A2: x <==> z & z <=*=> y by A1;
A3: x <=*=> z by A2,Th6;
    thus x <=*=> y by A2,A3,Th7;
  end;

theorem LemB:
  x <==> y implies x <=+=> y;

theorem
  x <==> y & y <==> z implies x <=*=> z
  proof
    assume
A1: x <==> y;
    assume
A2: y <==> z;
A3: x <=*=> y by A1,Th6;
A4: y <=*=> z by A2,Th6;
    thus x <=*=> z by A3,A4,Th7;
  end;

theorem Lem4A:
  x <==> y & y <=01=> z implies x <=*=> z
  proof
    assume
A1: x <==> y;
    assume
A2: y <=01=> z;
A3: x <=*=> y by A1,Th6;
A4: y <=*=> z by A2,Lem1A;
    thus x <=*=> z by A3,A4,Th7;
  end;

theorem
  x <=01=> y & y <==> z implies x <=*=> z by Lem4A;

theorem Lem5a:
  x <==> y & y <=*=> z implies x <=*=> z
  proof
    assume
A1: x <==> y;
    assume
A2: y <=*=> z;
A3: x <=*=> y by A1,Th6;
    thus x <=*=> z by A3,A2,Th7;
  end;

theorem
  x <=*=> y & y <==> z implies x <=*=> z by Lem5a;

theorem Lem5B:
  x <==> y & y <=+=> z implies x <=*=> z
  proof
    assume
A1: x <==> y;
    assume
A2: y <=+=> z;
A3: x <=*=> y by A1,Th6;
A4: y <=*=> z by A2,Lem2A;
    thus x <=*=> z by A3,A4,Th7;
  end;

theorem
  x <=+=> y & y <==> z implies x <=*=> z by Lem5B;

theorem
  x <=01=> y & y <=01=> z implies x <=*=> z
  proof
    assume
A1: x <=01=> y;
    assume
A2: y <=01=> z;
A3: x <=*=> y by A1,Lem1A;
A4: y <=*=> z by A2,Lem1A;
    thus x <=*=> z by A3,A4,Th7;
  end;

theorem Lm8:
  x <=01=> y & y <=*=> z implies x <=*=> z
  proof
    assume
A1: x <=01=> y;
    assume
A2: y <=*=> z;
A3: x <=*=> y by A1,Lem1A;
    thus x <=*=> z by A3,A2,Th7;
  end;

theorem
  x <=*=> y & y <=01=> z implies x <=*=> z by Lm8;

theorem Lem9:
  x <=01=> y & y <=+=> z implies x <=*=> z
  proof
    assume
A1: x <=01=> y;
    assume
A2: y <=+=> z;
A3: x <=*=> y by A1,Lem1A;
A4: y <=*=> z by A2,Lem2A;
    thus x <=*=> z by A3,A4,Th7;
  end;

theorem
  x <=+=> y & y <=01=> z implies x <=*=> z by Lem9;

theorem Lem11A:
  x <=*=> y & y <=+=> z implies x <=*=> z
  proof
    assume
A1: x <=*=> y;
    assume
A2: y <=+=> z;
A4: y <=*=> z by A2,Lem2A;
    thus x <=*=> z by A1,A4,Th7;
  end;

theorem
  x <=+=> y & y <=+=> z implies x <=*=> z
  proof
    assume
A1: x <=+=> y;
    assume
A2: y <=+=> z;
A3: x <=*=> y by A1,Lem2A;
A4: y <=*=> z by A2,Lem2A;
    thus x <=*=> z by A3,A4,Th7;
  end;

theorem
  x <==> y & y <==> z implies x <=+=> z by Th6;

theorem
  x <==> y & y <=01=> z implies x <=+=> z by Lem1A;

theorem
  x <==> y & y <=+=> z implies x <=+=> z by Lem2A;

theorem Lem18:
  x <=01=> y & y <=+=> z implies x <=+=> z
  proof
    assume
A1: x <=01=> y;
    assume
A2: y <=+=> z;
    consider u such that
A3: y <=*=> u & u <==> z by A2,Th8;
    thus x <=+=> z by A3,A1,Lm8,Th8;
  end;

theorem
  x <=*=> y & y <=+=> z implies x <=+=> z
  proof
    assume
A1: x <=*=> y;
    assume
A2: y <=+=> z;
    consider u such that
A3: y <=*=> u & u <==> z by A2,Th8;
    thus x <=+=> z by A3,A1,Th7,Th8;
  end;

theorem
  x <=+=> y & y <=+=> z implies x <=+=> z by Lem11A;

theorem Lem31:
  x <=01=> y implies x <== y or x = y or x ==> y
  proof
    assume
A1: x <=01=> y;
A2: x <==> y or x = y by A1;
    thus x <== y or x = y or x ==> y by A2;
  end;

theorem
  x <== y or x = y or x ==> y implies x <=01=> y
  proof
    assume
A1: x <== y or x = y or x ==> y;
A2: x <==> y or x = y by A1;
    thus x <=01=> y by A2;
  end;

theorem
  x <=01=> y implies x <=01= y or x ==> y
  proof
    assume
A1: x <=01=> y;
A2: x <==> y or x = y by A1;
    thus x <=01= y or x ==> y by A2;
  end;

theorem
  x <=01= y or x ==> y implies x <=01=> y
  proof
    assume
A1: x <=01= y or x ==> y;
A3: x <==> y or x = y by A1;
    thus x <=01=> y by A3;
  end;

theorem
  x <=01=> y implies x <=01= y or x =+=> y
  proof
    assume
A1: x <=01=> y;
A2: x <==> y or x = y by A1;
    thus x <=01= y or x =+=> y by A2;
  end;

theorem
  x <=01=> y implies x <=01= y or x <==> y;

theorem
  x <=01= y or x <==> y implies x <=01=> y
  proof
    assume
A1: x <=01= y or x <==> y;
A3: x = y or x <==> y by A1;
    thus x <=01=> y by A3;
  end;

theorem
  x <=*=> y & y ==> z implies x <=+=> z
  proof
    assume
A1: x <=*=> y;
    assume
A2: y ==> z;
A4: y <==> z by A2;
    thus x <=+=> z by A1,A4,Def8;
  end;

theorem
  x <=+=> y & y ==> z implies x <=+=> z
  proof
    assume
A1: x <=+=> y;
    assume
A2: y ==> z;
A3: x <=*=> y by A1,Lem2A;
A4: y <==> z by A2;
    thus x <=+=> z by A3,A4,Def8;
  end;

theorem
  x <=01=> y implies x <=01= y or x ==> y
  proof
    assume
A1: x <=01=> y;
A2: x = y or x <==> y by A1;
    thus x <=01= y or x ==> y by A2;
  end;

theorem
x <=01=> y implies x <=01= y or x =+=> y
  proof
    assume
A1: x <=01=> y;
A2: x = y or x <==> y by A1;
    thus x <=01= y or x =+=> y by A2;
  end;

theorem Lem43:
  x <=01= y or x ==> y implies x <=01=> y
  proof
    assume
A1: x <=01= y or x ==> y;
A3: x <==> y or x = y by A1;
    thus x <=01=> y by A3;
  end;

theorem
  x <=01= y or x <==> y implies x <=01=> y
  proof
    assume
A1: x <=01= y or x <==> y;
A3: x <==> y or x = y by A1;
    thus x <=01=> y by A3;
  end;

theorem
  x <=01=> y implies x <=01= y or x <==> y;

theorem
  x <=+=> y & y ==> z implies x <=+=> z
  proof
    assume
A1: x <=+=> y;
    assume
A2: y ==> z;
A3: x <=*=> y by A1,Lem2A;
A4: y <==> z by A2;
    thus x <=+=> z by A3,A4,Def8;
  end;

theorem
  x <=*=> y & y ==> z implies x <=+=> z
  proof
    assume
A1: x <=*=> y;
    assume
A2: y ==> z;
A4: y <==> z by A2;
    thus x <=+=> z by A1,A4,Def8;
  end;

theorem
  x <=01=> y & y ==> z implies x <=+=> z
  proof
    assume
A1: x <=01=> y;
    assume
A2: y ==> z;
A4: y <==> z by A2;
    thus x <=+=> z by A1,A4,Lem1A,Def8;
  end;

theorem
  x <=+=> y & y =01=> z implies x <=+=> z
  proof
    assume
A1: x <=+=> y;
    assume
A2: y =01=> z;
A3: y <=01=> z by A2,Lem43;
    thus x <=+=> z by A1,A3,Lem18;
  end;

theorem
  x <==> y & y =01=> z implies x <=+=> z
  proof
    assume
A1: x <==> y;
    assume
A2: y =01=> z;
A3: y <=01=> z by A2,Lem43;
    thus x <=+=> z by A3,A1,LemB,Lem18;
  end;

theorem
  x ==> y & y ==> z & z ==> u implies x =+=> u by Lem3;

theorem
  x ==> y & y =01=> z & z ==> u implies x =+=> u by Lem4,Th4;

theorem
  x ==> y & y =*=> z & z ==> u implies x =+=> u by Lem5,Th4;

theorem
  x ==> y & y =+=> z & z ==> u implies x =+=> u
  proof
    assume
A1: x ==> y;
    assume
A2: y =+=> z;
    assume
A3: z ==> u;
A4: x =*=> z by A1,A2,Lem5A;
    thus x =+=> u by A3,A4,Th4;
  end;

theorem LemZ:
  x =*=> y implies x <=*=> y
  proof
    assume
A1: x =*=> y;
    defpred P[Element of X] means x <=*=> $1;
A2: P[x];
A3: for y,z st y ==> z & P[y] holds P[z]
    proof
      let y,z;
      assume
A4:   y ==> z;
      assume
A5:   P[y];
A6:   y <==> z by A4;
A7:   y <=*=> z by A6,Th6;
      thus P[z] by A5,A7,Th7;
    end;
    thus P[y] from Star1(A1,A2,A3);
  end;

theorem
  for z st
    for x,y st x ==> z & x ==> y holds y ==> z
  for x,y st x ==> z & x =*=> y
  holds y ==> z
  proof
    let z;
    assume
A:  for x,y st x ==> z & x ==> y holds y ==> z;
    let x,y;
    assume
B:  x ==> z & x =*=> y;
    defpred P[Element of X] means $1 ==> z;
C:  for u,v st u ==> v & P[u] holds P[v] by A;
D:  for u,v st u =*=> v & P[u] holds P[v] from Star(C);
    thus y ==> z by B,D;
end;

theorem
  (for x,y st x ==> y holds y ==> x)
  implies
  for x,y st x <=*=> y holds x =*=> y
  proof
    assume
A:  for x,y st x ==> y holds y ==> x;
    let x,y;
    assume
B:  x <=*=> y;
    defpred P[Element of X] means x =*=> $1;
C:  for u,v st u <==> v & P[u] holds P[v] by A,Lem10;
D:  for u,v st u <=*=> v & P[u] holds P[v] from Star2(C);
    thus x =*=> y by B,D;
end;

theorem LemN:
  x =*=> y implies x = y or x =+=> y
  proof
    assume
A1: x =*=> y;
    defpred P[Element of X] means x = $1 or x =+=> $1;
A2: P[x];
A3: for y,z st y ==> z & P[y] holds P[z]
    proof
      let y,z;
      assume
A4:   y ==> z;
      assume
A5:   P[y];
A6:   x =*=> y by A5,Lem2;
      thus P[z] by A6,A4,Th4;
    end;
    thus P[y] from Star1(A1,A2,A3);
  end;

theorem
  (for x,y,z st x ==> y & y ==> z holds x ==> z)
  implies
  for x,y st x =+=> y holds x ==> y
  proof
    assume
A1: for x,y,z st x ==> y & y ==> z holds x ==> z;
    let x,y;
    assume
A2: x =+=> y;
    consider z such that
A3: x ==> z and
A4: z =*=> y by A2;
    defpred P[Element of X] means x ==> $1;
A5: P[z] by A3;
A6: for u,v st u ==> v & P[u] holds P[v] by A1;
    thus P[y] from Star1(A4,A5,A6);
  end;

begin :: Examples of ARS

scheme ARSex{A() -> non empty set, R[object,object]}:
  ex X being strict non empty ARS st the carrier of X = A() &
  for x,y being Element of X holds x ==> y iff R[x,y]
  proof
    consider r being Relation of A() such that
A1: for x,y being Element of A() holds [x,y] in r iff R[x,y]
    from RELSET_1:sch 2;
    take X = ARS(#A(), r#);
    thus the carrier of X = A();
    thus thesis by A1;
  end;

definition
  func ARS_01 -> strict ARS means:
Def18:
  the carrier of it = {0,1} &
  the reduction of it = [:{0},{0,1}:];
  existence
  proof
    {0} c= {0,1} by ZFMISC_1:7; then
    reconsider r = [:{0},{0,1}:] as Relation of {0,1} by ZFMISC_1:96;
    take X = ARS(#{0,1}, r#);
    thus thesis;
  end;
  uniqueness;
  func ARS_02 -> strict ARS means:
Def19:
  the carrier of it = {0,1,2} &
  the reduction of it = [:{0},{0,1,2}:];
  existence
  proof
    {0} c= {0,1,2} by SETWISEO:1; then
    reconsider r = [:{0},{0,1,2}:] as Relation of {0,1,2} by ZFMISC_1:96;
    take X = ARS(#{0,1,2}, r#);
    thus thesis;
  end;
  uniqueness;
end;

registration
  cluster ARS_01 -> non empty;
  coherence by Def18;
  cluster ARS_02 -> non empty;
  coherence by Def19;
end;

reserve i,j,k for Element of ARS_01;

theorem ThA1:
  for s being set holds s is Element of ARS_01 iff s = 0 or s = 1
  proof
    let s be set;
    the carrier of ARS_01 = {0,1} by Def18;
    hence thesis by TARSKI:def 2;
  end;

theorem
  i ==> j iff i = 0
  proof
    the reduction of ARS_01 = [:{0},{0,1}:] by Def18; then
    i ==> j iff i in {0} & j in {0,1} by ZFMISC_1:87; then
    i ==> j iff i = 0 & (j = 0 or j = 1) by TARSKI:def 1,def 2;
    hence thesis by ThA1;
  end;

reserve l,m,n for Element of ARS_02;

theorem ThB1:
  for s being set holds s is Element of ARS_02 iff s = 0 or s = 1 or s = 2
  proof
    let s be set;
    the carrier of ARS_02 = {0,1,2} by Def19;
    hence thesis by ENUMSET1:def 1;
  end;

theorem
  m ==> n iff m = 0
  proof
    the reduction of ARS_02 = [:{0},{0,1,2}:] by Def19; then
    m ==> n iff m in {0} & n in {0,1,2} by ZFMISC_1:87; then
    m ==> n iff m = 0 & (n = 0 or n = 1 or n = 2)
    by TARSKI:def 1,ENUMSET1:def 1;
    hence thesis by ThB1;
  end;

begin :: Normal Forms

definition
  let X,x;
  attr x is normform means not ex y st x ==> y;
end;

theorem Ch1:
  x is normform iff x is_a_normal_form_wrt the reduction of X
  proof set R = the reduction of X;
    thus x is normform implies x is_a_normal_form_wrt the reduction of X
    proof assume
Z0:   not ex y st x ==> y;
      let a be object;
      assume
Z1:   [x,a] in the reduction of X; then
      reconsider y = a as Element of X by ZFMISC_1:87;
      x ==> y by Z1;
      hence thesis by Z0;
    end;
    assume
Z1: not ex b being object st [x,b] in R;
    let y;
    assume [x,y] in the reduction of X;
    hence thesis by Z1;
  end;

definition
  let X,x,y;
  pred x is_normform_of y means x is normform & y =*=> x;
end;

theorem Ch2:
  x is_normform_of y iff x is_a_normal_form_of y, the reduction of X
  proof set R = the reduction of X;
    thus x is_normform_of y implies x is_a_normal_form_of y, R
    proof assume
      x is normform & R reduces y,x;
      hence x is_a_normal_form_wrt R & R reduces y,x by Ch1;
    end;
    assume x is_a_normal_form_wrt R & R reduces y,x;
    hence x is normform & R reduces y,x by Ch1;
  end;

definition
  let X,x;
  attr x is normalizable means ex y st y is_normform_of x;
end;

theorem Ch3:
  x is normalizable iff x has_a_normal_form_wrt the reduction of X
  proof
    set R = the reduction of X;
A0: field R c= (the carrier of X)\/the carrier of X by RELSET_1:8;
    thus x is normalizable implies x has_a_normal_form_wrt R
    proof
      given y such that
A1:   y is_normform_of x;
      take y; thus thesis by A1,Ch2;
    end;
    given a being object such that
A2: a is_a_normal_form_of x, R;
    R reduces x,a by A2,REWRITE1:def 6; then
    x = a or a in field R by REWRITE1:18; then
    reconsider a as Element of X by A0;
    take a; thus thesis by A2,Ch2;
  end;

definition
  let X;
  attr X is WN means for x holds x is normalizable;
  attr X is SN means
  for f being Function of NAT, the carrier of X
  ex i being Nat st not f.i ==> f.(i+1);
  attr X is UN* means
  for x,y,z st y is_normform_of x & z is_normform_of x holds y = z;
  attr X is UN means
  for x,y st x is normform & y is normform & x <=*=> y holds x = y;
  attr X is N.F. means
  for x,y st x is normform & x <=*=> y holds y =*=> x;
end;

theorem
  X is WN iff the reduction of X is weakly-normalizing
  proof set R = the reduction of X;
A0: field R c= (the carrier of X)\/the carrier of X by RELSET_1:8;
    thus X is WN implies R is weakly-normalizing
    proof assume
A1:   for x holds x is normalizable;
      let a be object; assume a in field R; then
      reconsider a as Element of X by A0;
      a is normalizable by A1;
      hence thesis by Ch3;
    end;
    assume
A2: for a being object st a in field R
    holds a has_a_normal_form_wrt R;
    let x;
    per cases;
    suppose
      x in field R;
      hence thesis by A2,Ch3;
    end;
    suppose
A3:   not x in field R;
      take x;
      thus x is normform
      proof
        let y;
        thus not [x,y] in R by A3,RELAT_1:15;
      end;
      thus thesis;
    end;
  end;

theorem Ch7:
  X is SN implies the reduction of X is strongly-normalizing
  proof set R = the reduction of X;
    set A = the carrier of X;
A0: field R c= A \/ A by RELSET_1:8;
    assume
A1: for f being Function of NAT, A
    ex i being Nat st not f.i ==> f.(i+1);
    let f be ManySortedSet of NAT;
    per cases;
    suppose f is A-valued; then
      rng f c= A & dom f = NAT by RELAT_1:def 19,PARTFUN1:def 2; then
      reconsider g = f as Function of NAT, A by FUNCT_2:2;
      consider i being Nat such that
A2:   not g.i ==> g.(i+1) by A1;
      take i;
      thus not [f.i,f.(i+1)] in R by A2;
    end;
    suppose
      f is not A-valued; then
      consider a being object such that
A3:   a in rng f & not a in A by TARSKI:def 3,RELAT_1:def 19;
      consider i being object such that
A4:   i in dom f & a = f.i by A3,FUNCT_1:def 3;
      reconsider i as Element of NAT by A4;
      take i;
      assume [f.i,f.(i+1)] in R; then
      a in field R by A4,RELAT_1:15;
      hence thesis by A0,A3;
    end;
  end;

theorem Ch8:
  X is non empty & the reduction of X is strongly-normalizing implies X is SN
  proof set R = the reduction of X;
    set A = the carrier of X;
    assume
A1: X is non empty;
    assume
A5: for f being ManySortedSet of NAT
    ex i being Nat st not [f.i,f.(i+1)] in R;
    let f be Function of NAT, A;
    consider i being Nat such that
A6: not [f.i,f.(i+1)] in R by A1,A5;
    take i;
    thus not [f.i,f.(i+1)] in R by A6;
  end;

reserve A for set;

theorem ThSN:
  for X holds X is SN iff
  not ex A,z st z in A & for x st x in A ex y st y in A & x ==> y
  proof
    let X;
    thus X is SN implies not ex A,z st z in A &
    for x st x in A ex y st y in A & x ==> y
    proof assume
00:   for f being Function of NAT, the carrier of X
      ex i being Nat st not f.i ==> f.(i+1);
      given A,z such that
01:   z in A & for x st x in A ex y st y in A & x ==> y;
      ex y st y in A & z ==> y by 01; then
      reconsider X0 = X as non empty ARS;
      reconsider z0 = z as Element of X0;
      defpred P[Nat,Element of X0,Element of X0] means
      $2 in A implies $3 in A & $2 ==> $3;
02:   for i being Nat, x being Element of X0
      ex y being Element of X0 st P[i,x,y] by 01;
      consider f being Function of NAT, the carrier of X0 such that
03:   f.0 = z0 and
04:   for i being Nat holds P[i,f.i,f.(i+1)]
      from RECDEF_1:sch 2(02);
      defpred Q[Nat] means f.$1 ==> f.($1+1) & f.$1 in A;
05:   Q[0] by 01,03,04;
06:   now let i be Nat; assume Q[i]; then
        f.(i+1) in A by 04;
        hence Q[i+1] by 04;
      end;
      for i being Nat holds Q[i] from NAT_1:sch 2(05,06);
      hence contradiction by 00;
    end;
    assume
00: not ex A,z st z in A &
    for x st x in A ex y st y in A & x ==> y;
    given f being Function of NAT, the carrier of X such that
01: for i being Nat holds f.i ==> f.(i+1);
    f.0 ==> f.(0+1) by 01; then
04: X is non empty & 0 in NAT by ORDINAL1:def 12; then
02: f.0 in rng f by FUNCT_2:4;
    now let x; assume x in rng f; then
      consider i being object such that
03:   i in dom f & x = f.i by FUNCT_1:def 3;
      reconsider i as Element of NAT by 03;
      take y = f.(i+1);
      thus y in rng f by 04,FUNCT_2:4;
      thus x ==> y by 01,03;
    end;
    hence contradiction by 00,02;
  end;

scheme notSN{X() -> ARS, P[object]}:
  X() is not SN
provided
A1: ex x being Element of X() st P[x]
 and
A2: for x being Element of X() st P[x]
    ex y being Element of X() st P[y] & x ==> y
  proof
    set A = {x where x is Element of X(): P[x]};
    consider z being Element of X() such that
A3: P[z] by A1;
A4: z in A by A3;
    now let x be Element of X(); assume x in A; then
      ex a being Element of X() st x = a & P[a]; then
      consider y being Element of X() such that
A6:   P[y] & x ==> y by A2;
      take y; thus y in A by A6;
      thus x ==> y by A6;
    end;
    hence thesis by A4,ThSN;
  end;

theorem
  X is UN iff the reduction of X is with_UN_property
  proof
    set R = the reduction of X;
    set A = the carrier of X;
A0: field R c= A \/ A by RELSET_1:8;
    thus X is UN implies R is with_UN_property
    proof
      assume
A1:   for x,y st x is normform & y is normform & x <=*=> y holds x = y;
      let a,b be object;
      assume
A2:   a is_a_normal_form_wrt R & b is_a_normal_form_wrt R &
      a,b are_convertible_wrt R;
      per cases;
      suppose a in A & b in A; then
        reconsider x = a, y = b as Element of X;
        x is normform & y is normform & x <=*=> y by A2,Ch1;
        hence a = b by A1;
      end;
      suppose not a in A or not b in A; then
        not a in field R or not b in field R by A0;
        hence a = b by A2,REWRITE1:28,31;
      end;
    end;
    assume
A4: for a,b being object
    st a is_a_normal_form_wrt R & b is_a_normal_form_wrt R &
    a,b are_convertible_wrt R holds a = b;
    let x,y; assume
    x is normform & y is normform & x <=*=> y; then
    x is_a_normal_form_wrt R & y is_a_normal_form_wrt R &
    x,y are_convertible_wrt R by Ch1;
    hence x = y by A4;
  end;

theorem
  X is N.F. iff the reduction of X is with_NF_property
  proof
    set R = the reduction of X;
    set A = the carrier of X;
A0: field R c= A \/ A by RELSET_1:8;
    thus X is N.F. implies R is with_NF_property
    proof
      assume
A1:   for x,y st x is normform & x <=*=> y holds y =*=> x;
      let a,b be object; assume
A2:   a is_a_normal_form_wrt R & a,b are_convertible_wrt R;
      per cases;
      suppose a in A & b in A; then
        reconsider x = a, y = b as Element of X;
        x is normform & x <=*=> y by A2,Ch1; then
        y =*=> x by A1;
        hence R reduces b,a;
      end;
      suppose not a in A or not b in A; then
        not a in field R or not b in field R by A0; then
        a = b by A2,REWRITE1:28,31;
        hence R reduces b,a by REWRITE1:12;
      end;
    end;
    assume
B1: for a,b being object st
      a is_a_normal_form_wrt R & a,b are_convertible_wrt R
    holds R reduces b,a;
    let x,y; assume
    x is normform & x <=*=> y;
    hence R reduces y,x by B1,Ch1;
  end;

definition
  let X;
  let x such that
A: ex y st y is_normform_of x and
B: for y,z st y is_normform_of x & z is_normform_of x holds y = z;
  func nf x -> Element of X means:
Def17:
  it is_normform_of x;
  existence by A;
  uniqueness by B;
end;

theorem
  (ex y st y is_normform_of x) &
  (for y,z st y is_normform_of x & z is_normform_of x holds y = z)
  implies nf x = nf(x, the reduction of X)
  proof set R = the reduction of X;
    set A = the carrier of X;
F0: field R c= A \/ A by RELSET_1:8;
    given y such that
A0: y is_normform_of x;
B0: x has_a_normal_form_wrt R by A0,Ch2,REWRITE1:def 11;
    assume
A1: for y,z st y is_normform_of x & z is_normform_of x holds y = z; then
    nf x is_normform_of x by A0,Def17; then
A2: nf x is_a_normal_form_of x,R by Ch2;
    now
      let b,c be object; assume
A3:   b is_a_normal_form_of x,R & c is_a_normal_form_of x,R; then
A4:   R reduces x,b & R reduces x,c by REWRITE1:def 6;
      per cases;
      suppose x in field R; then
        b in field R & c in field R by A4,REWRITE1:19; then
        reconsider y = b, z = c as Element of X by F0;
        y is_normform_of x & z is_normform_of x by A3,Ch2;
        hence b = c by A1;
      end;
      suppose not x in field R; then
        x = b & x = c by A4,REWRITE1:18;
        hence b = c;
      end;
    end;
    hence nf x = nf(x, the reduction of X) by B0,A2,REWRITE1:def 12;
 end;

theorem LemN1:
  x is normform & x =*=> y implies x = y
  proof
    assume
A1: x is normform;
    assume
A2: x =*=> y;
A4: not x =+=> y by A1;
    thus x = y by A2,A4,LemN;
  end;

theorem LemN2:
  x is normform implies x is_normform_of x;

theorem
  x is normform & y ==> x implies x is_normform_of y by Th2;

theorem
  x is normform & y =01=> x implies x is_normform_of y by Lem1;

theorem
  x is normform & y =+=> x implies x is_normform_of y by Lem2;

theorem
  x is_normform_of y & y is_normform_of x implies x = y by LemN1;

theorem LemN6:
  x is_normform_of y & z ==> y implies x is_normform_of z by Lem5;

theorem LemN7:
  x is_normform_of y & z =*=> y implies x is_normform_of z by Th3;

theorem
  x is_normform_of y & z =*=> x implies x is_normform_of z;

registration
  let X;
  cluster normform -> normalizable for Element of X;
  coherence
  proof let x;
    assume
A1: x is normform;
    take x;
    thus x is_normform_of x by A1;
  end;
end;

theorem LemN5:
  x is normalizable & y ==> x implies y is normalizable by LemN6;

theorem ThWN1:
  X is WN iff for x ex y st y is_normform_of x
  proof
    thus X is WN implies for x ex y st y is_normform_of x
    proof
      assume
A1:   for x holds x is normalizable;
      let x;
A2:   x is normalizable by A1;
      thus ex y st y is_normform_of x by A2;
    end;
    assume
A3: for x ex y st y is_normform_of x;
    let x; thus ex y st y is_normform_of x by A3;
  end;

theorem
  (for x holds x is normform) implies X is WN
  proof
    assume
A1: for x holds x is normform;
    let x;
A2: x is normform by A1;
    thus ex y st y is_normform_of x by A2,LemN2;
  end;

registration
  cluster SN -> WN for ARS;
  coherence
  proof let X;
    assume
A1: X is SN;
    assume
A2: X is not WN;
    consider z such that
A3: z is not normalizable by A2;
    set A = {x: x is not normalizable};
A4: z in A by A3;
A5: for x st x in A ex y st y in A & x ==> y
    proof
      let x;
      assume x in A; then
A6:   ex y st x = y & y is not normalizable; then
      x is not normform; then
      consider y such that
A7:   x ==> y;
      take y;
      y is not normalizable by A6,A7,LemN5;
      hence y in A;
      thus x ==> y by A7;
    end;
    thus contradiction by A1,A4,A5,ThSN;
  end;
end;

theorem LmA:
  x <> y & (for a,b holds a ==> b iff a = x)
  implies y is normform & x is normalizable
  proof
    assume
Z0: x <> y;
    assume
Z2: for a,b holds a ==> b iff a = x;
    thus y is normform by Z0,Z2;
    take y; thus y is normform by Z0,Z2;
    thus thesis by Z2,Th2;
  end;

theorem
  ex X st X is WN & X is not SN
  proof
    defpred R[set,set] means $1 = 0;
    consider X being strict non empty ARS such that
A1: the carrier of X = {0,1} and
A2: for x,y being Element of X holds x ==> y iff R[x,y] from ARSex;
    reconsider z = 0, o = 1 as Element of X by A1,TARSKI:def 2;
A3: z <> o;
    take X;
    thus X is WN
    proof
      let x be Element of X;
      x = 0 or x = 1 by A1,TARSKI:def 2; then
      x is normform or x is normalizable by A2,A3,LmA;
      hence thesis;
    end;
    set A = {z};
A4: z in A by TARSKI:def 1;
    now
      let x be Element of X;
      assume x in A; then
A5:   x = z by TARSKI:def 1;
      take y = z;
      thus y in A & x ==> y by A2,A5,TARSKI:def 1;
    end;
    hence X is not SN by A4,ThSN;
  end;

registration
  cluster N.F. -> UN* for ARS;
  coherence
  proof let X;
    assume
A1: for x,y st x is normform & x <=*=> y holds y =*=> x;
    let x,y,z;
    assume
A2: y is normform & x =*=> y;
    assume
A3: z is normform & x =*=> z;
A4: x <=*=> y & x <=*=> z by A2,A3,LemZ;
A5: y <=*=> z by A4,Th7;
    thus y = z by A2,A1,A3,A5,LemN1;
  end;

  cluster N.F. -> UN for ARS;
  coherence by LemN1;

  cluster UN -> UN* for ARS;
  coherence
  proof let X;
    assume
A1: for x,y st x is normform & y is normform & x <=*=> y holds x = y;
    let x,y,z;
    assume
A2: y is normform & x =*=> y;
    assume
A3: z is normform & x =*=> z;
A4: x <=*=> y & x <=*=> z by A2,A3,LemZ;
    thus y = z by A1,A2,A3,A4,Th7;
  end;
end;

theorem LemN12:
  X is WN UN* & x is normform & x <=*=> y implies y =*=> x
  proof
    assume
A1: X is WN UN*;
    assume
A2: x is normform;
    assume
A3: x <=*=> y;
    defpred P[Element of X] means $1 =*=> x;
A4: for y,z st y <==> z & P[y] holds P[z]
    proof
      let y,z;
      assume
B1:   y <==> z;
      assume
B2:   P[y];
      per cases by B1;
      suppose
C1:     y ==> z;
B3:     z is normalizable by A1;
        consider u such that
B4:     u is_normform_of z by B3;
B5:     u is_normform_of y by C1,B4,LemN6;
B6:     x is_normform_of y by A2,B2;
        thus P[z] by B4,B6,B5,A1;
      end;
      suppose
C2:     y <== z;
        thus P[z] by B2,C2,Lem5;
      end;
    end;
A5: for y,z st y <=*=> z & P[y] holds P[z] from Star2(A4);
    thus y =*=> x by A3,A5;
  end;

registration
  cluster WN UN* -> N.F. for ARS;
  coherence by LemN12;

  cluster WN UN* -> UN for ARS;
  coherence;
end;

theorem Lem21:
  y is_normform_of x & z is_normform_of x & y <> z implies x =+=> y
  proof
    assume
A1: y is_normform_of x;
    assume
A2: z is_normform_of x;
    assume
A3: y <> z;
A6: x = y or x =+=> y by A1,LemN;
    thus x =+=> y by A3,A1,A2,A6,LemN1;
  end;

theorem Lem22:
  X is WN UN* implies nf x is_normform_of x
  proof
    assume
A1: X is WN UN*;
A4: x is normalizable by A1;
A3: y is_normform_of x & z is_normform_of x implies y = z by A1;
    thus nf x is_normform_of x by A4,A3,Def17;
  end;

theorem Lem23:
  X is WN UN* & y is_normform_of x implies y = nf x
  proof
    assume
A1: X is WN UN*;
    assume
A2: y is_normform_of x;
A4: for z,u holds z is_normform_of x & u is_normform_of x implies z = u
    by A1;
    thus y = nf x by A2,A4,Def17;
  end;

theorem Lem24:
  X is WN UN* implies nf x is normform
  proof
    assume
A1: X is WN UN*;
A2: nf x is_normform_of x by A1,Lem22;
    thus nf x is normform by A2;
  end;

theorem
  X is WN UN* implies nf nf x = nf x
  proof
    assume
A1: X is WN UN*;
A2: nf x is normform by A1,Lem24;
    thus nf nf x = nf x by A1,A2,LemN2,Lem23;
  end;

theorem Lem26:
  X is WN UN* & x =*=> y implies nf x = nf y
  proof
    assume
A1: X is WN UN*;
    assume
A2: x =*=> y;
A4: nf y is_normform_of x by A2,A1,Lem22,LemN7;
    thus nf x = nf y by A1,A4,Lem23;
  end;

theorem Lem27:
  X is WN UN* & x <=*=> y implies nf x = nf y
  proof
    assume
A1: X is WN UN*;
    assume
A2: x <=*=> y;
    defpred P[Element of X] means nf x = nf $1;
A3: P[x];
A4: for z,u st z <==> u & P[z] holds P[u] by A1,Th2,Lem26;
    P[y] from Star2A(A2,A3,A4);
    hence thesis;
  end;

theorem
  X is WN UN* & nf x = nf y implies x <=*=> y
  proof
    assume
A1: X is WN UN*;
    assume
A2: nf x = nf y;
    nf x is_normform_of x & nf x is_normform_of y by A1,A2,Lem22; then
    x <=*=> nf x & nf x <=*=> y by LemZ;
    hence thesis by Th7;
  end;

begin :: Divergence and Convergence

definition
  let X,x,y;
  pred x <<>> y means
  ex z st x <=*= z & z =*=> y;
  symmetry;
  reflexivity;
  pred x >><< y means:DEF2:
  ex z st x =*=> z & z <=*= y;
  symmetry;
  reflexivity;
  pred x <<01>> y means
  ex z st x <=01= z & z =01=> y;
  symmetry;
  reflexivity;
  pred x >>01<< y means
  ex z st x =01=> z & z <=01= y;
  symmetry;
  reflexivity;
end;

theorem Ch11:
  x <<>> y iff x,y are_divergent_wrt the reduction of X
  proof set R = the reduction of X;
    thus x <<>> y implies x,y are_divergent_wrt R
    proof
      given z such that
A1:   x <=*= z & z =*=> y;
      take z;
      thus R reduces z,x & R reduces z,y by A1;
    end;
    set A = the carrier of X;
F0: field R c= A \/ A by RELSET_1:8;
    given a being object such that
A2: R reduces a,x & R reduces a,y;
    per cases;
    suppose
      a in field R; then
      reconsider z = a as Element of X by F0;
      take z;
      thus R reduces z,x & R reduces z,y by A2;
    end;
    suppose
      not a in field R; then
      a = x & a = y by A2,REWRITE1:18;
      hence thesis;
    end;
  end;

theorem Ch12:
  x >><< y iff x,y are_convergent_wrt the reduction of X
  proof set R = the reduction of X;
    thus x >><< y implies x,y are_convergent_wrt R
    proof
      given z such that
A1:   z <=*= x & y =*=> z;
      take z;
      thus R reduces x,z & R reduces y,z by A1;
    end;
    set A = the carrier of X;
F0: field R c= A \/ A by RELSET_1:8;
    given a being object such that
A2: R reduces x,a & R reduces y,a;
    per cases;
    suppose
      a in field R; then
      reconsider z = a as Element of X by F0;
      take z;
      thus R reduces x,z & R reduces y,z by A2;
    end;
    suppose
      not a in field R; then
      a = x & a = y by A2,REWRITE1:18;
      hence thesis;
    end;
  end;

theorem
  x <<01>> y iff x,y are_divergent<=1_wrt the reduction of X
  proof set R = the reduction of X;
    thus x <<01>> y implies x,y are_divergent<=1_wrt R
    proof
      given z such that
A1:   x <=01= z & z =01=> y;
      take z;
      (z ==> x or z = x) & (z ==> y or z = y) by A1;
      hence ([z,x] in R or z = x) & ([z,y] in R or z = y);
    end;
    set A = the carrier of X;
F0: field R c= A \/ A by RELSET_1:8;
    given a being object such that
A2: ([a,x] in R or a = x) & ([a,y] in R or a = y);
    a in field R or a = x or a = y by A2,RELAT_1:15; then
    reconsider z = a as Element of X by F0;
    take z;
    thus z = x or z ==> x by A2;
    thus z = y or z ==> y by A2;
  end;

theorem Ch14:
  x >>01<< y iff x,y are_convergent<=1_wrt the reduction of X
  proof set R = the reduction of X;
    thus x >>01<< y implies x,y are_convergent<=1_wrt R
    proof
      given z such that
A1:   z <=01= x & y =01=> z;
      take z;
      (x ==> z or z = x) & (y ==> z or z = y) by A1;
      hence ([x,z] in R or x = z) & ([y,z] in R or y = z);
    end;
    set A = the carrier of X;
F0: field R c= A \/ A by RELSET_1:8;
    given a being object such that
A2: ([x,a] in R or x = a) & ([y,a] in R or y = a);
    a in field R or a = x or a = y by A2,RELAT_1:15; then
    reconsider z = a as Element of X by F0;
    take z;
    thus x = z or x ==> z by A2;
    thus y = z or y ==> z by A2;
  end;

definition
  let X;
  attr X is DIAMOND means
  x <<01>> y implies x >>01<< y;
  attr X is CONF means
  x <<>> y implies x >><< y;
  attr X is CR means
  x <=*=> y implies x >><< y;
  attr X is WCR means
  x <<01>> y implies x >><< y;
end;

definition
  let X;
  attr X is COMP means
  X is SN CONF;
end;

scheme isCR{X() -> non empty ARS, F(Element of X()) -> Element of X()}:
  X() is CR
provided
A1: for x being Element of X() holds x =*=> F(x)
and
A2: for x,y being Element of X() st x <=*=> y holds F(x) = F(y)
  proof
    let x,y be Element of X(); assume x <=*=> y; then
A3: F(x) = F(y) by A2;
    take z = F(x);
    thus thesis by A3,A1;
  end;

Lm3:
  x =*=> y implies x <=*=> y
  proof
    assume
A1: x =*=> y;
    defpred P[Element of X] means x <=*=> $1;
A2: P[x];
A3: for y,z st y ==> z & P[y] holds P[z]
    proof
      let y,z;
      assume
A4:   y ==> z;
      assume
A5:   P[y];
A6:   y <==> z by A4;
A7:   y <=*=> z by A6,Th6;
      thus P[z] by A5,A7,Th7;
    end;
    P[y] from Star1(A1,A2,A3);
    hence thesis;
  end;

Lm2: x <<>> y implies x <=*=> y
  proof
    assume
A1: x <<>> y;
    consider u such that
A2: x <=*= u & u =*=> y by A1;
A3: x <=*=> u & u <=*=> y by A2,Lm3;
    thus x <=*=> y by A3,Th7;
  end;

Lm1: X is CR implies X is CONF by Lm2;

scheme isCOMP{X() -> non empty ARS, F(Element of X()) -> Element of X()}:
  X() is COMP
provided
A1: X() is SN
and
A2: for x being Element of X() holds x =*=> F(x)
and
A3: for x,y being Element of X() st x <=*=> y holds F(x) = F(y)
  proof
    X() is CR from isCR(A2,A3);
    hence X() is SN CONF by A1,Lm1;
  end;

theorem Lem18:
  x <<01>> y implies x <<>> y
  proof
    given z such that
A2: x <=01= z & z =01=> y;
    take z;
    thus x <=*= z & z =*=> y by A2,Lem1;
  end;

theorem Lem18a:
  x >>01<< y implies x >><< y
  proof
    given z such that
A2: x =01=> z & z <=01= y;
    take z;
    thus x =*=> z & z <=*= y by A2,Lem1;
  end;

theorem
  x ==> y implies x <<01>> y
  proof
    assume
A1: x ==> y;
    take x;
    thus x <=01= x & x =01=> y by A1;
  end;

theorem Th17:
  x ==> y implies x >>01<< y
  proof
    assume
A1: x ==> y;
    take y;
    thus x =01=> y & y =01=> y by A1;
  end;

theorem
  x =01=> y implies x <<01>> y;

theorem
  x =01=> y implies x >>01<< y;

theorem
  x <==> y implies x <<01>> y
  proof
    assume
A1: x <==> y;
    per cases by A1;
    suppose
A2:   x ==> y;
      take x;
      thus x <=01= x & x =01=> y by A2;
    end;
    suppose
A3:   x <== y;
      take y;
      thus x <=01= y & y =01=> y by A3;
    end;
  end;

theorem
  x <==> y implies x >>01<< y
  proof
    assume
A1: x <==> y;
    per cases by A1;
    suppose
A2:   x ==> y;
      take y;
      thus x =01=> y & y <=01= y by A2;
    end;
    suppose
A3:   x <== y;
      take x;
      thus x =01=> x & x <=01= y by A3;
    end;
  end;

theorem
  x <=01=> y implies x <<01>> y
  proof
    assume
A1: x <=01=> y;
    per cases by A1,Lem31;
    suppose x = y;
      hence thesis;
    end;
    suppose
A2:   x ==> y;
      take x;
      thus x <=01= x & x =01=> y by A2;
    end;
    suppose
A3:   x <== y;
      take y;
      thus x <=01= y & y =01=> y by A3;
    end;
  end;

theorem
  x <=01=> y implies x >>01<< y
  proof
    assume
A1: x <=01=> y;
    per cases by A1,Lem31;
    suppose x = y;
      hence thesis;
    end;
    suppose
A2:   x ==> y;
      take y;
      thus x =01=> y & y <=01= y by A2;
    end;
    suppose
A3:   x <== y;
      take x;
      thus x =01=> x & x <=01= y by A3;
    end;
  end;

theorem Th17a:
  x ==> y implies x >><< y by Th17,Lem18a;

theorem Lem17:
  x =*=> y implies x >><< y;

theorem
  x =*=> y implies x <<>> y;

theorem
  x =+=> y implies x >><< y
  proof
    assume
A1: x =+=> y;
    take y; thus thesis by A1,Lem2;
  end;

theorem
  x =+=> y implies x <<>> y
  proof
    assume
A1: x =+=> y;
    take x; thus thesis by A1,Lem2;
  end;

theorem Lm11:
  x ==> y & x ==> z implies y <<01>> z
  proof
    assume
A1: x ==> y;
    assume
A2: x ==> z;
    take x;
    thus y <=01= x by A1;
    thus x =01=> z by A2;
  end;

theorem
  x ==> y & z ==> y implies x >>01<< z
  proof
    assume
A1: x ==> y;
    assume
A2: z ==> y;
    take y;
    thus y <=01= x by A1;
    thus z =01=> y by A2;
  end;

theorem
  x >><< z & z <== y implies x >><< y
  proof
    given u such that
A3: x =*=> u & u <=*= z;
    assume
A2: z <== y;
    take u;
    thus x =*=> u by A3;
    thus y =*=> u by A2,A3,Lem5;
  end;

theorem
  x >><< z & z <=01= y implies x >><< y
  proof
    given u such that
A3: x =*=> u & u <=*= z;
    assume
A2: z <=01= y;
    take u;
    thus x =*=> u by A3;
    thus y =*=> u by A2,A3,Lem8;
  end;

theorem Lm5:
  x >><< z & z <=*= y implies x >><< y
  proof
    given u such that
A3: x =*=> u & u <=*= z;
    assume
A2: z <=*= y;
    take u;
    thus x =*=> u by A3;
    thus y =*=> u by A2,A3,Th3;
  end;

theorem Lem19:
  x <<>> y implies x <=*=> y
  proof
    given u such that
A2: x <=*= u & u =*=> y;
A3: x <=*=> u & u <=*=> y by A2,LemZ;
    thus x <=*=> y by A3,Th7;
  end;

theorem
  x >><< y implies x <=*=> y
  proof
    given u such that
A2: x =*=> u & u <=*= y;
A3: x <=*=> u & u <=*=> y by A2,LemZ;
    thus x <=*=> y by A3,Th7;
  end;

begin :: Church-Rosser Property

theorem
  X is DIAMOND iff the reduction of X is subcommutative
  proof
    set R = the reduction of X;
    set A = the carrier of X;
F0: field R c= A \/ A by RELSET_1:8;
    thus X is DIAMOND implies R is subcommutative
    proof assume
A1:   x <<01>> y implies x >>01<< y;
      let a,b,c be object;
      assume
A2:   [a,b] in R & [a,c] in R; then
      a in field R & b in field R & c in field R by RELAT_1:15; then
      reconsider x = a, y = b, z = c as Element of X by F0;
      x ==> y & x ==> z by A2; then
      x =01=> y & x =01=> z; then
      y <<01>> z;
      hence b,c are_convergent<=1_wrt R by A1,Ch14;
    end;
    assume
A3: for a,b,c being object st [a,b] in R & [a,c] in R
    holds b,c are_convergent<=1_wrt R;
    let x,y; given z such that
A4: x <=01= z & z =01=> y;
    per cases by A4;
    suppose
      x <== z & z ==> y;
      hence thesis by A3,Ch14;
    end;
    suppose
      x = z & z = y;
      hence thesis;
    end;
    suppose
      x <== z & z = y;
      hence thesis by Th17;
    end;
    suppose
      x = z & z ==> y;
      hence thesis by Th17;
    end;
  end;

theorem Ch17:
  X is CONF iff the reduction of X is confluent
  proof
    set R = the reduction of X;
    set A = the carrier of X;
F0: field R c= A \/ A by RELSET_1:8;
    thus X is CONF implies R is confluent
    proof assume
A1:   x <<>> y implies x >><< y;
      let a,b be object; assume
A2:   a,b are_divergent_wrt R; then
A3:   a,b are_convertible_wrt R by REWRITE1:37;
      per cases by A3,REWRITE1:32;
      suppose
        a in field R & b in field R; then
        reconsider x = a, y = b as Element of X by F0;
        x <<>> y by A2,Ch11;
        hence a,b are_convergent_wrt R by A1,Ch12;
      end;
      suppose
        a = b;
        hence a,b are_convergent_wrt R by REWRITE1:38;
      end;
    end;
    assume
A5: for a,b being object st a,b are_divergent_wrt R
    holds a,b are_convergent_wrt R;
    let x,y; assume x <<>> y; then
    x,y are_divergent_wrt R by Ch11;
    hence thesis by A5,Ch12;
  end;

theorem
  X is CR iff the reduction of X is with_Church-Rosser_property
  proof
    set R = the reduction of X;
    set A = the carrier of X;
F0: field R c= A \/ A by RELSET_1:8;
    thus X is CR implies R is with_Church-Rosser_property
    proof assume
A1:   x <=*=> y implies x >><< y;
      let a,b be object; assume
A2:   a,b are_convertible_wrt R;
      per cases by A2,REWRITE1:32;
      suppose
        a in field R & b in field R; then
        reconsider x = a, y = b as Element of X by F0;
        x <=*=> y by A2;
        hence a,b are_convergent_wrt R by A1,Ch12;
      end;
      suppose
        a = b;
        hence a,b are_convergent_wrt R by REWRITE1:38;
      end;
    end;
    assume
A5: for a,b being object st a,b are_convertible_wrt R
    holds a,b are_convergent_wrt R;
    let x,y; assume x <=*=> y;
    hence thesis by A5,Ch12;
  end;

theorem
  X is WCR iff the reduction of X is locally-confluent
  proof
    set R = the reduction of X;
    set A = the carrier of X;
F0: field R c= A \/ A by RELSET_1:8;
    thus X is WCR implies R is locally-confluent
    proof assume
A1:   x <<01>> y implies x >><< y;
      let a,b,c be object; assume
A2:   [a,b] in R & [a,c] in R; then
      a in field R & b in field R & c in field R by RELAT_1:15; then
      reconsider x = a, y = b, z = c as Element of X by F0;
      x ==> y & x ==> z by A2; then
      x =01=> y & x =01=> z; then
      y <<01>> z;
      hence b,c are_convergent_wrt R by A1,Ch12;
    end;
    assume
A3: for a,b,c being object st [a,b] in R & [a,c] in R
    holds b,c are_convergent_wrt R;
    let x,y; given z such that
A4: x <=01= z & z =01=> y;
    per cases by A4;
    suppose
      x <== z & z ==> y;
      hence thesis by A3,Ch12;
    end;
    suppose
      x = z & z = y;
      hence thesis;
    end;
    suppose
      x <== z & z = y;
      hence thesis by Th17a;
    end;
    suppose
      x = z & z ==> y;
      hence thesis by Th17a;
    end;
  end;

theorem
  for X being non empty ARS holds X is COMP iff the reduction of X is complete
  proof let X be non empty ARS;
    set R = the reduction of X;
A2: X is CONF iff R is confluent by Ch17;
    X is SN iff R is strongly-normalizing by Ch7,Ch8;
    hence thesis by A2;
  end;

theorem LemA:
  X is DIAMOND & x <=*= z & z =01=> y implies
  ex u st x =01=> u & u <=*= y
  proof
    assume
A1: for x,y st x <<01>> y holds x >>01<< y;
    assume
A2: x <=*= z;
    assume
A3: z =01=> y;
    defpred P[Element of X] means ex u st $1 =01=> u & u <=*= y;
A4: for u,v st u ==> v & P[u] holds P[v]
    proof
      let u,v;
      assume u ==> v; then
B1:   u =01=> v;
      given w such that
B2:   u =01=> w & w <=*= y;
      v <<01>> w by B1,B2; then
      v >>01<< w by A1; then
      consider u such that
B3:   v =01=> u & u <=01= w;
      thus P[v] by B2,B3,Lem11;
    end;
A5: for u,v st u =*=> v & P[u] holds P[v] from Star(A4);
    thus thesis by A5,A2,A3;
  end;

theorem
  X is DIAMOND & x <=01= y & y =*=> z implies
  ex u st x =*=> u & u <=01= z
  proof
    assume X is DIAMOND & x <=01= y & y =*=> z; then
    ex u st z =01=> u & u <=*= x by LemA;
    hence thesis;
  end;

registration
  cluster DIAMOND -> CONF for ARS;
  coherence
  proof let X;
    assume
A1: X is DIAMOND;
    let x,y;
    given z such that
A2: x <=*= z and
A3: z =*=> y;
    defpred P[Element of X] means x >><< $1;
A4: P[z] by A2,Lem17;
A5: for u,v st u ==> v & P[u] holds P[v]
    proof
      let u,v;
      assume
A6:   u ==> v;
      given w such that
A7:   x =*=> w & w <=*= u;
A8:   u =01=> v by A6;
      consider a such that
A9:   w =01=> a & a <=*= v by A1,A7,A8,LemA;
A10:  x =*=> a by A7,A9,Lem11;
      thus P[v] by A9,A10,DEF2;
    end;
    P[y] from Star1(A3,A4,A5);
    hence x >><< y;
  end;
end;

registration
  cluster DIAMOND -> CR for ARS;
  coherence
  proof let X;
    assume
A1: X is DIAMOND;
    let x,y;
    assume
A2: x <=*=> y;
    defpred P[Element of X] means x >><< $1;
A4: P[x];
A5: for u,v st u <==> v & P[u] holds P[v]
    proof
      let u,v;
      assume
A6:   u <==> v;
      given w such that
A7:   x =*=> w & w <=*= u;
      per cases by A6;
      suppose u ==> v; then
A8:     u =01=> v;
        consider a such that
A9:     w =01=> a & a <=*= v by A1,A7,A8,LemA;
A10:    x =*=> a by A7,A9,Lem11;
        thus P[v] by A9,A10,DEF2;
      end;
      suppose u <== v; then
A11:    v =*=> w by A7,Lem5;
        thus P[v] by A7,A11,DEF2;
      end;
    end;
    P[y] from Star2A(A2,A4,A5);
    hence x >><< y;
  end;
end;

registration
  cluster CR -> WCR for ARS;
  coherence
  proof let X;
    assume
A1: X is CR;
    let x,y;
    assume
A2: x <<01>> y;
A4: x <=*=> y by A2,Lem18,Lem19;
    thus x >><< y by A1,A4;
  end;
end;

registration
  cluster CR -> CONF for ARS;
  coherence by Lm1;
end;

registration
  cluster CONF -> CR for ARS;
  coherence
  proof let X;
    assume
A1: X is CONF;
    let x;
    defpred P[Element of X] means x >><< $1;
A3: for y,z st y <==> z & P[y] holds P[z]
    proof
      let y,z;
      assume
B1:   y <==> z & P[y];
      consider u such that
B2:   x =*=> u & u <=*= y by B1,DEF2;
      per cases by B1;
      suppose
B3:     y ==> z;
        y =*=> z by B3,Th2; then
        u <<>> z by B2;
        hence P[z] by A1,B2,Lm5;
      end;
      suppose
B5:     y <== z;
        thus P[z] by B1,B5,Th2,Lm5;
      end;
    end;
    for y,z st y <=*=> z & P[y] holds P[z] from Star2(A3);
    hence thesis;
  end;
end;

theorem
  X is non CONF WN implies
  ex x,y,z st y is_normform_of x & z is_normform_of x & y <> z
  proof
    given a,b such that
A1: a <<>> b  & not a >><< b;
    consider x such that
A0: a <=*= x & x =*=> b by A1;
    assume
A2: c is normalizable; then
    a is normalizable; then
    consider y such that
A3: y is_normform_of a;
    b is normalizable by A2; then
    consider z such that
A4: z is_normform_of b;
    take x,y,z;
    thus y is_normform_of x & z is_normform_of x by A0,A3,A4,LemN7;
    thus thesis by A1,A3,A4;
  end;

registration
::$N Newman's lemma
  cluster SN WCR -> CR for ARS;
  coherence
  proof let X;
    assume
A1: X is SN WCR;
    assume
A2: X is not CR;
A3: X is not CONF by A2;
    consider x1,x2 being Element of X such that
A4: x1 <<>> x2 & not x1 >><< x2 by A3;
    defpred P[Element of X] means
    ex x,y st x is_normform_of $1 & y is_normform_of $1 & x <> y;
A5: ex x st P[x]
    proof
      consider x such that
B1:   x1 <=*= x & x =*=> x2 by A4;
      take x;
      consider y1 being Element of X such that
B2:   y1 is_normform_of x1 by A1,ThWN1;
      consider y2 being Element of X such that
B3:   y2 is_normform_of x2 by A1,ThWN1;
      take y1,y2;
      thus y1 is_normform_of x by B1,B2,LemN7;
      thus y2 is_normform_of x by B1,B3,LemN7;
      assume
B4:   y1 = y2;
      thus contradiction by A4,B2,B3,B4;
    end;
A6: for x st P[x] ex y st P[y] & x ==> y
    proof
      let x;
      assume P[x]; then
      consider x1,x2 being Element of X such that
C1:   x1 is_normform_of x & x2 is_normform_of x & x1 <> x2;
      x =+=> x1 by C1,Lem21; then
      consider y1 being Element of X such that
C2:   x ==> y1 & y1 =*=> x1;
      x =+=> x2 by C1,Lem21; then
      consider y2 being Element of X such that
C3:   x ==> y2 & y2 =*=> x2;
      y1 >><< y2 by A1,C2,C3,Lm11; then
      consider y such that
C4:   y1 =*=> y & y <=*= y2;
      consider y0 being Element of X such that
C5:   y0 is_normform_of y by A1,ThWN1;
      per cases;
      suppose
D1:     y0 = x1;
        take y2;
D2:     y0 is_normform_of y2 by C4,C5,LemN7;
        x2 is_normform_of y2 by C1,C3;
        hence P[y2] by C1,D1,D2;
        thus x ==> y2 by C3;
      end;
      suppose
D3:     y0 <> x1;
        take y1;
D4:     y0 is_normform_of y1 by C4,C5,LemN7;
        x1 is_normform_of y1 by C1,C2;
        hence thesis by C2,D3,D4;
      end;
    end;
A7: X is not SN from notSN(A5,A6);
    thus contradiction by A1,A7;
  end;
end;

registration
  cluster CR -> N.F. for ARS;
  coherence
  proof let X;
    assume
A1: X is CR;
    let x,y;
    assume
A2: x is normform;
    assume
A3: x <=*=> y;
A4: x >><< y by A1,A3;
    consider z such that
A5: x =*=> z & z <=*= y by A4;
    thus y =*=> x by A2,A5,LemN1;
  end;
end;

registration
  cluster WN UN -> CR for ARS;
  coherence
  proof let X;
    assume
A1: X is WN;
    assume
A2: X is UN;
    let x,y;
    assume
A3: x <=*=> y;
A4: x is normalizable & y is normalizable by A1;
    consider u such that
A5: u is_normform_of x by A4;
    consider v such that
A6: v is_normform_of y by A4;
A7: u is normform & x =*=> u by A5;
    take u;
    thus x =*=> u by A5;
    u <=*=> x by A5,LemZ; then
    u <=*=> y & y <=*=> v by A3,A6,Th7,LemZ;
    hence y =*=> u by A2,A7,A6,Th7;
  end;
end;

registration
  cluster SN CR -> COMP for ARS;
  coherence;

  cluster COMP -> CR WCR N.F. UN UN* WN for ARS;
  coherence;
end;

theorem
  X is COMP implies
  for x,y st x <=*=> y holds nf x = nf y by Lem27;

registration
  cluster WN UN* -> CR for ARS;
  coherence;

  cluster SN UN* -> COMP for ARS;
  coherence;
end;

begin :: Term Rewriting Systems

definition
  struct(ARS,UAStr) TRSStr (#
    carrier -> set,
    charact -> PFuncFinSequence of the carrier,
    reduction -> Relation of the carrier
  #);
end;

registration
  cluster non empty non-empty strict for TRSStr;
  existence
  proof
    set S = the non empty set;
    set o = the non-empty non empty PFuncFinSequence of S;
    set r = the Relation of S;
    take X = TRSStr(#S, o, r#);
    thus the carrier of X is non empty;
    thus the charact of X <> {};
    thus thesis;
  end;
end;

definition
  let S be non empty UAStr;
  attr S is Group-like means
  Seg 3 c= dom the charact of S &
  for f being non empty homogeneous
    PartFunc of (the carrier of S)*, the carrier of S holds
  (f = (the charact of S).1 implies arity f = 0) &
  (f = (the charact of S).2 implies arity f = 1) &
  (f = (the charact of S).3 implies arity f = 2);
end;

theorem Th01:
  for X being non empty set
  for f1,f2,f3 being non empty homogeneous PartFunc of X*, X
   st arity f1 = 0 & arity f2 = 1 & arity f3 = 2
  for S being non empty UAStr
   st the carrier of S = X & <*f1,f2,f3*> c= the charact of S
  holds S is Group-like
  proof
    let X be non empty set;
    let f1,f2,f3 be non empty homogeneous PartFunc of X*, X;
    assume
01: arity f1 = 0;
    assume
02: arity f2 = 1;
    assume
03: arity f3 = 2;
    let S be non empty UAStr;
    assume
04: the carrier of S = X & <*f1,f2,f3*> c= the charact of S;
05: dom <*f1,f2,f3*> = Seg 3 by FINSEQ_2:124;
    hence Seg 3 c= dom the charact of S by 04,RELAT_1:11;
    let f be non empty homogeneous
    PartFunc of (the carrier of S)*, the carrier of S;
    1 in Seg 3 & 2 in Seg 3 & 3 in Seg 3 by FINSEQ_3:1,ENUMSET1:def 1; then
    (the charact of S).1 = <*f1,f2,f3*>.1 &
    (the charact of S).2 = <*f1,f2,f3*>.2 &
    (the charact of S).3 = <*f1,f2,f3*>.3 by 04,05,GRFUNC_1:2;
    hence (f = (the charact of S).1 implies arity f = 0) &
    (f = (the charact of S).2 implies arity f = 1) &
    (f = (the charact of S).3 implies arity f = 2) by 01,02,03,FINSEQ_1:45;
  end;

theorem Th02:
  for X being non empty set
  for f1,f2,f3 being non empty quasi_total homogeneous PartFunc of X*, X
  for S being non empty UAStr
   st the carrier of S = X & <*f1,f2,f3*> = the charact of S
  holds S is quasi_total partial
  proof
    let X be non empty set;
    let f1,f2,f3 be non empty quasi_total homogeneous PartFunc of X*, X;
    let S be non empty UAStr;
    assume
04: the carrier of S = X & <*f1,f2,f3*> = the charact of S;
    set A = the carrier of S;
    thus S is quasi_total
    proof
      let i be Nat, h being PartFunc of A*,A;
      assume i in dom the charact of S; then
      i in Seg 3 by 04,FINSEQ_1:89; then
      i = 1 or i = 2 or i = 3 by FINSEQ_3:1,ENUMSET1:def 1;
      hence thesis by 04,FINSEQ_1:45;
    end;
    let i be Nat, h being PartFunc of A*,A;
    assume i in dom the charact of S; then
    i in Seg 3 by 04,FINSEQ_1:89; then
    i = 1 or i = 2 or i = 3 by FINSEQ_3:1,ENUMSET1:def 1;
    hence thesis by 04,FINSEQ_1:45;
  end;

definition
  let S be non empty non-empty UAStr;
  let o be operation of S;
  let a be Element of dom o;
  redefine func o.a -> Element of S;
  coherence
  proof
    o in rng the charact of S; then
    o <> {} & o in PFuncs((the carrier of S)*, the carrier of S)
    by RELAT_1:def 9; then
    o.a in rng o & rng o c= the carrier of S by RELAT_1:def 19,FUNCT_1:3;
    hence thesis;
  end;
end;

registration
  let S be non empty non-empty UAStr;
  cluster -> non empty for operation of S;
  coherence by RELAT_1:def 9;
  let o be operation of S;
  cluster -> Relation-like Function-like for Element of dom o;
  coherence
  proof
    let a be Element of dom o;
    a in dom o & dom o c= (the carrier of S)*; then
    a is Element of (the carrier of S)*;
    hence thesis;
  end;
end;

registration
  let S be partial non empty non-empty UAStr;
  cluster -> homogeneous for operation of S;
  coherence
  proof
    let o be operation of S;
    consider i being object such that
A1: i in dom the charact of S & o = (the charact of S).i by FUNCT_1:def 3;
    thus thesis by A1;
  end;
end;

registration
  let S be quasi_total non empty non-empty UAStr;
  cluster -> quasi_total for operation of S;
  coherence
  proof
    let o be operation of S;
    consider i being object such that
A1: i in dom the charact of S & o = (the charact of S).i by FUNCT_1:def 3;
    thus thesis by A1,MARGREL1:def 24;
  end;
end;

theorem ThA:
  for S being non empty non-empty UAStr st S is Group-like
  holds
    1 is OperSymbol of S & 2 is OperSymbol of S & 3 is OperSymbol of S
    proof
      let S be non empty non-empty UAStr;
      assume
A0:   Seg 3 c= dom the charact of S;
      1 in Seg 3 & 2 in Seg 3 & 3 in Seg 3 by FINSEQ_3:1,ENUMSET1:def 1;
      hence thesis by A0;
    end;

theorem ThB:
  for S being partial non empty non-empty UAStr st S is Group-like
  holds
    arity Den(In(1, dom the charact of S), S) = 0 &
    arity Den(In(2, dom the charact of S), S) = 1 &
    arity Den(In(3, dom the charact of S), S) = 2
  proof
    let S be partial non empty non-empty UAStr;
    assume
A1: S is Group-like; then
    1 is OperSymbol of S & 2 is OperSymbol of S & 3 is OperSymbol of S
    by ThA; then
    In(1, dom the charact of S) = 1 &
    In(2, dom the charact of S) = 2 &
    In(3, dom the charact of S) = 3;
    hence thesis by A1,PUA2MSS1:def 1;
  end;

definition
  let S be non empty non-empty TRSStr;
  attr S is invariant means:
DEF2:
  for o being OperSymbol of S
  for a,b being Element of dom Den(o,S)
  for i being Nat st i in dom a
  for x,y being Element of S
  st x = a.i & b = a+*(i,y) & x ==> y
  holds Den(o,S).a ==> Den(o,S).b;
end;

definition
  let S be non empty non-empty TRSStr;
  attr S is compatible means
  for o being OperSymbol of S
  for a,b being Element of dom Den(o,S)
  st for i being Nat st i in dom a holds
     for x,y being Element of S st x = a.i & y = b.i holds x ==> y
  holds Den(o,S).a =*=> Den(o,S).b;
end;

theorem Th0:
  for n being natural number, X being non empty set, x being Element of X
  ex f being non empty homogeneous quasi_total PartFunc of X*, X st
  arity f = n & f = (n-tuples_on X) --> x
  proof
    let n be natural number, X be non empty set;
    let x be Element of X;
    set f = (n-tuples_on X) --> x;
A1: dom f = n-tuples_on X & rng f = {x} & n in omega
    by FUNCOP_1:8,ORDINAL1:def 12; then
    dom f c= X* & rng f c= X by ZFMISC_1:31,FINSEQ_2:134; then
    reconsider f as non empty PartFunc of X*, X by RELSET_1:4;
A2: f is quasi_total
    proof
      let x,y be FinSequence of X; assume
      len x = len y & x in dom f; then
      len x = n & len y = n by A1,FINSEQ_2:132;
      hence thesis by FINSEQ_2:133;
    end;
    f is homogeneous
    proof
      let x,y be FinSequence; assume
      x in dom f & y in dom f; then
      reconsider x,y as Element of n-tuples_on X;
      len x = n & len y = n by A1,FINSEQ_2:132;
      hence thesis;
    end; then
    reconsider f as non empty homogeneous quasi_total PartFunc of X*, X by A2;
    take f;
    set y = the Element of n-tuples_on X;
A3: for x being FinSequence st x in dom f holds n = len x by A1,FINSEQ_2:132;
    y in dom f;
    hence arity f = n by A3,MARGREL1:def 25;
    thus thesis;
  end;

registration
  let X be non empty set;
  let O be PFuncFinSequence of X;
  let r be Relation of X;
  cluster TRSStr(#X, O, r#) -> non empty;
  coherence;
end;

registration
  let X be non empty set;
  let O be non empty non-empty PFuncFinSequence of X;
  let r be Relation of X;
  cluster TRSStr(#X, O, r#) -> non-empty;
  coherence
  proof
    thus the charact of TRSStr(#X, O, r#) <> {};
    thus the charact of TRSStr(#X, O, r#) is non-empty;
  end;
end;

definition
  let X be non empty set;
  let x be Element of X;
  func TotalTRS(X,x) -> non empty non-empty strict TRSStr means:
DEF3:
  the carrier of it = X &
  the charact of it =
  <*(0-tuples_on X)-->x, (1-tuples_on X)-->x, (2-tuples_on X)-->x*> &
  the reduction of it = nabla X;
  uniqueness;
  existence
  proof
    consider f0 being non empty homogeneous quasi_total PartFunc of X*, X
    such that
A0: arity f0 = 0 & f0 = (0-tuples_on X) --> x by Th0;
    consider f1 being non empty homogeneous quasi_total PartFunc of X*, X
    such that
A1: arity f1 = 1 & f1 = (1-tuples_on X) --> x by Th0;
    consider f2 being non empty homogeneous quasi_total PartFunc of X*, X
    such that
A2: arity f2 = 2 & f2 = (2-tuples_on X) --> x by Th0;
    set r = nabla X;
    reconsider a = f0, b = f1, c = f2 as Element of PFuncs(X*, X)
    by PARTFUN1:45;
    reconsider O = <*a,b,c*> as non empty non-empty PFuncFinSequence of X;
    take S = TRSStr(#X, O, r#);
    thus thesis by A0,A1,A2;
  end;
end;

registration
  let X be non empty set;
  let x be Element of X;
  cluster TotalTRS(X,x) -> quasi_total partial Group-like invariant;
  coherence
  proof set S = TotalTRS(X,x);
A3: the carrier of S = X & the charact of S =
    <*(0-tuples_on X)-->x, (1-tuples_on X)-->x, (2-tuples_on X)-->x*> &
    the reduction of S = nabla X by DEF3;
    consider f0 being non empty homogeneous quasi_total PartFunc of X*, X
    such that
A0: arity f0 = 0 & f0 = (0-tuples_on X) --> x by Th0;
    consider f1 being non empty homogeneous quasi_total PartFunc of X*, X
    such that
A1: arity f1 = 1 & f1 = (1-tuples_on X) --> x by Th0;
    consider f2 being non empty homogeneous quasi_total PartFunc of X*, X
    such that
A2: arity f2 = 2 & f2 = (2-tuples_on X) --> x by Th0;
    [:X,X:] c= [:X,X:]; then
    reconsider r = [:X,X:] as Relation of X;
    reconsider a = f0, b = f1, c = f2 as Element of PFuncs(X*, X)
    by PARTFUN1:45;
    thus S is quasi_total partial Group-like by A0,A1,A2,A3,Th01,Th02;
    let o be OperSymbol of S;
    let a,b be Element of dom Den(o,S);
    let i be Nat such that i in dom a;
    let x,y be Element of S such that x = a.i & b = a+*(i,y) & x ==> y;
    thus [Den(o,S).a,Den(o,S).b] in the reduction of S by A3,ZFMISC_1:87;
  end;
end;

registration
  cluster strict quasi_total partial Group-like invariant for
  non empty non-empty TRSStr;
  existence
  proof
    take TotalTRS(NAT,In(0,NAT));
    thus thesis;
  end;
end;

definition
  let S be Group-like quasi_total partial non empty non-empty TRSStr;
  func 1.S -> Element of S equals
     Den(In(1,dom the charact of S), S).{};
  coherence
  proof
    arity Den(In(1,dom the charact of S), S) = 0 by ThB; then
    dom Den(In(1,dom the charact of S), S) = 0-tuples_on the carrier of S
    by COMPUT_1:22 .= {{}} by COMPUT_1:5; then
    {} in dom Den(In(1,dom the charact of S), S) by TARSKI:def 1;
    hence thesis by FUNCT_1:102;
  end;
  let a be Element of S;
  func a " -> Element of S equals
     Den(In(2,dom the charact of S), S).<*a*>;
  coherence
  proof
    arity Den(In(2,dom the charact of S), S) = 1 by ThB; then
    dom Den(In(2,dom the charact of S), S) = 1-tuples_on the carrier of S &
    <*a*> is Element of 1-tuples_on the carrier of S
    by FINSEQ_2:98,MARGREL1:22;
    hence thesis by FUNCT_1:102;
  end;
  let b be Element of S;
  func a * b -> Element of S equals
     Den(In(3,dom the charact of S), S).<*a,b*>;
  coherence
  proof
    arity Den(In(3,dom the charact of S), S) = 2 by ThB; then
    dom Den(In(3,dom the charact of S), S) = 2-tuples_on the carrier of S &
    <*a,b*> is Element of 2-tuples_on the carrier of S
    by FINSEQ_2:101,MARGREL1:22;
    hence thesis by FUNCT_1:102;
  end;
end;

reserve
  S for Group-like quasi_total partial invariant non empty non-empty TRSStr;
reserve a,b,c for Element of S;

theorem
  a ==> b implies a" ==> b"
  proof
    assume
A0: a ==> b;
    set o = In(2, dom the charact of S);
    arity Den(o, S) = 1 by ThB; then
    dom Den(o, S) = 1-tuples_on the carrier of S by MARGREL1:22; then
    reconsider aa = <*a*>, bb = <*b*> as Element of dom Den(o, S)
    by FINSEQ_2:98;
A2: dom <*a*> = Seg 1 & 1 in Seg 1 by FINSEQ_1:1,38;
A3: <*a*>.1 = a by FINSEQ_1:40;
    <*a*>+*(1,b) = <*b*> by FUNCT_7:95; then
    Den(o,S).aa ==> Den(o,S).bb by A0,A2,A3,DEF2;
    hence a" ==> b";
  end;

theorem ThI2:
  a ==> b implies a*c ==> b*c
  proof
    assume
A0: a ==> b;
    set o = In(3, dom the charact of S);
    arity Den(o, S) = 2 by ThB; then
    dom Den(o, S) = 2-tuples_on the carrier of S by MARGREL1:22; then
    reconsider ac = <*a,c*>, bc = <*b,c*> as Element of dom Den(o, S)
    by FINSEQ_2:101;
A2: dom <*a,c*> = Seg 2 & 1 in Seg 2 by FINSEQ_1:1,89;
A3: <*a,c*>.1 = a by FINSEQ_1:44;
    <*a,c*>+*(1,b) = <*b,c*> by COMPUT_1:1; then
    Den(o,S).ac ==> Den(o,S).bc by A0,A2,A3,DEF2;
    hence a*c ==> b*c;
  end;

theorem ThI3:
  a ==> b implies c*a ==> c*b
  proof
    assume
A0: a ==> b;
    set o = In(3, dom the charact of S);
    arity Den(o, S) = 2 by ThB; then
    dom Den(o, S) = 2-tuples_on the carrier of S by MARGREL1:22; then
    reconsider ac = <*c,a*>, bc = <*c,b*> as Element of dom Den(o, S)
    by FINSEQ_2:101;
A2: dom <*c,a*> = Seg 2 & 2 in Seg 2 by FINSEQ_1:1,89;
A3: <*c,a*>.2 = a by FINSEQ_1:44;
    <*c,a*>+*(2,b) = <*c,b*> by COMPUT_1:1; then
    Den(o,S).ac ==> Den(o,S).bc by A0,A2,A3,DEF2;
    hence c*a ==> c*b;
  end;

begin :: An Execution of Knuth-Bendix Algorithm

reserve S for Group-like quasi_total partial non empty non-empty TRSStr;
reserve a,b,c for Element of S;

definition
  let S;
  attr S is (R1) means
   1.S * a ==> a;
  attr S is (R2) means
   a" * a ==> 1.S;
  attr S is (R3) means
   (a * b) * c ==> a * (b * c);
  attr S is (R4) means
   a" * (a * b) ==> b;
  attr S is (R5) means
   (1.S)" * a ==> a;
  attr S is (R6) means
   (a")" * 1.S ==> a;
  attr S is (R7) means
   (a")" * b ==> a * b;
  attr S is (R8) means
   a * 1.S ==> a;
  attr S is (R9) means
   (a")" ==> a;
  attr S is (R10) means
   (1.S)" ==> 1.S;
  attr S is (R11) means
   a * (a") ==> 1.S;
  attr S is (R12) means
   a * (a" * b) ==> b;
  attr S is (R13) means
   a * (b * (a * b)") ==> 1.S;
  attr S is (R14) means
   a * (b * a)" ==> b";
  attr S is (R15) means
   (a * b)" ==> b" * a";
end;

reserve
  S for Group-like quasi_total partial invariant non empty non-empty TRSStr,
  a,b,c for Element of S;

theorem
  S is (R1) (R2) (R3) implies a" * (a * b) <<>> b
  proof
    assume
A1: S is (R1) (R2) (R3);
    take (a"*a)*b;
    thus (a"*a)*b =*=> a"*(a*b) by A1,Th2;
    (a"*a)*b ==> 1.S * b & 1.S * b ==> b by A1,ThI2; then
    (a"*a)*b =*=> 1.S * b & 1.S * b =*=> b by Th2;
    hence (a"*a)*b =*=> b by Th3;
  end;

theorem
  S is (R1) (R4) implies (1.S)" * a <<>> a
  proof
    assume
A1: S is (R1) (R4);
    take (1.S)"*(1.S*a);
    1.S*a ==> a by A1;
    hence (1.S)"*(1.S*a) =*=> (1.S)" * a by Th2,ThI3;
    thus thesis by A1,Th2;
  end;

theorem
  S is (R2) (R4) implies (a")" * 1.S <<>> a
  proof
    assume
A1: S is (R2) (R4);
    take (a")" * (a" * a);
    a" * a ==> 1.S by A1;
    hence (a")" * (a" * a) =*=> (a")" * 1.S by Th2,ThI3;
    thus (a")" * (a" * a) =*=> a by A1,Th2;
  end;

theorem
  S is (R1) (R3) (R6) implies (a")" * b <<>> a * b
  proof
    assume
A1: S is (R1) (R3) (R6);
    take (a""*1.S)*b;
A2: (a""*1.S)*b =*=> a""*(1.S*b) by A1,Th2;
    1.S*b ==> b by A1; then
    a""*(1.S*b) =*=> a""*b by Th2,ThI3;
    hence (a""*1.S)*b =*=> a""*b by A2,Th3;
    a"" * 1.S ==> a by A1;
    hence (a"" * 1.S) * b =*=> a * b by Th2,ThI2;
  end;

theorem
  S is (R6) (R7) implies a * 1.S <<>> a
  proof
    assume
A1: S is (R6) (R7);
    take a""*1.S;
    thus a""*1.S =*=> a*1.S by A1,Th2;
    thus a"" * 1.S =*=> a by A1,Th2;
  end;

theorem
  S is (R6) (R8) implies (a")" <<>> a
  proof
    assume
A1: S is (R6) (R8);
    take a""*1.S;
    thus a""*1.S =*=> a"" by A1,Th2;
    thus a"" * 1.S =*=> a by A1,Th2;
  end;

theorem
  S is (R5) (R8) implies (1.S)" <<>> 1.S
  proof
    assume
A1: S is (R5) (R8);
    take (1.S)"*1.S;
    thus (1.S)"*1.S =*=> (1.S)" by A1,Th2;
    thus (1.S)" * 1.S =*=> 1.S by A1,Th2;
  end;

theorem
  S is (R2) (R9) implies a * (a") <<>> 1.S
  proof
    assume
A1: S is (R2) (R9);
    take a""*a";
    a"" ==> a by A1;
    hence a""*a" =*=> a*a" by Th2,ThI2;
    thus a""*a" =*=> 1.S by A1,Th2;
  end;

theorem
  S is (R1) (R3) (R11) implies a * (a" * b) <<>> b
  proof
    assume
A1: S is (R1) (R3) (R11);
    take (a * a") * b;
    thus (a * a") * b =*=> a * (a" * b) by A1,Th2;
    (a * a") * b ==> 1.S * b & 1.S * b ==> b by A1,ThI2;
    hence (a * a") * b =*=> b by Lem3;
  end;

theorem
  S is (R3) (R11) implies a * (b * (a * b)") <<>> 1.S
  proof
    assume
A1: S is (R3) (R11);
    take (a * b) * (a * b)";
    thus (a * b) * (a * b)" =*=> a * (b * (a * b)") by A1,Th2;
    thus (a * b) * (a * b)" =*=> 1.S by A1,Th2;
  end;

theorem
  S is (R4) (R8) (R13) implies a * (b * a)" <<>> b"
  proof
    assume
A1: S is (R4) (R8) (R13);
    take b"*(b*(a*(b*a)"));
    thus b"*(b*(a*(b*a)")) =*=> a*(b*a)" by A1,Th2;
    b"*(b*(a*(b*a)")) ==> b"*1.S & b"*1.S ==> b" by A1,ThI3;
    hence b"*(b*(a*(b*a)")) =*=> b" by Lem3;
  end;

theorem
  S is (R4) (R14) implies (a * b)" <<>> b" * a"
  proof
    assume
A1: S is (R4) (R14);
    take b"*(b*(a*b)");
    thus b"*(b*(a*b)") =*=> (a * b)" by A1,Th2;
    (b*(a*b)") ==> a" by A1;
    hence b"*(b*(a*b)") =*=> b" * a" by Th2,ThI3;
  end;

theorem
  S is (R1) (R10) implies (1.S)" * a =*=> a
  proof
    assume
A1: S is (R1) (R10);
    (1.S)"*a ==> 1.S*a & 1.S*a ==> a by A1,ThI2;
    hence (1.S)" * a =*=> a by Lem3;
  end;

theorem
  S is (R8) (R9) implies (a")" * 1.S =*=> a
  proof
    assume S is (R8) (R9); then
    (a")" * 1.S ==> a"" & a"" ==> a;
    hence (a")" * 1.S =*=> a by Lem3;
  end;

theorem
  S is (R9) implies (a")" * b =*=> a * b
  proof
    assume S is (R9); then
    a"" ==> a;
    hence (a")" * b =*=> a * b by Th2,ThI2;
  end;

theorem
  S is (R11) (R14) implies a * (b * (a * b)") =*=> 1.S
  proof
    assume
A1: S is (R11) (R14);
    a * (b * (a * b)") ==> a*a" & a*a" ==> 1.S by A1,ThI3;
    hence a * (b * (a * b)") =*=> 1.S by Lem3;
  end;

theorem
  S is (R12) (R15) implies a * (b * a)" =*=> b"
  proof
    assume
A1: S is (R12) (R15);
    a * (b * a)" ==> a*(a"*b") & a*(a"*b") ==> b" by A1,ThI3;
    hence a * (b * a)" =*=> b" by Lem3;
  end;