File: algolycee.html

package info (click to toggle)
giac 1.6.0.41%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 64,540 kB
  • sloc: cpp: 351,842; ansic: 105,138; python: 30,545; javascript: 8,675; yacc: 2,690; lex: 2,449; makefile: 1,243; sh: 579; perl: 314; lisp: 216; asm: 62; java: 41; sed: 16; csh: 7; pascal: 6
file content (9820 lines) | stat: -rw-r--r-- 885,904 bytes parent folder | download | duplicates (4)
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
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
<!DOCTYPE html>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="generator" content="hevea 2.29+5 of 2017-05-18">
<style type="text/css">
.li-itemize{margin:1ex 0ex;}
.li-enumerate{margin:1ex 0ex;}
.dd-description{margin:0ex 0ex 1ex 4ex;}
.dt-description{margin:0ex;}
.toc{list-style:none;}
.footnotetext{margin:0ex; padding:0ex;}
div.footnotetext P{margin:0px; text-indent:1em;}
.thefootnotes{text-align:left;margin:0ex;}
.dt-thefootnotes{margin:0em;}
.dd-thefootnotes{margin:0em 0em 0em 2em;}
.footnoterule{margin:1em auto 1em 0px;width:50%;}
.caption{padding-left:2ex; padding-right:2ex; margin-left:auto; margin-right:auto}
.title{margin:2ex auto;text-align:center}
.titlemain{margin:1ex 2ex 2ex 1ex;}
.titlerest{margin:0ex 2ex;}
.center{text-align:center;margin-left:auto;margin-right:auto;}
.flushleft{text-align:left;margin-left:0ex;margin-right:auto;}
.flushright{text-align:right;margin-left:auto;margin-right:0ex;}
div table{margin-left:inherit;margin-right:inherit;margin-bottom:2px;margin-top:2px}
td table{margin:auto;}
table{border-collapse:collapse;}
td{padding:0;}
.cellpadding0 tr td{padding:0;}
.cellpadding1 tr td{padding:1px;}
pre{text-align:left;margin-left:0ex;margin-right:auto;}
blockquote{margin-left:4ex;margin-right:4ex;text-align:left;}
td p{margin:0px;}
.boxed{border:1px solid black}
.textboxed{border:1px solid black}
.vbar{border:none;width:2px;background-color:black;}
.hbar{border:none;height:2px;width:100%;background-color:black;}
.hfill{border:none;height:1px;width:200%;background-color:black;}
.vdisplay{border-collapse:separate;border-spacing:2px;width:auto; empty-cells:show; border:2px solid red;}
.vdcell{white-space:nowrap;padding:0px; border:2px solid green;}
.display{border-collapse:separate;border-spacing:2px;width:auto; border:none;}
.dcell{white-space:nowrap;padding:0px; border:none;}
.dcenter{margin:0ex auto;}
.vdcenter{border:solid #FF8000 2px; margin:0ex auto;}
.minipage{text-align:left; margin-left:0em; margin-right:auto;}
.marginpar{border:solid thin black; width:20%; text-align:left;}
.marginparleft{float:left; margin-left:0ex; margin-right:1ex;}
.marginparright{float:right; margin-left:1ex; margin-right:0ex;}
.theorem{text-align:left;margin:1ex auto 1ex 0ex;}
.part{margin:2ex auto;text-align:center}
.lstlisting{font-family:monospace;white-space:pre;margin-right:auto;margin-left:0pt;text-align:left}
</style>
<script language="javascript"> 
var ua = window.navigator.userAgent;  
var old_ie = ua.indexOf('MSIE ');  
var new_ie = ua.indexOf('Trident/');  
if ((old_ie > -1) || (new_ie > -1) || Boolean(window.chrome)){
 (function () {
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src  = "file:///usr/share/javascript/mathjax/MathJax.js?config=TeX-MML-AM_CHTML";
  document.getElementsByTagName("head")[0].appendChild(script);
})();
}
</script>
<title>Algorithmique et programmation au Lycée
</title>
</head>
<body >
<!--HEVEA command line is: hevea -fix algolycee.tex -->
<!--CUT STYLE book--><!--CUT DEF chapter 1 --><p>


<div>
<div id="maindiv" style="max-height: 500px; overflow:auto">


</p><table class="title"><tr><td style="padding:1ex"><h1 class="titlemain">Algorithmique et programmation au Lycée</h1><h3 class="titlerest">Renée De Graeve   Bernard Parisse</h3></td></tr>
</table><!--TOC chapter id="sec1" Table des matières-->
<h1 id="sec1" class="chapter">Table des matières</h1><!--SEC END --><ul class="toc"><li class="li-toc">
<a href="#sec3">Chapitre 1  Introduction</a>
<ul class="toc"><li class="li-toc">
<a href="#sec4">1.1  Apprendre en programmant.</a>
</li><li class="li-toc"><a href="#sec5">1.2  Le choix du langage de programmation</a>
</li><li class="li-toc"><a href="#sec6">1.3  Structure du document</a>
</li></ul>
</li><li class="li-toc"><a href="#sec7">Chapitre 2  Types, fonctions</a>
<ul class="toc"><li class="li-toc">
<a href="#sec8">2.1  Types</a>
<ul class="toc"><li class="li-toc">
<a href="#sec9">2.1.1  Entiers, rationnels, réels, complexes et les nombres approchés.</a>
</li><li class="li-toc"><a href="#sec10">2.1.2  Les listes, les séquences et les chaînes de caractères</a>
</li><li class="li-toc"><a href="#sec17">2.1.3  Les instructions sur les listes les séquences et les chaînes de caractères</a>
</li><li class="li-toc"><a href="#sec18">2.1.4  Les booléens</a>
</li><li class="li-toc"><a href="#sec24">2.1.5  Expressions, polynômes</a>
</li><li class="li-toc"><a href="#sec28">2.1.6  Connaître les types et les sous-types</a>
</li></ul>
</li><li class="li-toc"><a href="#sec29">2.2  Les fonctions</a>
<ul class="toc"><li class="li-toc">
<a href="#sec30">2.2.1  Quelques fonctions algébriques de <span style="font-family:monospace">Xcas</span></a>
</li><li class="li-toc"><a href="#sec31">2.2.2  Quelques fonctions aléatoires de <span style="font-family:monospace">Xcas</span></a>
</li><li class="li-toc"><a href="#sec32">2.2.3  Définition d’une fonction algébrique d’une variable</a>
</li><li class="li-toc"><a href="#sec33">2.2.4  Définition d’une fonction algébrique de 2 variables</a>
</li><li class="li-toc"><a href="#sec34">2.2.5  Définition d’une fonction algébrique 
sans lui donner un nom</a>
</li><li class="li-toc"><a href="#sec35">2.2.6  Définition d’une fonction algébrique par morceaux avec <span style="font-family:monospace">quand</span></a>
</li></ul>
</li></ul>
</li><li class="li-toc"><a href="#sec36">Chapitre 3  Les instructions de programmation sur des exemples</a>
<ul class="toc"><li class="li-toc">
<a href="#sec37">3.1  Commentaires et documentation.</a>
<ul class="toc"><li class="li-toc">
<a href="#sec38">3.1.1  Les commentaires dans un programme.</a>
</li><li class="li-toc"><a href="#sec39">3.1.2  Documenter une fonction avec la commande <span style="font-family:monospace">help</span></a>
</li></ul>
</li><li class="li-toc"><a href="#sec40">3.2  Stocker une valeur dans une variable avec <span style="font-family:monospace">:=</span></a>
</li><li class="li-toc"><a href="#sec41">3.3  Enlever une valeur stockée dans une variable avec <span style="font-family:monospace">purge</span></a>
</li><li class="li-toc"><a href="#sec42">3.4  Suite d’instructions avec <span style="font-family:monospace">;</span> ou <span style="font-family:monospace">:;</span></a>
</li><li class="li-toc"><a href="#sec43">3.5  L’instruction <span style="font-family:monospace">retourne</span> ou <span style="font-family:monospace">return</span></a>
</li><li class="li-toc"><a href="#sec44">3.6  L’instruction <span style="font-family:monospace">local</span></a>
</li><li class="li-toc"><a href="#sec45">3.7  L’instruction <span style="font-family:monospace">pour</span></a>
</li><li class="li-toc"><a href="#sec46">3.8  L’instruction <span style="font-family:monospace">pour</span> avec un <span style="font-family:monospace">pas</span></a>
</li><li class="li-toc"><a href="#sec47">3.9  L’instruction <span style="font-family:monospace">si</span></a>
</li><li class="li-toc"><a href="#sec48">3.10  Utiliser une fonction utilisateur dans un programme</a>
</li><li class="li-toc"><a href="#sec49">3.11  L’instruction <span style="font-family:monospace">tantque</span></a>
</li><li class="li-toc"><a href="#sec50">3.12  Un exercice et un problème</a>
<ul class="toc"><li class="li-toc">
<a href="#sec51">3.12.1  Exercice</a>
</li><li class="li-toc"><a href="#sec52">3.12.2  Problème : le crible d’Eratosthène</a>
</li><li class="li-toc"><a href="#sec53">3.12.3  Description</a>
</li><li class="li-toc"><a href="#sec54">3.12.4  Écriture de l’algorithme</a>
</li><li class="li-toc"><a href="#sec55">3.12.5  En syntaxe <span style="font-family:monospace">Xcas</span></a>
</li><li class="li-toc"><a href="#sec58">3.12.6  En syntaxe Python</a>
</li></ul>
</li><li class="li-toc"><a href="#sec61">3.13  Autre exemple de boucle <span style="font-family:monospace">tantque</span> : le ticket de caisse</a>
</li><li class="li-toc"><a href="#sec62">3.14  Interruption d’une boucle</a>
</li><li class="li-toc"><a href="#sec63">3.15  Autre exemple de boucle <span style="font-family:monospace">tantque</span> : le ticket de caisse</a>
</li><li class="li-toc"><a href="#sec64">3.16  Encore un exemple de boucle <span style="font-family:monospace">tantque</span> : le ticket de caisse</a>
</li><li class="li-toc"><a href="#sec65">3.17  Exercice : Algorithme de tracé de courbe</a>
</li><li class="li-toc"><a href="#sec66">3.18  Mettre au point un programme</a>
</li></ul>
</li><li class="li-toc"><a href="#sec67">Chapitre 4  Résolution d’équations</a>
<ul class="toc"><li class="li-toc">
<a href="#sec68">4.1  Encadrer une racine d’une équation par dichotomie</a>
</li><li class="li-toc"><a href="#sec69">4.2  Résoudre dans <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Ropf;</mi></mrow><annotation encoding='application/x-tex'>\mathbb{R}</annotation></semantics></math> une équation se ramenant au premier degré ou au degré 2</a>
</li><li class="li-toc"><a href="#sec70">4.3  Résoudre un système de deux équations du premier degré à deux inconnues.</a>
</li></ul>
</li><li class="li-toc"><a href="#sec71">Chapitre 5  Les figures en géométrie plane avec <span style="font-family:monospace">Xcas</span></a>
<ul class="toc"><li class="li-toc">
<a href="#sec72">5.1  Le point : <span style="font-family:monospace">point</span> et le segment : <span style="font-family:monospace">segment</span></a>
</li><li class="li-toc"><a href="#sec73">5.2  Les coordonnées d’un point : <span style="font-family:monospace">coordonnees</span></a>
</li><li class="li-toc"><a href="#sec74">5.3  La droite et son équation : <span style="font-family:monospace">droite</span> et <span style="font-family:monospace">equation</span></a>
</li><li class="li-toc"><a href="#sec75">5.4  Ligne brisée : <span style="font-family:monospace">polygone_ouvert</span></a>
</li><li class="li-toc"><a href="#sec76">5.5  Les polygones : <span style="font-family:monospace">triangle, carre, polygone</span></a>
</li><li class="li-toc"><a href="#sec77">5.6  Le cercle et son équation : <span style="font-family:monospace">cercle</span> et <span style="font-family:monospace">equation</span></a>
</li><li class="li-toc"><a href="#sec78">5.7  Les tangentes à un cercle passant par un point et leurs équations</a>
</li><li class="li-toc"><a href="#sec79">5.8  Exercice : les lunules d’Hippocrate</a>
<ul class="toc"><li class="li-toc">
<a href="#sec80">5.8.1  Exercice 1</a>
</li><li class="li-toc"><a href="#sec81">5.8.2  Exercice 2</a>
</li><li class="li-toc"><a href="#sec82">5.8.3  Exercice 3</a>
</li><li class="li-toc"><a href="#sec83">5.8.4  Exercice 4</a>
</li></ul>
</li></ul>
</li><li class="li-toc"><a href="#sec84">Chapitre 6  La géométrie analytique</a>
<ul class="toc"><li class="li-toc">
<a href="#sec85">6.1  Les segments</a>
<ul class="toc"><li class="li-toc">
<a href="#sec86">6.1.1  Calculer la distance de deux points connaissant leurs coordonnées</a>
</li><li class="li-toc"><a href="#sec87">6.1.2  Calculer les coordonnées du milieu d’un segment</a>
</li></ul>
</li><li class="li-toc"><a href="#sec88">6.2  Les droites</a>
<ul class="toc"><li class="li-toc">
<a href="#sec89">6.2.1  Équation d’une droite définie par 2 points ou par sa pente et un point</a>
</li><li class="li-toc"><a href="#sec90">6.2.2  Coefficients (a,b,c) de la droite d’équation ax+by+c=0</a>
</li><li class="li-toc"><a href="#sec91">6.2.3  Point d’intersection de 2 droites sécantes</a>
</li></ul>
</li><li class="li-toc"><a href="#sec92">6.3  Triangles et quadrilatères définis par les coordonnées des sommets</a>
</li><li class="li-toc"><a href="#sec93">6.4  Les vecteurs</a>
<ul class="toc"><li class="li-toc">
<a href="#sec94">6.4.1  Les coordonnées d’un vecteur défini par 2 points</a>
</li><li class="li-toc"><a href="#sec95">6.4.2  Calculer les coordonnées de la somme de deux vecteurs dans un repère</a>
</li><li class="li-toc"><a href="#sec96">6.4.3  Coordonnées de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>D</mi></mrow><annotation encoding='application/x-tex'>D</annotation></semantics></math> extrémité du vecteur 
d’origine <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> équipollent au vecteur <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>AB</annotation></semantics></math></a>
</li><li class="li-toc"><a href="#sec97">6.4.4  Norme d’un vecteur</a>
</li></ul>
</li><li class="li-toc"><a href="#sec98">6.5  Changement de repères</a>
<ul class="toc"><li class="li-toc">
<a href="#sec99">6.5.1  Le problème</a>
</li><li class="li-toc"><a href="#sec100">6.5.2  Le programme <span style="font-family:monospace">Changexy2XY(cM,cI,cU)</span></a>
</li><li class="li-toc"><a href="#sec101">6.5.3  Le programme <span style="font-family:monospace">ChangeXY2xy(CM,cI,cU)</span></a>
</li><li class="li-toc"><a href="#sec102">6.5.4  Exercices</a>
</li></ul>
</li><li class="li-toc"><a href="#sec103">6.6  Cercles, Tangentes à un cercle</a>
<ul class="toc"><li class="li-toc">
<a href="#sec104">6.6.1  Équation d’un cercle défini par son centre et son rayon</a>
</li><li class="li-toc"><a href="#sec105">6.6.2  Équation d’un cercle défini par son diamètre</a>
</li><li class="li-toc"><a href="#sec106">6.6.3  Équation d’un cercle défini par son centre et son rayon ou par son diamètre</a>
</li><li class="li-toc"><a href="#sec107">6.6.4  Centre et rayon d’un cercle donné par son équation</a>
</li><li class="li-toc"><a href="#sec108">6.6.5  Construire la tangente à un cercle en l’un de ses points</a>
</li><li class="li-toc"><a href="#sec109">6.6.6  Construire les tangentes à un cercle passant par un point</a>
</li><li class="li-toc"><a href="#sec112">6.6.7  Solution analytique des tangentes à un cercle</a>
</li></ul>
</li></ul>
</li><li class="li-toc"><a href="#sec113">Chapitre 7  Quelques tests géométriques</a>
<ul class="toc"><li class="li-toc">
<a href="#sec114">7.1  Test d’alignement de 3 points</a>
</li><li class="li-toc"><a href="#sec115">7.2  Test de parallélisme de 2 droites</a>
</li><li class="li-toc"><a href="#sec116">7.3  Caractériser alignement et parallélisme par la colinéarité</a>
</li></ul>
</li><li class="li-toc"><a href="#sec117">Chapitre 8  Statistiques</a>
<ul class="toc"><li class="li-toc">
<a href="#sec118">8.1  Calcul de moyenne et écart-type</a>
</li><li class="li-toc"><a href="#sec119">8.2  Simulation d’un échantillon</a>
</li><li class="li-toc"><a href="#sec120">8.3  Intervalle de fluctuation</a>
</li><li class="li-toc"><a href="#sec121">8.4  Évolution d’une fréquence.</a>
</li><li class="li-toc"><a href="#sec122">8.5  Triangles de spaghettis</a>
</li><li class="li-toc"><a href="#sec123">8.6  Les aiguilles de Buffon</a>
</li><li class="li-toc"><a href="#sec124">8.7  Marche aléatoire à 1 dimension.</a>
</li><li class="li-toc"><a href="#sec125">8.8  Les urnes de Polya</a>
</li></ul>
</li><li class="li-toc"><a href="#sec126">Chapitre 9  Les algorithmes du document ressource Python d’eduscol</a>
<ul class="toc"><li class="li-toc">
<a href="#sec127">9.1  Arithmétique</a>
<ul class="toc"><li class="li-toc">
<a href="#sec128">9.1.1  Euclide</a>
</li><li class="li-toc"><a href="#sec129">9.1.2  Écriture en base 2</a>
</li><li class="li-toc"><a href="#sec130">9.1.3  Test de primalité</a>
</li><li class="li-toc"><a href="#sec131">9.1.4  Factorisation d’entiers</a>
</li></ul>
</li><li class="li-toc"><a href="#sec132">9.2  Longueur d’un arc de courbe</a>
</li><li class="li-toc"><a href="#sec133">9.3  Réfraction et recherche de minimas</a>
<ul class="toc"><li class="li-toc">
<a href="#sec134">9.3.1  Minimum d’une fonction</a>
</li><li class="li-toc"><a href="#sec135">9.3.2  Application à la réfraction</a>
</li><li class="li-toc"><a href="#sec136">9.3.3  Discussion</a>
</li><li class="li-toc"><a href="#sec137">9.3.4  Autre méthode de recherche de minimum</a>
</li></ul>
</li><li class="li-toc"><a href="#sec138">9.4  Solveur de triangle</a>
</li></ul>
</li><li class="li-toc"><a href="#sec139">Chapitre 10  Aide</a>
<ul class="toc"><li class="li-toc">
<a href="#sec140">10.1  Les fonctions usuelles avec <span style="font-family:monospace">Xcas</span></a>
</li><li class="li-toc"><a href="#sec141">10.2  Les fonctions <span style="font-family:monospace">Xcas</span> de calcul formel utilisées</a>
</li><li class="li-toc"><a href="#sec142">10.3  Les fonctions <span style="font-family:monospace">Xcas</span> de géométrie utilisées</a>
</li><li class="li-toc"><a href="#sec143">10.4  Les fonctions <span style="font-family:monospace">Xcas</span> de programmation utilisées</a>
</li><li class="li-toc"><a href="#sec144">10.5  Les fonctions <span style="font-family:monospace">Xcas</span> utilisées en statistiques</a>
</li></ul>
</li><li class="li-toc"><a href="#sec145">Annexe A  Premiers pas avec les interfaces de <span style="font-family:monospace">Xcas</span></a>
<ul class="toc"><li class="li-toc">
<a href="#sec146">A.1  Les différentes intefaces</a>
</li><li class="li-toc"><a href="#sec147">A.2  Avec <span style="font-family:monospace">Xcas</span> pour Firefox</a>
</li><li class="li-toc"><a href="#sec148">A.3  <span style="font-family:monospace">Xcas</span> natif sur PC Windows et Linux et sur Mac.</a>
</li><li class="li-toc"><a href="#sec149">A.4  Conseils pour adapter des scripts Python.</a>
</li><li class="li-toc"><a href="#sec150">A.5  Python et giacpy</a>
</li></ul>
</li><li class="li-toc"><a href="#sec151">Annexe B  Xcas, Python et Javascript.</a>
<ul class="toc"><li class="li-toc">
<a href="#sec152">B.1  Le mode de compatibilité Python de Xcas</a>
</li><li class="li-toc"><a href="#sec153">B.2  Xcas et Javascript</a>
</li><li class="li-toc"><a href="#sec154">B.3  Xcas et Python</a>
</li><li class="li-toc"><a href="#sec155">B.4  Comparaison rapide</a>
</li></ul>
</li><li class="li-toc"><a href="#sec156">Annexe C  Les biais des langages interprétés</a>
</li></ul><!--TOC chapter id="sec2" Index-->
<h1 id="sec2" class="chapter">Index</h1><!--SEC END --><p></p><table style="border-spacing:6px;border-collapse:separate;" class="cellpading0"><tr><td style="vertical-align:top;text-align:left;" ><ul class="indexenv"><li class="li-indexenv">
(), <a href="#hevea_default7">2.1.2</a>
<br>
<br>
</li><li class="li-indexenv">+, <a href="#hevea_default12">2.1.2</a>
<br>
<br>
</li><li class="li-indexenv">-&gt;, <a href="#hevea_default72">2.2.5</a>
<br>
<br>
</li><li class="li-indexenv">//, <a href="#hevea_default76"><span style="font-weight:bold">3.1.1</span></a>
<br>
<br>
</li><li class="li-indexenv">:;, <a href="#hevea_default83">3.4</a>
</li><li class="li-indexenv">:=, <a href="#hevea_default79"><span style="font-weight:bold">3.2</span></a>
<br>
<br>
</li><li class="li-indexenv">;, <a href="#hevea_default82">3.4</a>
<br>
<br>
</li><li class="li-indexenv">=, <a href="#hevea_default71">2.2.4</a>
</li><li class="li-indexenv">==, <a href="#hevea_default26">2.1.4</a>
<br>
<br>
</li><li class="li-indexenv">[], <a href="#hevea_default2">2.1.2</a>, <a href="#hevea_default11">2.1.2</a>
<br>
<br>
</li><li class="li-indexenv">#, <a href="#hevea_default77"><span style="font-weight:bold">3.1.1</span></a>
</li><li class="li-indexenv"># local, <a href="#hevea_default55">2.2</a>, <a href="#hevea_default88"><span style="font-weight:bold">3.6</span></a>
</li><li class="li-indexenv">#=, <a href="#hevea_default27">2.1.4</a>
</li><li class="li-indexenv">&#36;, <a href="#hevea_default6">2.1.2</a>, <a href="#hevea_default9">2.1.2</a>
</li><li class="li-indexenv">!=, <a href="#hevea_default28">2.1.4</a>
</li><li class="li-indexenv">", <a href="#hevea_default13">2.1.2</a>
</li><li class="li-indexenv">&lt;, <a href="#hevea_default31">2.1.4</a>
</li><li class="li-indexenv">&lt;=, <a href="#hevea_default29">2.1.4</a>
</li><li class="li-indexenv">&gt;, <a href="#hevea_default32">2.1.4</a>
</li><li class="li-indexenv">&gt;=, <a href="#hevea_default30">2.1.4</a>
<br>
<br>
</li><li class="li-indexenv">alors, <a href="#hevea_default94"><span style="font-weight:bold">3.9</span></a>
</li><li class="li-indexenv">append, <a href="#hevea_default18">2.1.3</a>
<br>
<br>
</li><li class="li-indexenv">Buffon, <a href="#hevea_default126">8.6</a>
<br>
<br>
</li><li class="li-indexenv">carre, <a href="#hevea_default119">5.5</a>
</li><li class="li-indexenv">cercle, <a href="#hevea_default120">5.6</a>
</li><li class="li-indexenv">choice, <a href="#hevea_default62">2.2.2</a>
</li><li class="li-indexenv">coeff, <a href="#hevea_default38">2.1.5</a>, <a href="#hevea_default122">6.2.2</a>
</li><li class="li-indexenv">concat, <a href="#hevea_default20">2.1.3</a>
</li><li class="li-indexenv">coordonnees, <a href="#hevea_default113">5.2</a>
<br>
<br>
</li><li class="li-indexenv">debug, <a href="#hevea_default110">3.18</a>
</li><li class="li-indexenv">degree, <a href="#hevea_default36">2.1.5</a>
</li><li class="li-indexenv">del, <a href="#hevea_default81"><span style="font-weight:bold">3.3</span></a>
</li><li class="li-indexenv">dim, <a href="#hevea_default14">2.1.3</a>
</li><li class="li-indexenv">droit, <a href="#hevea_default16">2.1.3</a>, <a href="#hevea_default124">6.2.2</a>
</li><li class="li-indexenv">droite, <a href="#hevea_default114">5.3</a>
<br>
<br>
</li><li class="li-indexenv">else, <a href="#hevea_default98"><span style="font-weight:bold">3.9</span></a>
</li><li class="li-indexenv">equation, <a href="#hevea_default115">5.3</a>, <a href="#hevea_default121">5.6</a>
</li><li class="li-indexenv">erreur d’exécution, <a href="#hevea_default109">3.18</a>
</li><li class="li-indexenv">erreur de syntaxe, <a href="#hevea_default107">3.18</a>
</li><li class="li-indexenv">evalc, <a href="#hevea_default1">2.1.1</a>
</li><li class="li-indexenv">evalf, <a href="#hevea_default0">2.1.1</a>
</li><li class="li-indexenv">exécution, erreur de, <a href="#hevea_default108">3.18</a>
</li><li class="li-indexenv">expression, <a href="#hevea_default45">2.1.6</a>
<br>
<br>
</li><li class="li-indexenv">ffonction, <a href="#hevea_default52">2.2</a>, <a href="#hevea_default66"><span style="font-weight:bold">2.2.3</span></a>
</li><li class="li-indexenv">fonction, <a href="#hevea_default51">2.2</a>, <a href="#hevea_default65"><span style="font-weight:bold">2.2.3</span></a>
</li><li class="li-indexenv">fpour, <a href="#hevea_default90"><span style="font-weight:bold">3.7</span></a>
</li><li class="li-indexenv">fsi, <a href="#hevea_default96"><span style="font-weight:bold">3.9</span></a>
</li><li class="li-indexenv">ftantque, <a href="#hevea_default100"><span style="font-weight:bold">3.11</span></a>
</li><li class="li-indexenv">func, <a href="#hevea_default46">2.1.6</a>
<br>
<br>
</li><li class="li-indexenv">gauche, <a href="#hevea_default15">2.1.3</a>, <a href="#hevea_default123">6.2.2</a>
</li><li class="li-indexenv">gcd, <a href="#hevea_default87">3.6</a>
<br>
<br>
</li><li class="li-indexenv">help, <a href="#hevea_default78"><span style="font-weight:bold">3.1.2</span></a>
<br>
<br>
</li><li class="li-indexenv">identifier, <a href="#hevea_default49">2.1.6</a>
</li><li class="li-indexenv">if, <a href="#hevea_default97"><span style="font-weight:bold">3.9</span></a>
</li><li class="li-indexenv">ifte, <a href="#hevea_default75">2.2.6</a>
</li></ul></td><td style="vertical-align:top;text-align:left;" ><ul class="indexenv"><li class="li-indexenv">integer, <a href="#hevea_default43">2.1.6</a>
</li><li class="li-indexenv">iquo, <a href="#hevea_default69">2.2.4</a>
</li><li class="li-indexenv">iquorem, <a href="#hevea_default67">2.2.4</a>
</li><li class="li-indexenv">irem, <a href="#hevea_default68">2.2.4</a>
<br>
<br>
</li><li class="li-indexenv">Javascript, <a href="#hevea_default129">B.2</a>
<br>
<br>
</li><li class="li-indexenv">lambda, <a href="#hevea_default73">2.2.5</a>
</li><li class="li-indexenv">len, <a href="#hevea_default17">2.1.3</a>
</li><li class="li-indexenv">local, <a href="#hevea_default53">2.2</a>, <a href="#hevea_default86"><span style="font-weight:bold">3.6</span></a>
<br>
<br>
</li><li class="li-indexenv">makelist, <a href="#hevea_default4">2.1.2</a>
</li><li class="li-indexenv">marche aléatoire, <a href="#hevea_default127">8.7</a>
<br>
<br>
</li><li class="li-indexenv">normal, <a href="#hevea_default33">2.1.5</a>
<br>
<br>
</li><li class="li-indexenv">op, <a href="#hevea_default10">2.1.2</a>
</li><li class="li-indexenv">or, <a href="#hevea_default91"><span style="font-weight:bold">3.7</span></a>
<br>
<br>
</li><li class="li-indexenv">Polya, <a href="#hevea_default128">8.8</a>
</li><li class="li-indexenv">Python, <a href="#hevea_default130">B.3</a>
</li><li class="li-indexenv">pas, <a href="#hevea_default92"><span style="font-weight:bold">3.8</span></a>
</li><li class="li-indexenv">plotfunc, <a href="#hevea_default70">2.2.4</a>
</li><li class="li-indexenv">point, <a href="#hevea_default104">3.17</a>, <a href="#hevea_default111">5.1</a>
</li><li class="li-indexenv">poly2symb, <a href="#hevea_default39">2.1.5</a>
</li><li class="li-indexenv">polygone, <a href="#hevea_default117">5.5</a>
</li><li class="li-indexenv">polygone_ouvert, <a href="#hevea_default116">5.4</a>
</li><li class="li-indexenv">pour, <a href="#hevea_default89"><span style="font-weight:bold">3.7</span></a>
</li><li class="li-indexenv">prepend, <a href="#hevea_default19">2.1.3</a>
</li><li class="li-indexenv">purge, <a href="#hevea_default35">2.1.5</a>, <a href="#hevea_default50">2.1.6</a>, <a href="#hevea_default80"><span style="font-weight:bold">3.3</span></a>
<br>
<br>
</li><li class="li-indexenv">quand, <a href="#hevea_default74">2.2.6</a>
<br>
<br>
</li><li class="li-indexenv">RandSeed, <a href="#hevea_default58">2.2.2</a>
</li><li class="li-indexenv">rand, <a href="#hevea_default59">2.2.2</a>
</li><li class="li-indexenv">randint, <a href="#hevea_default60">2.2.2</a>
</li><li class="li-indexenv">random, <a href="#hevea_default61">2.2.2</a>
</li><li class="li-indexenv">randseed, <a href="#hevea_default57">2.2.2</a>
</li><li class="li-indexenv">range, <a href="#hevea_default3">2.1.2</a>
</li><li class="li-indexenv">rational, <a href="#hevea_default44">2.1.6</a>
</li><li class="li-indexenv">real, <a href="#hevea_default42">2.1.6</a>
</li><li class="li-indexenv">retourne, <a href="#hevea_default54">2.2</a>, <a href="#hevea_default84"><span style="font-weight:bold">3.5</span></a>, <a href="#hevea_default103">3.14</a>
</li><li class="li-indexenv">return, <a href="#hevea_default85"><span style="font-weight:bold">3.5</span></a>
</li><li class="li-indexenv">reverse, <a href="#hevea_default24">2.1.3</a>
</li><li class="li-indexenv">revlist, <a href="#hevea_default25">2.1.3</a>
</li><li class="li-indexenv">rotate, <a href="#hevea_default21">2.1.3</a>
<br>
<br>
</li><li class="li-indexenv">sample, <a href="#hevea_default64">2.2.2</a>
</li><li class="li-indexenv">segment, <a href="#hevea_default105">3.17</a>, <a href="#hevea_default112">5.1</a>
</li><li class="li-indexenv">seq, <a href="#hevea_default5">2.1.2</a>, <a href="#hevea_default8">2.1.2</a>
</li><li class="li-indexenv">shift, <a href="#hevea_default22">2.1.3</a>
</li><li class="li-indexenv">shuffle, <a href="#hevea_default63">2.2.2</a>
</li><li class="li-indexenv">si, <a href="#hevea_default93"><span style="font-weight:bold">3.9</span></a>
</li><li class="li-indexenv">simplify, <a href="#hevea_default34">2.1.5</a>
</li><li class="li-indexenv">sinon, <a href="#hevea_default95"><span style="font-weight:bold">3.9</span></a>
</li><li class="li-indexenv">spaghetti, <a href="#hevea_default125">8.5</a>
</li><li class="li-indexenv">srand, <a href="#hevea_default56">2.2.2</a>
</li><li class="li-indexenv">string, <a href="#hevea_default48">2.1.6</a>
</li><li class="li-indexenv">subtype, <a href="#hevea_default41">2.1.6</a>
</li><li class="li-indexenv">suppress, <a href="#hevea_default23">2.1.3</a>
</li><li class="li-indexenv">symb2poly, <a href="#hevea_default37">2.1.5</a>
</li><li class="li-indexenv">syntaxe, erreur de, <a href="#hevea_default106">3.18</a>
<br>
<br>
</li><li class="li-indexenv">tantque, <a href="#hevea_default99"><span style="font-weight:bold">3.11</span></a>
</li><li class="li-indexenv">time, <a href="#hevea_default102">3.12.5</a>
</li><li class="li-indexenv">triangle, <a href="#hevea_default118">5.5</a>
</li><li class="li-indexenv">type, <a href="#hevea_default40">2.1.6</a>
<br>
<br>
</li><li class="li-indexenv">vector, <a href="#hevea_default47">2.1.6</a>
<br>
<br>
</li><li class="li-indexenv">while, <a href="#hevea_default101"><span style="font-weight:bold">3.11</span></a>
</li></ul></td></tr>
</table>
<!--TOC chapter id="sec3" Introduction-->
<h1 id="sec3" class="chapter">Chapitre 1  Introduction</h1><!--SEC END -->
<!--TOC section id="sec4" Apprendre en programmant.-->
<h2 id="sec4" class="section">1.1  Apprendre en programmant.</h2><!--SEC END --><p>
Ce document est principalement destiné aux enseignants qui 
souhaitent utiliser Xcas pour enseigner l’algorithmique au lycée.
Nous espérons qu’il sera aussi consulté par des élèves.
Dans sa version 
<a href="http://www-fourier.ujf-grenoble.fr/%7eparisse/irem/algolycee.html">HTML</a> consultable depuis un navigateur, certains champs de saisies peuvent 
être modifiés et testés directement, y compris sur une tablette
ou un smartphone, ce qui devrait être un plus par rapport
à un cours de programmation papier ou PDF (les fonctions “utilitaires” qui 
sont appelées plusieurs fois par d’autres fonctions n’ont pas besoin 
d’être validées par l’utilisateur, elles sont interprétées 
au chargement).</p><p><span style="font-family:monospace">Xcas</span> possède deux interfaces. L’interface classique (Xcas natif)
fonctionne sur PC et nécessite une installation, 
cf. la section <a href="#sec%3APcMac">A.3</a>.
On peut aussi utiliser Xcas pour Firefox sans installation
depuis tout appareil disposant d’un navigateur (Firefox 
recommandé), par exemple depuis un smartphone 
ou une tablette sans installation, depuis le lien :<br>
<a href="http://www-fourier.ujf-grenoble.fr/%7eparisse/xcasfr.html">http://www-fourier.ujf-grenoble.fr/~parisse/xcasfr.html</a><br>
(L’accès réseau est nécessaire uniquement lors du chargement de
la page).<br>
Il n’est donc pas indispensable d’aller en salle informatique
pour faire un exercice d’algorithmique pendant un cours de mathématiques, 
on peut utiliser les smartphones (en mode avion) 
ou les tablettes des élèves comme des super-calculatrices (formelles, 
graphiques, 3d, ... il ne manque que le mode examen...). C’est une
raison supplémentaire pour écrire ce document, car faire programmer 
les algorithmes par les élèves nous parait indispensable
pour les motiver par la satisfaction de faire tourner son
programme puis de le modifier et de l’améliorer. </p><p>Faire programmer nous semble bien plus formateur que de demander
à un élève de comprendre ce que fait un algorithme non commenté, 
surtout s’il n’a pas de machine pour le tester (par exemple le jour
du bac).
En effet l’élève n’a aucun rôle créateur 
(il ne conçoit pas l’algorithme), il a un rôle analogue à
celui d’un professeur corrigeant des copies ce qui n’est pas du tout
motivant et a devant les yeux un modèle désastreux d’algorithme puisque
non commenté ! 
De plus, comprendre ce que fait un algorithme non
commenté est parfois plus difficile que d’en concevoir un, car les
notations de variables, par exemple, ne prennent souvent sens qu’une fois
l’algorithme compris. 
Imagine-t-on donner les étapes de calcul
d’une démonstration, sans explications, et demander quel
est le théorème qui a été démontré ?
Bien sur, la programmation s’apprend de manière progressive,
en regardant des exemples de code commentés, puis en complétant
des maquettes d’algorithmes avant de se lancer dans l’écriture
complète de nouveaux algorithmes.</p>
<!--TOC section id="sec5" Le choix du langage de programmation-->
<h2 id="sec5" class="section">1.2  Le choix du langage de programmation</h2><!--SEC END --><p>
La plupart des langages interprétés permettent d’apprendre à programmer 
les concepts algorithmiques au programme du lycée (test, boucle,
variable, affectation, fonction). Pour les élèves, la difficulté
principale ce sont les concepts algorithmiques, rarement la syntaxe du langage 
lui-même, à condition de pouvoir se faire aider par l’enseignant s’ils sont 
bloqués. C’est donc l’enseignant qui devrait choisir un langage avec 
lequel il se sent à l’aise, non seulement pour écrire lui-même un 
programme, mais aussi pour trouver rapidement une erreur de syntaxe ou 
d’exécution dans le programme d’un de ses élèves. </p><p>Pour la grande majorité des élèves, nous pensons qu’il serait 
souhaitable qu’ils soient confrontés lors des changements de professeur
à plusieurs langages au cours de leur scolarité
(par exemple <span style="font-family:monospace">Xcas</span>, calculatrices, Python, Javascript ...),
ce qui leur permettrait de mieux comprendre les concepts universels partagés 
(l’algorithmique) et les biais et particularités propres à un langage 
donné (voir en appendice), et faciliterait 
aussi leur adaptation à d’autres 
langages plus tard. 
Pour ceux qui se destinent à des études scientifiques, il nous 
parait important qu’ils soient aussi confrontés à d’autres 
types de langages (compilés, fonctionnels ...) au cours de leurs études
supérieures, dont au moins un langage de plus bas
niveau : les langages interprétés permettent d’utiliser
facilement des types ou instructions puissantes,
se confronter avec un langage de plus bas niveau permet
de mieux comprendre ce qui est basique ou ne l’est pas
et ce qui est intrinsèquement rapide ou/et couteux en ressource
mémoire ou ne l’est pas (on peut voir ça comme l’analogue entre
faire une démonstration ou admettre un théorème).</p><p>Actuellement aucun langage n’est imposé dans les textes
pour le lycée,
nous espérons que cette situation va perdurer et que certains
enseignants résisteront aux pressions de vouloir imposer
Python comme le seul et unique langage de programmation
au lycée (comme pour les enseignements obligatoires
d’informatique en classe préparatoires). Pour les aider
dans cette démarche, nous avons ajouté la possibilité
de programmer dans Xcas avec une syntaxe compatible avec Python (les 
personnes connaissant Python peuvent consulter l’appendice <a href="#sec%3Apython">B.1</a> 
qui décrit plus en détails les différences entre Python et <span style="font-family:monospace">Xcas</span>).</p><p><span style="font-weight:bold">Pourquoi choisir </span><span style="font-weight:bold"><span style="font-family:monospace">Xcas</span></span><span style="font-weight:bold"> ?</span><br>
<span style="font-family:monospace">Xcas</span> est fortement orienté mathématique et de ce fait
peut facilement interagir avec les thèmes du programme de maths, tous les 
types mathématiques au programme du lycée sont directement accessibles (par
exemple : les nombres entiers, rationnels, réels, complexes, les nombres 
approchés, les vecteurs, les polynômes et les matrices). </p><p>Le langage de programmation natif
de <span style="font-family:monospace">Xcas</span> est proche du langage algorithmique
ce qui facilite ensuite sa traduction dans d’autre langage, y compris 
en syntaxe Python (menu Fichier, Exporter, texte python).
Nous avons adapté le langage en français pour en faciliter l’apprentissage
d’après notre expérience d’enseignement avec des publics divers :
</p><ul class="itemize"><li class="li-itemize">
Les structures sont délimitées par des mots-clefs explicites 
en français <br>
(<code>si . alors . sinon . fsi</code>),<br>
(<code>pour . de . jusque . faire ... fpour</code>),<br>
(<code>tantque . faire ... ftantque</code>)...<br>
L’indentation sert à controler qu’on n’a pas fait
de faute de syntaxe (non-fermeture d’une parenthèse par exemple).
Les diverses interfaces de <span style="font-family:monospace">Xcas</span> proposent des assistants
pour créer facilement les structures de controle usuelles 
(fonction, test, boucle).
</li><li class="li-itemize">Il faut déclarer explicitement les variables locales, ainsi une
faute de frappe dans un nom de variable est détectée et un
avertissement est affiché si une variable n’est pas déclarée ou n’est pas
initialisée.
</li><li class="li-itemize">Lorsqu’on programme une fonction, on peut lui passer en argument des 
variables qui sont de type fonction ou expression, ceci facilite l’écriture 
de certains algorithmes (dichotomie, méthode des rectangles par exemple).
</li><li class="li-itemize">Les thèmes d’algorithmique abordés au lycée sont
presque toujours déjà implémentés dans une commande de <span style="font-family:monospace">Xcas</span>, 
ceci permet de vérifier en comparant le résultat de la fonction qu’on
vient de concevoir avec la commande interne.
</li></ul><p>
<span style="font-family:monospace">Xcas</span> accepte également l’écriture de programmes 
en syntaxe compatible Python, mais en évitant 
certains pièges du langage par rapport aux mathématiques :
</p><ul class="itemize"><li class="li-itemize">
on peut écrire <code><span style="font-family:monospace">^</span></code> pour la puissance, 
<span style="font-family:monospace">**</span> est également accepté,
</li><li class="li-itemize">on peut écrire comme en mathématiques <span style="font-family:monospace">2a</span> (inutile de mettre 
le signe <span style="font-family:monospace">*</span>). Par contre il faut mettre le signe <span style="font-family:monospace">*</span>
dans <span style="font-family:monospace">2a*(a+1)</span>,
</li><li class="li-itemize">on peut travailler naturellement avec les rationnels,
<span style="font-family:monospace">1/2</span> renvoie une fraction,
et non <span style="font-family:monospace">0</span> (en Python 2) ou le nombre approché <span style="font-family:monospace">0.5</span> (en Python 3),
</li><li class="li-itemize">on peut aussi faire du calcul exact avec des racines carrées et
du calcul littéral avec des variables formelles,
</li><li class="li-itemize">le nombre complexe <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>i</mi></mrow><annotation encoding='application/x-tex'>i</annotation></semantics></math> est noté <span style="font-family:monospace">i</span> 
et non <span style="font-family:monospace">1j</span>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>i</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>i^2</annotation></semantics></math> s’écrit 
<span style="font-family:monospace">i</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2</span> et non <span style="font-family:monospace">1j**2</span> et donne comme réponse <span style="font-family:monospace">-1</span> et non 
<span style="font-family:monospace">-1+0j</span>, 
</li><li class="li-itemize">les listes servent à représenter des vecteurs, des matrices,
des polynômes,
</li><li class="li-itemize">toutes les commandes de <span style="font-family:monospace">Xcas</span>
sont accessibles, par exemple les commandes de géométrie analytique
(ces commandes sont capables de faire des calculs, 
pas seulement de représentations graphiques) ou de calcul littéral,
</li></ul><p>On s’efforcera de donner dans ce document 
des programmes écrits avec les mots-clefs en français et leur 
traduction en syntaxe Python, les deux syntaxes sont valides dans
<span style="font-family:monospace">Xcas</span>. Lorsque la traduction Python n’est pas fournie,
on peut l’obtenir de manière automatique depuis Xcas :
on saisit le programme écrit en français, puis on
l’exporte en texte Python.</p><p>Une partie des programmes de ce document écrits en syntaxe Python,
peuvent être utilisés dans un interpréteur Python à condition
d’y avoir chargé le module 
<a href="https://www-fourier.ujf-grenoble.fr/%7eparisse/giac_fr.html#python">giacpy</a>
par la commande <code>from giacpy import *</code> et d’avoir
affecté quelques variables symboliques (par exemple
pour <code>x</code> par <code>x=giac('x')</code>, car il n’y a pas 
de variables symboliques en Python)</p>
<!--TOC section id="sec6" Structure du document-->
<h2 id="sec6" class="section">1.3  Structure du document</h2><!--SEC END --><p>
Les deux premiers chapitres <a href="#sec%3Atypefunc">2</a> et <a href="#chap%3Aprog">3</a>
sont destinés aux débutants, ils présentent les notions
de variables, types fondementaux, les structures de programmation et
les fonctions avec de nombreux exemples, en partie non mathématiques.
Les chapitres suivants donnent de nombreux exemples d’algorithmes
dans des thèmes mathématiques allant de la résolution
d’équation, à la géométrie et aux statistiques. En annexe
on trouvera une aide à l’installation et aux premiers pas avec Xcas,
ainsi qu’une discussion plus avancée sur les divers langages
de programmation interprétés.</p>
<!--TOC chapter id="sec7" Types, fonctions-->
<h1 id="sec7" class="chapter">Chapitre 2  Types, fonctions</h1><!--SEC END --><p> <a id="sec:typefunc"></a>
</p>
<!--TOC section id="sec8" Types-->
<h2 id="sec8" class="section">2.1  Types</h2><!--SEC END -->
<!--TOC subsection id="sec9" Entiers, rationnels, réels, complexes et les nombres approchés.-->
<h3 id="sec9" class="subsection">2.1.1  Entiers, rationnels, réels, complexes et les nombres approchés.</h3><!--SEC END --><p><a id="hevea_default0"></a><a id="hevea_default1"></a>
Dans <span style="font-family:monospace">Xcas</span> :
</p><ul class="itemize"><li class="li-itemize">
les entiers sont des nombres de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Zopf;</mi></mrow><annotation encoding='application/x-tex'>\mathbb{Z}</annotation></semantics></math>, par exemple -2,
</li><li class="li-itemize">les rationnels sont des nombres de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Qopf;</mi></mrow><annotation encoding='application/x-tex'>\mathbb{Q}</annotation></semantics></math>, par exemple <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>1</mn><mo stretchy="false">/</mo><mn>3</mn></mrow><annotation encoding='application/x-tex'>1/3</annotation></semantics></math>,
</li><li class="li-itemize">les nombres approchés sont des nombres décimaux<sup><a id="text1" href="#note1">1</a></sup>, par exemple <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>3.14</mn></mrow><annotation encoding='application/x-tex'>3.14</annotation></semantics></math>.<br>
<span style="font-weight:bold">Attention</span>, le séparateur entre
partie entière et partie fractionnaire est le point <code>.</code><br>
On peut utiliser la notation scientifique mantisse <code>e</code> exposant
pour entrer des nombres approchés, par exemple <code>1.2e-7</code>
signifie <code>1.2</code> multiplié par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mn>10</mn> <mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mn>7</mn></mrow></msup></mrow><annotation encoding='application/x-tex'>10^{&#x2d;7}</annotation></semantics></math>.
</li><li class="li-itemize">les nombres réels sont représentés par des nombres décimaux ou 
par des valeurs symboliques, par exemple <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msqrt><mn>2</mn></msqrt></mrow><annotation encoding='application/x-tex'>\sqrt 2</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&pi;</mi></mrow><annotation encoding='application/x-tex'>\pi</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>e</mi></mrow><annotation encoding='application/x-tex'>e</annotation></semantics></math>.
</li><li class="li-itemize">les nombres complexes sont représentés par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>+</mo><mi>i</mi><mi>b</mi></mrow><annotation encoding='application/x-tex'>a+ib</annotation></semantics></math> pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> 
réels. Avec les commandes <span style="font-family:monospace">re</span>, <span style="font-family:monospace">im</span>, <span style="font-family:monospace">arg</span> et <span style="font-family:monospace">abs</span> pour 
avoir la partie réelle, la partie imaginaire, l’argument et le module.
</li></ul><p>
Pour avoir une valeur approchée d’un nombre réel on utilise la commande
<span style="font-family:monospace">evalf</span>, par exemple <span style="font-family:monospace">evalf(sqrt(2))</span> ou <span style="font-family:monospace">evalf(sqrt(2),20)</span> pour 
avoir une valeur approchée de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msqrt><mn>2</mn></msqrt></mrow><annotation encoding='application/x-tex'>\sqrt 2</annotation></semantics></math> avec 20 chiffres significatifs.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">evalf(sqrt(2))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">evalf(sqrt(2),20)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Pour avoir l’écriture d’un nombre complexe sous la forme <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>+</mo><mi>i</mi><mi>b</mi></mrow><annotation encoding='application/x-tex'>a+ib</annotation></semantics></math> avec <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> et 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> réels on utilise la commande <span style="font-family:monospace">evalc</span>, par exemple 
<span style="font-family:monospace">evalc((1+i*sqrt(2))</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+2)</span>.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">(1+i*sqrt(2))^2+2
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">evalc((1+i*sqrt(2))^2+2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC subsection id="sec10" Les listes, les séquences et les chaînes de caractères-->
<h3 id="sec10" class="subsection">2.1.2  Les listes, les séquences et les chaînes de caractères</h3><!--SEC END -->
<!--TOC subsubsection id="sec11" Définition d’une liste-->
<h4 id="sec11" class="subsubsection">Définition d’une liste</h4><!--SEC END --><p><a id="hevea_default2"></a>
Qu’est-ce qu’une <span style="font-weight:bold">liste</span> ?<br>
C’est une énumération d’objets, dont l’ordre est important. 
Cela peut servir à représenter les coordonnées d’un point ou
d’un vecteur, à contenir une liste de valeurs (observations) 
en statistiques, ...<br>
Une liste est délimitée par des crochets <span style="font-family:monospace">[]</span> et les éléments de 
la liste sont séparés par une virgule <span style="font-family:monospace">,</span><br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[2,24,1,15,5,10]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC subsubsection id="sec12" Création d’une liste-->
<h4 id="sec12" class="subsubsection">Création d’une liste</h4><!--SEC END --><p><a id="hevea_default3"></a><a id="hevea_default4"></a><a id="hevea_default5"></a><a id="hevea_default6"></a>
</p><ul class="itemize"><li class="li-itemize">
<span style="font-family:monospace">range</span><br>
<span style="font-family:monospace">range(n)</span> renvoie la liste <span style="font-family:monospace">[0,1..n-1]</span><br>
<span style="font-family:monospace">range(a,b)</span> renvoie la liste <span style="font-family:monospace">[a,a+1..b[</span><br>
<span style="font-family:monospace">range(a,b,p)</span> la liste <span style="font-family:monospace">[a,a+p,a+2p..b[</span> à condition que <span style="font-family:monospace">p</span> 
soit un entier.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">range(5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">range(5,11)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">range(11,5,-1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">range(1,11,3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
</li><li class="li-itemize"><span style="font-family:monospace">seq</span> renvoie la liste obtenue lorsqu’on calcule
une expression dépendant d’un paramètre <span style="font-family:monospace">var</span> qui varie entre <span style="font-family:monospace">a</span> 
et <span style="font-family:monospace">b</span> (on peut ajouter un argument optionnel, le pas <span style="font-family:monospace">p</span>.<br>
<span style="font-family:monospace">seq</span> a 4 ou 5 arguments)

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">seq(2^k,k,0,8)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">seq(2^k,k,0,8,2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">seq(2^k,k,0,8,1/2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</li><li class="li-itemize"><span style="font-family:monospace">makelist</span> renvoie une liste faite à partir d’une fonction ou d’une 
constante.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">makelist(x->x^2,1,10)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">makelist(x->x^2,1,10,2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">makelist(x->x^2,1,10,1/2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</li></ul>
<!--TOC subsubsection id="sec13" Définition d’une séquence-->
<h4 id="sec13" class="subsubsection">Définition d’une séquence</h4><!--SEC END --><p><a id="hevea_default7"></a>
Qu’est-ce qu’une <span style="font-weight:bold">séquence</span> ?<br>
On peut le voir comme une liste sans crochets, ce qui signifie
que si on sépare 2 séquences par une virgule, elles sont
concaténées, on ne peut
donc pas créer une séquence de séquences alors qu’on peut créer
une liste de listes. Par exemple les arguments d’une fonction sont
regroupés en une séquence.<br>
Une séquence n’est pas délimitée 
(ou est délimitée par des parenthèses <span style="font-family:monospace">()</span>) et les éléments
de la séquence sont séparés par une virgule <span style="font-family:monospace">,</span><br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">S:=(2,24,1,15,5,10)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-weight:bold">Attention</span>, <br>
cette syntaxe renvoie un n-uplet en Python, il s’agit d’une liste
constante (non modifiable après création).</p>
<!--TOC subsubsection id="sec14" Création d’une séquence-->
<h4 id="sec14" class="subsubsection">Création d’une séquence</h4><!--SEC END --><p><a id="hevea_default8"></a><a id="hevea_default9"></a>
</p><ul class="itemize"><li class="li-itemize">
<span style="font-family:monospace">seq</span> renvoie la séquence obtenue lorsque <span style="font-family:monospace">var</span> varie entre 
<span style="font-family:monospace">a</span> et <span style="font-family:monospace">b</span> (avec un argument optionnel, le pas=<span style="font-family:monospace">p</span>).
<span style="font-family:monospace">seq</span> a 2 ou 3 arguments.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">seq(2^k,k=0..8)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">seq(2^k,k=0..8,2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">seq(2^k,k=0..8,1/2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</li><li class="li-itemize">&#36; est la version infixée de <span style="font-family:monospace">seq</span><br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">2^k&#36;10
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">2^k&#36;(k=0..8)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">2^k&#36;(k=0..8,2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">2^k&#36;(k=0..8,1/2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</li></ul>
<!--TOC subsubsection id="sec15" Transformation d’une séquence en liste et vice-versa-->
<h4 id="sec15" class="subsubsection">Transformation d’une séquence en liste et vice-versa</h4><!--SEC END --><p><a id="hevea_default10"></a>
<a id="hevea_default11"></a>
Si <span style="font-family:monospace">S</span> est une séquence alors <span style="font-family:monospace">[S]</span> est une liste.<br>
Si <span style="font-family:monospace">L</span> est une liste alors <span style="font-family:monospace">op(L)]</span> est une séquence.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[2,24,1,15,5,10]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">S:=(2,24,1,15,5,10)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">op(L)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">[S]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsubsection id="sec16" Définition d’une chaine de caractères-->
<h4 id="sec16" class="subsubsection">Définition d’une chaine de caractères</h4><!--SEC END --><p><a id="hevea_default12"></a><a id="hevea_default13"></a>
Qu’est-ce qu’une <span style="font-weight:bold">chaine de caractères</span> ?<br>
C’est la concaténation de 0, 1 ou plusieurs caractères.<br>
Une chaine de caractères est délimitée par <span style="font-family:monospace">""</span><br>
On concaténe de 2 chaînes avec <span style="font-family:monospace">+</span><br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">s:="Bonjour"
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">s:="";s:=s+"Bon"+"jour"
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec17" Les instructions sur les listes les séquences et les chaînes de caractères-->
<h3 id="sec17" class="subsection">2.1.3  Les instructions sur les listes les séquences et les chaînes de caractères</h3><!--SEC END --><p><a id="hevea_default14"></a><a id="hevea_default15"></a><a id="hevea_default16"></a><a id="hevea_default17"></a><a id="hevea_default18"></a><a id="hevea_default19"></a><a id="hevea_default20"></a><a id="hevea_default21"></a><a id="hevea_default22"></a><a id="hevea_default23"></a><a id="hevea_default24"></a><a id="hevea_default25"></a>
</p><ul class="itemize"><li class="li-itemize">
<span style="font-family:monospace">dim(L)</span> ou <span style="font-family:monospace">len(L)</span>
renvoie le nombre d’éléments de la liste <span style="font-family:monospace">L</span>.<br>
<span style="font-family:monospace">dim(S)</span> ou <span style="font-family:monospace">len(S)</span> renvoie le nombre d’éléments de la 
séquence <span style="font-family:monospace">S</span>.<br>
<span style="font-family:monospace">dim(s)</span> ou <span style="font-family:monospace">len(s)</span> renvoie le nombre de caractères de la chaîne 
<span style="font-family:monospace">s</span>.
</li><li class="li-itemize"><span style="font-family:monospace">[]</span> représente la liste vide et <span style="font-family:monospace">dim([])</span> vaut <span style="font-family:monospace">0</span>.<br>
<span style="font-family:monospace">NULL</span> représente la séquence vide et <span style="font-family:monospace">dim(NULL)</span> vaut <span style="font-family:monospace">0</span>.<br>
<span style="font-family:monospace">""</span> représente la chaîne vide et <span style="font-family:monospace">dim("")</span> vaut <span style="font-family:monospace">0</span>.
</li><li class="li-itemize">Les éléments de la liste sont numérotés de 0 jusque <span style="font-family:monospace">dim(L)-1</span>.<br>
<span style="font-family:monospace">L|0]</span> désigne le premier élément de la liste et <span style="font-family:monospace">L[dim(L)-1]</span> 
ou <span style="font-family:monospace">L[-1]</span> désigne le dernier élément de la liste <span style="font-family:monospace">L</span>.<br>
Les éléments de la séquence sont numérotés de 0 jusque <span style="font-family:monospace">dim(S)-1</span>.<br>
<span style="font-family:monospace">S|0]</span> désigne le premier élément de la séquence et 
<span style="font-family:monospace">S[dim(S)-1]</span> ou <span style="font-family:monospace">S[-1]</span> désigne le dernier élément de la séquence.<br>
<span style="font-family:monospace">s|0]</span> désigne le premier caractère de la chaîne et <span style="font-family:monospace">s[dim(s)-1]</span> 
désigne le dernier caractère de la chaîne <span style="font-family:monospace">S</span>.<br>
</li><li class="li-itemize"><span style="font-family:monospace">gauche(L,n)</span> renvoie les <span style="font-family:monospace">n</span> premiers éléments de la liste <span style="font-family:monospace">L</span>
(c’est le côté gauche de la liste).<br>
<span style="font-family:monospace">droit(L,n)</span> renvoie les <span style="font-family:monospace">n</span> derniers éléments de la liste <span style="font-family:monospace">L</span>
(c’est le côté droit de la liste).<br>
<span style="font-family:monospace">gauche(s,n)</span> renvoie les <span style="font-family:monospace">n</span> premiers caractères de la chaîne 
<span style="font-family:monospace">s</span> (c’est le côté gauche de la chaîne).<br>
<span style="font-family:monospace">droit(s,n)</span> renvoie les <span style="font-family:monospace">n</span> derniers caractères de la chaîne 
<span style="font-family:monospace">s</span> (c’est le côté droit de la chaîne).<br>
 Par exemple : soient la liste <span style="font-family:monospace">L:=[2,24,1,15,5,10]</span> et la chaîne
<span style="font-family:monospace">s:="Bonjour"</span>.<br>
<span style="font-family:monospace">L1:=seq(2*k,k,0,4)</span> crée la liste <span style="font-family:monospace">[0,2,4,6,8]</span>
</li><li class="li-itemize"><code>count_eq, count_inf, count_sup, count</code> : nombre d’éléments
égaux, inférieurs, supérieurs ou vérifiant une condition<br>
<code>count_sup(2,L1)</code> ou <span style="font-family:monospace">count(x-&gt;x&gt;2,L1)</span> compte le nombre d’éléments de <span style="font-family:monospace">L1</span> supérieurs
à 2.<br>
<span style="font-family:monospace">S1:=seq(2*k,k=0..4)</span> crée la séquence <span style="font-family:monospace">(0,2,4,6,8)</span><br>
<span style="font-family:monospace">count(x-&gt;x&gt;2,S1)</span> compte le nombre d’éléments de <span style="font-family:monospace">S1</span> supérieurs
à 2.
</li><li class="li-itemize"><span style="font-family:monospace">sum(L)</span> renvoie la somme des éléments de la liste <span style="font-family:monospace">L</span>.<br>
<span style="font-family:monospace">sum(S)</span> renvoie la somme des éléments de la séquence <span style="font-family:monospace">S</span>.
</li><li class="li-itemize">Quelques exemples :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[2,18,1,9,6,54]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">n1:=dim(L)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L[0]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
 <br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L[1];L[2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L[n1-1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">gauche(L,2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
 <br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">droit(L,2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
 <br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">sum(L)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">S:=(2,18,1,9,6,54)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">n1:=dim(S)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">S[0]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
 <br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">S[1];S[2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">S[n1-1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">sum(S)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">S:=S,3,27
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">S:=S,(4,36)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">S:=S,[5,45]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">s:="Bonjour"
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">n2:=dim(s)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
 <br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">s[0]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">s[1];s[2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
 <br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">s[n2-1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">gauche(s,3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">droit(s,4)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</li><li class="li-itemize"><span style="font-family:monospace">append</span><br>
<span style="font-family:monospace">append(L,a)</span> renvoie la liste où l’élément <span style="font-family:monospace">a</span> à été
rajouté à la fin de la liste <span style="font-family:monospace">L</span>.<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">append([1,2,3],4)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,2,3]; append(L,4); L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Attention</span><br>
Pour ajouter <span style="font-family:monospace">4</span> à la fin de la liste <span style="font-family:monospace">L</span> on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,2,3]; L:=append(L,4); L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
ou comme en Python<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,2,3]; L.append(4); L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</li><li class="li-itemize">Il est facile d’ajouter un élément à une séquence ou de concaténer 2 
séquences.<br>
Supposons que <span style="font-family:monospace">S</span> soit la séquence <span style="font-family:monospace">(1,2,3)</span>(<span style="font-family:monospace">S:=1,2,3</span>) et 
que <span style="font-family:monospace">L</span> soit la liste <span style="font-family:monospace">[1,2,3]</span> (<span style="font-family:monospace">L:=[1,2,3]</span>).<br>
Pour modifier une séquence il suffit par exemple, décrire :<br>
<span style="font-family:monospace">S:=S,4</span> (resp <span style="font-family:monospace">S:=S,4,5,6</span> ou <span style="font-family:monospace">S:=S,(4,5,6)</span>) pour que
<span style="font-family:monospace">S</span> soit la séquence <span style="font-family:monospace">(1,2,3,4)</span> (resp <span style="font-family:monospace">(1,2,3,4,5,6)</span><br>
alors que pour modifier une liste il faut écrire :<br>
<span style="font-family:monospace">L:=append(L,4)</span> (resp <span style="font-family:monospace">L:=append(L,4,5,6)</span> ou <span style="font-family:monospace">L:=concat(L,4,5,6)</span> 
ou <span style="font-family:monospace">L:=concat(L,[4,5,6])</span>) pour que <span style="font-family:monospace">L</span> soit la liste <span style="font-family:monospace">[1,2,3,4]</span> 
(resp <span style="font-family:monospace">[1,2,3,4,5,6]</span>).<br>
<span style="font-weight:bold">Mais attention !</span><br>
<span style="font-family:monospace">L:=append(L,[4,5,6])</span> renvoie <span style="font-family:monospace">[1,2,3,[4,5,6]]</span><br>
Pour les chaînes de caractères, supposons que <span style="font-family:monospace">s</span> soit la 
chaîne <span style="font-family:monospace">"abc"</span> (<span style="font-family:monospace">s:="abc"</span>), on peut écrire pour lui rajouter 
<span style="font-family:monospace">"def"</span> :<br>
<span style="font-family:monospace">s:=append(s,"def")</span> ou <span style="font-family:monospace">s:=concat(s,"def")</span> ou <span style="font-family:monospace">s:=s+"def")</span><br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">s:="abc";s:=s+"def"
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</li><li class="li-itemize"><span style="font-family:monospace">prepend</span><br>
<span style="font-family:monospace">prepend(L,a)</span> renvoie la liste où l’élément <span style="font-family:monospace">a</span> à été
rajouté au début de la liste <span style="font-family:monospace">L</span>.<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">prepend([1,2,3],0)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,2,3]; prepend(L,0); L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Attention</span><br>
Pour ajouter <span style="font-family:monospace">0</span> au début de la liste <span style="font-family:monospace">L</span> on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,2,3]; L:=prepend(L,0); L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
ou<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,2,3]; L.prepend(0); L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
</li><li class="li-itemize"><span style="font-family:monospace">concat</span><br>
<span style="font-family:monospace">concat(L1,L2)</span> renvoie la concaténation des deux listes <span style="font-family:monospace">L1</span> et 
<span style="font-family:monospace">L2)</span>.<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">concat([1,2,3],[4,5,6,7])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,2,3]; concat(L,[4,5,6,7]); L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Attention</span><br>
Pour ajouter <span style="font-family:monospace">4,5,6,7</span> à la fin de la liste <span style="font-family:monospace">L</span> on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,2,3]; L:=concat(L,[4,5,6,7]); L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
ou<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,2,3]; L.concat([4,5,6,7]); L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</li><li class="li-itemize"><span style="font-family:monospace">rotate</span><br>
<span style="font-family:monospace">rotate(L)</span> (resp <span style="font-family:monospace">rotate(L,n)</span>) renvoie la liste obtenue en mettant le dernier élément (resp la fin de la liste à partir du <span style="font-family:monospace">n</span>-ième 
élément) en premier (par défaut n=-1).<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">rotate([0,1,2,3])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3]; rotate(L)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Attention</span><br>
Pour modifier le contenu de <span style="font-family:monospace">L</span>, on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3]; L:=rotate(L); L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
ou<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3]; L.rotate(); L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">rotate([0,1,2,3],2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large"> L:=[0,1,2,3]; rotate(L,2); L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Attention</span><br>
Pour modifier le contenu de <span style="font-family:monospace">L</span>, on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3];L:=rotate(L,2);L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
ou<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3]; L.rotate(2);L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</li><li class="li-itemize"><span style="font-family:monospace">shift</span><br>
<span style="font-family:monospace">shift(L,n)</span> : si <span style="font-family:monospace">n&gt;0</span> on remplace les <span style="font-family:monospace">n</span> premiers 
éléments de la liste par des <span style="font-family:monospace">0</span> et on renvoie ces <span style="font-family:monospace">0</span> à la fin de
la liste,<br>
si <span style="font-family:monospace">n&lt;0</span> renvoie la liste obtenue en remplaçant les 
<span style="font-family:monospace">-n</span> derniers éléments de la liste par <span style="font-family:monospace">0</span> et on renvoie ces <span style="font-family:monospace">0</span> au début de la liste, puis on renvoie la liste ainsi obtenue.
(par défaut n=-1 ce qui signifie que le dernier élément de la liste est 
supprimé et on met un <span style="font-family:monospace">0</span> au début de la liste).
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">shift([1,2,3,4],-1),shift([1,2,3,4])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3];shift(L);shift(L,-2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">shift([1,2,3,4],-2);shift([1,2,3,4],2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3];shift(L,2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Attention</span><br>
Pour modifier le contenu de <span style="font-family:monospace">L</span>, on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3];L:=shift(L);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
ou<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3];L.shift();L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Pour modifier le contenu de <span style="font-family:monospace">L</span>, on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3];L:=shift(L,-2);L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
ou<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3];L.shift(-2);L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Pour modifier le contenu de <span style="font-family:monospace">L</span>, on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3];L:=shift(L,2);L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
ou<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3];L.shift(2);L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
</li><li class="li-itemize"><span style="font-family:monospace">suppress</span><br>
<span style="font-family:monospace">suppress(L,n)</span> renvoie <span style="font-family:monospace">L</span> sans son élément d’indice 
<span style="font-family:monospace">n</span>.<br>
On tape (attention les indices commencent à 0) :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">suppress([0,1,2,3],2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3];suppress(L,2);L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Attention</span><br>
Pour modifier le contenu de <span style="font-family:monospace">L</span>, on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3];L:=suppress(L,2);L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
ou<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[0,1,2,3];L.suppress(2);L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</li><li class="li-itemize"><span style="font-family:monospace">reverse</span><br>
<span style="font-family:monospace">reverse(L)</span> ou <span style="font-family:monospace">revlist(L)</span> renvoie la liste <span style="font-family:monospace">L</span> inversée.<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">reverse([1,2,3])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,2,3];reverse(L);L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Attention</span><br>
Pour modifier le contenu de <span style="font-family:monospace">L</span>, on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,2,3];L:=reverse(L);L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
ou<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,2,3];L.reverse();L
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</li></ul>
<!--TOC subsection id="sec18" Les booléens-->
<h3 id="sec18" class="subsection">2.1.4  Les booléens</h3><!--SEC END -->
<!--TOC subsubsection id="sec19" Définition-->
<h4 id="sec19" class="subsubsection">Définition</h4><!--SEC END --><p>
L’ensemble des booléens est un ensemble à 2 éléments :<br>
<span style="font-family:monospace">vrai</span> ou <span style="font-family:monospace">1</span> et <span style="font-family:monospace">faux</span> ou <span style="font-family:monospace">0</span>.<br>
Pour faire des tests, on utilise des opérateurs booléens.</p>
<!--TOC subsubsection id="sec20" Opérateur booléen infixé qui teste l’égalité <span style="font-family:monospace">==</span>-->
<h4 id="sec20" class="subsubsection">Opérateur booléen infixé qui teste l’égalité <span style="font-family:monospace">==</span></h4><!--SEC END --><p>
<a id="hevea_default26"></a>
Pour tester l’égalité entre deux objets (réels, entiers, expressions, 
listes..) on utilise l’opérateur <code>==</code>. Le test renvoie vrai si les
deux objets sont égaux, au sens où leur représentation informatique
est identique. Pour tester que deux expressions littérales
contenues dans les variables <code>a</code> et <code>b</code>
sont mathématiquement
équivalentes, il est parfois nécessaire de faire une commande explicite
de simplification, au lieu d’écrire <code>a==b</code> on écrit 
<code>simplify(a-b)==0</code>.</p><p><span style="font-weight:bold">Exemple :</span><br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a:=3;b:=5
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">b-a==0
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">b-a-2==0
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">(1+sqrt(2))^2==3+2*sqrt(2);simplify((1+sqrt(2))^2-3-2*sqrt(2))==0;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsubsection id="sec21" Les différentes significations des signes <span style="font-family:monospace">:=</span>, <span style="font-family:monospace">=</span>,<span style="font-family:monospace">==</span>, <span style="font-family:monospace">#=</span>-->
<h4 id="sec21" class="subsubsection">Les différentes significations des signes <span style="font-family:monospace">:=</span>, <span style="font-family:monospace">=</span>,<span style="font-family:monospace">==</span>, <span style="font-family:monospace">#=</span></h4><!--SEC END --><p><a id="hevea_default27"></a>
<span style="font-weight:bold">Attention </span>
</p><ul class="itemize"><li class="li-itemize">
Il ne faut pas confondre les différentes significations du signe 
<code>=</code><br>
Le signe <span style="font-family:monospace">:=</span> sert à stocker une valeur dans une variable, le
signe <span style="font-family:monospace">=</span> sert à définir une équation (ou à donner la valeur par
défaut d’un argument, cf. la section <a href="#sec%3Avaldef">2.2.4</a>).<br>
Le signe <span style="font-family:monospace">==</span> sert à tester l’égalité. C’est un opérateur booléen infixé. Il renvoie <span style="font-family:monospace">vrai</span> ou <span style="font-family:monospace">faux</span>.<br>
<br>
<span style="font-family:monospace">Xcas</span> accepte toutefois <span style="font-family:monospace">=</span> dans certaines situations non 
ambigües (affectation ou test d’égalité), par exemple :<br>
<span style="font-family:monospace">a=1;si a=2 alors vrai sinon faux fsi;a;</span> renvoie <span style="font-family:monospace">1=1,faux,1</span>.<br>
<span style="font-weight:bold">Remarque</span> <br>
En Python l’affectation se fait avec le signe <span style="font-family:monospace">=</span>, car Python ne gére pas 
les équations, 
c’est pourquoi dans <span style="font-family:monospace">Xcas</span> en syntaxe compatible Python, 
on utilisera le signe <span style="font-family:monospace">#=</span> pour définir une équation. 
Dans un interpréteur Python avec <span style="font-family:monospace">giacpy</span>, il faut utiliser la
commande préfixée <span style="font-family:monospace">equal</span>.
</li><li class="li-itemize"><span style="font-family:monospace">Xcas</span> travaille par défaut avec des nombres exacts donc :<br>
<span style="font-family:monospace">3+10</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">(-16)==3</span> renverra <span style="font-family:monospace">faux</span> ou <span style="font-family:monospace">false</span> car il compare 2 
nombres rationnels alors qu’avec un logiciel qui ne fait pas 
de calcul formel, il se peut que <span style="font-family:monospace">3+10</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">(-16)==3</span> renvoie <span style="font-family:monospace">vrai</span> 
ou <span style="font-family:monospace">true</span> car il compare 2 nombres flottants i.e. 2 nombres approchés.
</li></ul>
<!--TOC subsubsection id="sec22" Opérateur booléen infixé qui teste la non égalité <span style="font-family:monospace">!=</span>-->
<h4 id="sec22" class="subsubsection">Opérateur booléen infixé qui teste la non égalité <span style="font-family:monospace">!=</span></h4><!--SEC END --><p><a id="hevea_default28"></a>
Le signe <span style="font-family:monospace">!=</span> sert à tester la non égalité. <br>
C’est un opérateur booléen infixé. Il renvoie <span style="font-family:monospace">vrai</span> ou <span style="font-family:monospace">faux</span>.<br>
<span style="font-weight:bold">Exemple :</span><br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a:=3;b:=5
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">b!=a
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a+2!=b
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsubsection id="sec23" Opérateur booléen infixé qui teste l’inégalité <span style="font-family:monospace">&lt;, &gt;, &lt;=, &gt;=</span>-->
<h4 id="sec23" class="subsubsection">Opérateur booléen infixé qui teste l’inégalité <span style="font-family:monospace">&lt;, &gt;, &lt;=, &gt;=</span></h4><!--SEC END --><p><a id="hevea_default29"></a><a id="hevea_default30"></a><a id="hevea_default31"></a><a id="hevea_default32"></a>
Les signes <span style="font-family:monospace">&lt;, &gt;, &lt;=, &gt;=</span> servent à tester les inégalités. <br>
Ce sont des opérateurs booléens infixés. Ils renvoient <span style="font-family:monospace">vrai</span> ou 
<span style="font-family:monospace">faux</span>.<br>
<span style="font-weight:bold">Exemple :</span><br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a:=3;b:=5
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">b >= a
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a+2 > b
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a+2 >= b
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec24" Expressions, polynômes-->
<h3 id="sec24" class="subsection">2.1.5  Expressions, polynômes</h3><!--SEC END -->
<!--TOC subsubsection id="sec25" Simplification d’une expression avec <span style="font-family:monospace">normal</span>-->
<h4 id="sec25" class="subsubsection">Simplification d’une expression avec <span style="font-family:monospace">normal</span></h4><!--SEC END --><p><a id="hevea_default33"></a>
<a id="hevea_default34"></a><a id="hevea_default35"></a>
<span style="font-family:monospace">Xcas</span> renvoie le résultat d’un calcul littéral sans le simplifier 
(sauf pour les calculs dans les rationnels).<br>
Il faut utiliser la fonction <span style="font-family:monospace">normal</span> ou <span style="font-family:monospace">simplify</span>
pour obtenir un résulat simplifié.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">purge(x)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">(x^2+1)^2+(x^2-1)^2
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">normal((x^2+1)^2+(x^2-1)^2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsubsection id="sec26" Les polynômes-->
<h4 id="sec26" class="subsubsection">Les polynômes</h4><!--SEC END --><p>
Un polynôme à une indéterminée à coefficients dans <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Ropf;</mi></mrow><annotation encoding='application/x-tex'>\mathbb{R}</annotation></semantics></math> est 
déterminé par une 
séquence <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mi>n</mi></msub><mo>,</mo><mo>.</mo><mo>.</mo><mo>.</mo><mo>,</mo><msub><mi>a</mi> <mn>1</mn></msub><mo>,</mo><msub><mi>a</mi> <mn>0</mn></msub></mrow><annotation encoding='application/x-tex'>a_n,...,a_1,a_0</annotation></semantics></math> d’éléments de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Ropf;</mi></mrow><annotation encoding='application/x-tex'>\mathbb{R}</annotation></semantics></math>, c’est l’expression :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mi>n</mi></msub><msup><mi>x</mi> <mi>n</mi></msup><mo>+</mo><mo>.</mo><mo>.</mo><mo>.</mo><mo>+</mo><msub><mi>a</mi> <mn>1</mn></msub><mi>x</mi><mo>+</mo><msub><mi>a</mi> <mn>0</mn></msub></mrow><annotation encoding='application/x-tex'>a_nx^n+...+a_1x+a_0</annotation></semantics></math> (ou <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>0</mn></msub><mo>+</mo><msub><mi>a</mi> <mn>1</mn></msub><mi>x</mi><mo>+</mo><msub><mi>a</mi> <mn>2</mn></msub><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><mo>.</mo><mo>.</mo><mo>+</mo><msub><mi>a</mi> <mi>n</mi></msub><msup><mi>x</mi> <mi>n</mi></msup></mrow><annotation encoding='application/x-tex'>a_0+a_1x+a_2x^2+..+a_nx^n</annotation></semantics></math>).<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> est le degré du polynôme.<br>
On dit que l’on a écrit le polynôme selon les puissances décroissantes 
(ou croissantes).<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mi>n</mi></msub><mo>,</mo><mo>.</mo><mo>.</mo><msub><mi>a</mi> <mn>1</mn></msub><mo>,</mo><msub><mi>a</mi> <mn>0</mn></msub></mrow><annotation encoding='application/x-tex'>a_n,..a_1,a_0</annotation></semantics></math> sont les coefficients du polynôme et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> est la variable ou
l’indéterminée du polynôme.<br>
On notera l’ensemble des polynômes à une indéterminée <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> : <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Ropf;</mi><mo stretchy="false">[</mo><mi>x</mi><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>\mathbb{R}[x]</annotation></semantics></math>.</p><p>Un polynôme à 2 indéterminées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi></mrow><annotation encoding='application/x-tex'>y</annotation></semantics></math> à coefficients dans <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Ropf;</mi></mrow><annotation encoding='application/x-tex'>\mathbb{R}</annotation></semantics></math> est déterminé par 
une séquence <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>A</mi> <mi>n</mi></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><mo>,</mo><mo>.</mo><mo>.</mo><mo>.</mo><mo>,</mo><msub><mi>A</mi> <mn>1</mn></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><mo>,</mo><msub><mi>A</mi> <mn>0</mn></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>A_n(y),...,A_1(y),A_0(y)</annotation></semantics></math> d’éléments de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Ropf;</mi><mo stretchy="false">[</mo><mi>y</mi><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>\mathbb{R}[y]</annotation></semantics></math>
et a pour expression :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>A</mi> <mi>n</mi></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><msup><mi>x</mi> <mi>n</mi></msup><mo>+</mo><mo>.</mo><mo>.</mo><mo>.</mo><mo>+</mo><msub><mi>A</mi> <mn>1</mn></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><mi>x</mi><mo>+</mo><msub><mi>A</mi> <mn>0</mn></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>A_n(y)x^n+...+A_1(y)x+A_0(y)</annotation></semantics></math> (ou <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>A</mi> <mn>0</mn></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>A</mi> <mn>1</mn></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><mi>x</mi><mo>+</mo><msub><mi>A</mi> <mn>2</mn></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><mo>.</mo><mo>.</mo><mo>+</mo><msub><mi>A</mi> <mi>n</mi></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><msup><mi>x</mi> <mi>n</mi></msup></mrow><annotation encoding='application/x-tex'>A_0(y)+A_1(y)x+A_2(y)x^2+..+A_n(y)x^n</annotation></semantics></math>)<br>
Par exemple :<br>
si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>A</mi> <mn>0</mn></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><mo>=</mo><msup><mi>y</mi> <mn>3</mn></msup><mo>&minus;</mo><mn>2</mn><mo>,</mo><msub><mi>A</mi> <mn>1</mn></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><mo>=</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mn>2</mn><mi>y</mi><mo>,</mo><msub><mi>A</mi> <mn>2</mn></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><mo>=</mo><msup><mi>y</mi> <mn>3</mn></msup><mo>+</mo><mn>2</mn><mo>*</mo><mi>y</mi><mo>+</mo><mn>3</mn></mrow><annotation encoding='application/x-tex'>A_0(y)=y^3&#x2d;2,A_1(y)=&#x2d;2y,A_2(y)=y^3+2*y+3</annotation></semantics></math><br>
Le polynôme s’écrit :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>y</mi> <mn>3</mn></msup><mo>&minus;</mo><mn>2</mn><mo>&minus;</mo><mn>2</mn><mi>y</mi><mo>*</mo><mi>x</mi><mo>+</mo><mo stretchy="false">(</mo><msup><mi>y</mi> <mn>3</mn></msup><mo>+</mo><mn>2</mn><mo>*</mo><mi>y</mi><mo>+</mo><mn>3</mn><mo stretchy="false">)</mo><mo>*</mo><msup><mi>x</mi> <mn>2</mn></msup><mo>=</mo><msup><mi>x</mi> <mn>2</mn></msup><mo>*</mo><msup><mi>y</mi> <mn>3</mn></msup><mo>+</mo><mn>2</mn><mo>*</mo><msup><mi>x</mi> <mn>2</mn></msup><mo>*</mo><mi>y</mi><mo>+</mo><mn>3</mn><mo>*</mo><msup><mi>x</mi> <mn>2</mn></msup><mo>&minus;</mo><mn>2</mn><mo>*</mo><mi>x</mi><mo>*</mo><mi>y</mi><mo>+</mo><msup><mi>y</mi> <mn>3</mn></msup><mo>&minus;</mo><mn>2</mn></mrow><annotation encoding='application/x-tex'>y^3&#x2d;2&#x2d;2y*x+(y^3+2*y+3)*x^2=x^2*y^3+2*x^2*y+3*x^2&#x2d;2*x*y+y^3&#x2d;2</annotation></semantics></math><br>
Le degré par rapport à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> du polynôme de cet exemple et égal à 2.<br>
Le degré par rapport à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi></mrow><annotation encoding='application/x-tex'>y</annotation></semantics></math> du polynôme de cet exemple et égal à 3.</p>
<!--TOC subsubsection id="sec27" Coefficients et degré d’un polynôme-->
<h4 id="sec27" class="subsubsection">Coefficients et degré d’un polynôme</h4><!--SEC END --><p><a id="hevea_default36"></a><a id="hevea_default37"></a><a id="hevea_default38"></a><a id="hevea_default39"></a>
<span style="font-family:monospace">Xcas</span> représente les polynômes soit sous la forme d’une expression 
symbolique, soit comme la séquence des coefficients selon les puissances 
décroissantes (<span style="font-family:monospace">poly1[1,2,3]</span> i.e. <span style="font-family:monospace">[a2,a1,a0]:=[1,2,3]</span>).<br>
Par exemple, le polynôme <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><mn>2</mn><mi>x</mi><mo>+</mo><mn>3</mn></mrow><annotation encoding='application/x-tex'>x^2+2x+3</annotation></semantics></math> s’écrit:<br>
soit <span style="font-family:monospace">x</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+2x+3</span> où <span style="font-family:monospace">x</span> est l’indéterminée mais 
<span style="font-weight:bold">Attention</span> <span style="font-family:monospace">x</span> doit être une variable symbolique donc <span style="font-family:monospace">x</span> doit 
être purgée,<br>
 soit <span style="font-family:monospace">poly1[1,2,3]</span><br>
Les commandes <span style="font-family:monospace">symb2poly(x</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+2x+3)</span> et <span style="font-family:monospace">poly2symb([1,2,3],x)</span> 
passent d’une représentation à l’autre.
</p><ul class="itemize"><li class="li-itemize">
Pour avoir le degré d’une expression polynômiale par rapport à une 
variable, on utilise
l’instruction <span style="font-family:monospace">degree</span> qui renvoie le degré d’un polynôme (on peut
ajouter un 2ième argument si le polynôme est symbolique en une 
indéterminée
qui n’est pas <span style="font-family:monospace">x</span>).
</li><li class="li-itemize">Pour avoir les coefficients d’un polynôme par rapport à une variable
on utilise l’instruction <span style="font-family:monospace">symb2poly</span> qui renvoie la liste des coefficients 
d’un polynôme par rapport au 2ième argument (<span style="font-family:monospace">x</span> est la variable par 
défaut). Ainsi si <span style="font-family:monospace">L:=symb2poly(P(x))</span>, <span style="font-family:monospace">degree(P(x))</span> est égal à 
<span style="font-family:monospace">dim(L)-1</span>.<br>
La commande <span style="font-family:monospace">poly2symb</span> effectue le calcul inverse, ainsi :<br>
<span style="font-family:monospace">symb2poly(y</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+2y+3)</span> renvoie <span style="font-family:monospace">poly1[1,2,3]</span>.<br>
<span style="font-family:monospace">poly2symb([1,2,3],y)</span> renvoie <span style="font-family:monospace">(y+2)*y+3</span>.
</li><li class="li-itemize">Pour avoir le coefficient de degré donné d’un polynôme par rapport à 
une variable, on utilise l’instruction <span style="font-family:monospace">coeff</span>.
</li><li class="li-itemize">Exemples :

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">purge(x,y):;degree(x^2-2x*y+y^3-2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">degree(x^2-2x*y+y^3-2,x)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">degree(x^2-2x*y+y^3-2,y)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">symb2poly(x^2-2x*y+y^3-2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">symb2poly(x^2-2x*y+y^3-2,x)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">symb2poly(x^2-2x*y+y^3-2,y)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">coeff(x^2-2x*y+y^3-2,x,2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">coeff(x^2-2x*y+y^3-2,y,1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</li></ul>
<!--TOC subsection id="sec28" Connaître les types et les sous-types-->
<h3 id="sec28" class="subsection">2.1.6  Connaître les types et les sous-types</h3><!--SEC END --><p><a id="hevea_default40"></a><a id="hevea_default41"></a>
<a id="hevea_default42"></a><a id="hevea_default43"></a><a id="hevea_default44"></a><a id="hevea_default45"></a><a id="hevea_default46"></a><a id="hevea_default47"></a><a id="hevea_default48"></a><a id="hevea_default49"></a><a id="hevea_default50"></a>
<span style="font-weight:bold">Les types</span><br>
<span style="font-family:monospace">Xcas</span> sait reconnaître le type d’un objet.<br>
Pour avoir le type de l’objet <span style="font-family:monospace">a</span> ou le contenu d’une variable <span style="font-family:monospace">a</span>, on 
utilise <span style="font-family:monospace">type(a)</span>.<br>
Les types utilisés ici sont :<br>
<span style="font-family:monospace">real</span> ou <span style="font-family:monospace">1</span> ce qui signifie que <span style="font-family:monospace">a</span> contient un nombre flottant.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a:=3.14
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(a)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(a)+0
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">integer</span> ou <span style="font-family:monospace">2</span> ce qui signifie que <span style="font-family:monospace">a</span> contient un nombre 
entier,<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a:=2017
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(a)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(a)+0
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">rational</span> ou <span style="font-family:monospace">10</span> ce qui signifie que <span style="font-family:monospace">a</span> contient un nombre 
rationnel,<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a:=2/7
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(a)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(a)+0
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">func</span> ou <span style="font-family:monospace">13</span> ce qui signifie que <span style="font-family:monospace">a</span> est le nom d’une 
fonction,<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f(x):=2x+3
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(f)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(sin)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(sin)+0
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">vecteur</span> ou <span style="font-family:monospace">7</span> ce qui signifie que <span style="font-family:monospace">a</span> contient une liste,<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[2,24,1,15,5,10]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(L)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(L)+0
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">string</span> ou <span style="font-family:monospace">12</span> ce qui signifie que <span style="font-family:monospace">a</span> contient une 
chaîne de caractères,<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">s:="Bonjour"
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(s)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(s)+0
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">expression</span> ou <span style="font-family:monospace">8</span> ce qui signifie que <span style="font-family:monospace">a</span> contient une 
expression,<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a:=sqrt(2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(a)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(a)+0
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(f(x))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(f(x))+0
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">identifier</span> ou <span style="font-family:monospace">6</span> ce qui signifie que <span style="font-family:monospace">a</span> contient le nom d’une 
variable non affectée.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">purge(a)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(a)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">type(a)+0
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-weight:bold">Les sous-types</span><br>
Certains types de variables peuvent servir à plusieurs usages : par exemple
une liste peut représenter les coordonnées d’un point dans l’espace
ou les coefficients d’un polynôme ou un ensemble. <span style="font-family:monospace">Xcas</span> possède
une commande <span style="font-family:monospace">subtype</span> permettant de préciser le type d’une variable.
Pour avoir le sous-type de la variable <span style="font-family:monospace">a</span>, on utilise <span style="font-family:monospace">subtype(a)</span>.<br>
Par exemple si <span style="font-family:monospace">a</span> contient une liste,
<span style="font-family:monospace">subtype(a)</span> renvoie <span style="font-family:monospace">1</span> pour une séquence, <span style="font-family:monospace">2</span> pour un ensemble, 
<span style="font-family:monospace">10</span> pour un polynôme et <span style="font-family:monospace">0</span> sinon.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">subtype(1,2,3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">subtype(set[1,2,3])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">subtype(poly1[1,2,3])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">subtype([1,2,3])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec29" Les fonctions-->
<h2 id="sec29" class="section">2.2  Les fonctions</h2><!--SEC END --><p><a id="hevea_default51"></a><a id="hevea_default52"></a><a id="hevea_default53"></a><a id="hevea_default54"></a><a id="hevea_default55"></a>
On distingue les fonctions ou commandes de <span style="font-family:monospace">Xcas</span> et les fonctions 
définies par l’utilisateur. Pour éviter le risque d’utiliser un nom
de fonction de <span style="font-family:monospace">Xcas</span>, il est conseillé de nommer les fonctions
utilisateurs en utilisant une majuscule comme première lettre.
Pour définir des fonctions (utilisateurs), 
on distinguera :
</p><ul class="itemize"><li class="li-itemize">
les fonctions définies par une expression algébrique.
Leur définition peut se faire simplement avec <span style="font-family:monospace">:=</span>
</li><li class="li-itemize">les fonctions qui nécessitent des calculs intermédiaires ou
des structures de contrôle
(test, boucle). Leur définition se fait au moyen d’un 
programme, en utilisant les instructions 
<span style="font-family:monospace">fonction...ffonction</span>, <span style="font-family:monospace">local</span> et <span style="font-family:monospace">retourne</span> et
les structures de contrôle qui seront détaillées au chapitre
<a href="#chap%3Aprog">3</a><sup><a id="text2" href="#note2">2</a></sup>, par exemple : <span style="font-family:monospace">"bon"</span>. 
</li></ul>
<!--TOC subsection id="sec30" Quelques fonctions algébriques de <span style="font-family:monospace">Xcas</span>-->
<h3 id="sec30" class="subsection">2.2.1  Quelques fonctions algébriques de <span style="font-family:monospace">Xcas</span></h3><!--SEC END --><p>
<span style="font-family:monospace">abs</span> est la fonction valeur absolue.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">abs(sqrt(2)-3/2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">ceil</span> est le plus grand entier <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&gt;</mi><mo>=</mo></mrow><annotation encoding='application/x-tex'>&amp;gt;=</annotation></semantics></math> à l’argument.<br>
<span style="font-family:monospace">cos</span> est la fonction cosinus.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cos(pi/6)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">floor</span> est la partie entière i.e.le plus grand entier <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&lt;</mi><mo>=</mo></mrow><annotation encoding='application/x-tex'>&amp;lt;=</annotation></semantics></math> à 
l’argument.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">floor(-2.42)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">floor(2.42)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">frac</span> est la partie fractionnaire d’un réel.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">frac(3/2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">frac(2.42)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">max</span> est la fonction maximum pour une séquence de nombres réels.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">max(sqrt(2),3,5,sqrt(26))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">min</span> est la fonction minimum pour une séquence de nombres réels.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">min(sqrt(2),3,5,sqrt(26))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<code><span style="font-family:monospace">^</span></code> est la fonction puissance.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">2^10
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">round</span> est la fonction qui arrondit un réel en l’entier (resp le décimal) le plus proche.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">round(-2.42)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">round(-2.42,1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">round(sqrt(2),4)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">sign</span> est la fonction signe de l’argument et renvoie -1, 0 ou +1.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">sign(-4)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">sign(4-4)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">sign(4)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">sin</span> est la fonction sinus.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">sin(pi/3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">sqrt</span> est la racine carrée.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">sqrt(2)^2
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">(sqrt(3)+1)*(sqrt(3)-1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">normal((sqrt(3)+1)*(sqrt(3)-1))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">tan</span> est la fonction tangente.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">tan(pi/4)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec31" Quelques fonctions aléatoires de <span style="font-family:monospace">Xcas</span>-->
<h3 id="sec31" class="subsection">2.2.2  Quelques fonctions aléatoires de <span style="font-family:monospace">Xcas</span></h3><!--SEC END --><p><a id="hevea_default56"></a><a id="hevea_default57"></a><a id="hevea_default58"></a><a id="hevea_default59"></a><a id="hevea_default60"></a><a id="hevea_default61"></a><a id="hevea_default62"></a><a id="hevea_default63"></a><a id="hevea_default64"></a></p><p>Nous donnons ci-après les fonctions aléatoires les plus fréquentes : pour 
des raisons de compatibilité avec le langage <span style="font-family:monospace">Python</span> chacune des fonctions 
ci-dessous peuvent être préfixée par <span style="font-family:monospace">random.</span> (par exemple on peut 
écrire <span style="font-family:monospace">random.randint()</span> ou <span style="font-family:monospace">randint()</span>)</p><p><span style="font-family:monospace">srand randseed RandSeed</span><br>
<span style="font-family:monospace">srand</span> ou <span style="font-family:monospace">randseed</span> initialise la suite des nombres aléatoires : 
<span style="font-family:monospace">srand</span> ou <span style="font-family:monospace">randseed</span>renvoie un entier qui a servi à cette 
initialisation.<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">srand
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-family:monospace">RandSeed</span><br>
<span style="font-family:monospace">RandSeed(n)</span> initialise les nombres aléatoires selon la valeur de 
l’entier <span style="font-family:monospace">n</span>.<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">RandSeed(321)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-family:monospace">random rand</span><br>
<span style="font-family:monospace">random()</span> ou <span style="font-family:monospace">rand()</span> renvoie un nombre réel 
(pseudo)-aléatoire de l’intervalle semi-ouvert <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mn>0</mn><mo>,</mo><mn>1</mn><mo stretchy="false">[</mo></mrow><annotation encoding='application/x-tex'>[0,1[</annotation></semantics></math>.<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">random()
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-family:monospace">choice</span><br>
<span style="font-family:monospace">choice(L)</span> ou <span style="font-family:monospace">random(L)</span> ou <span style="font-family:monospace">rand(L)</span> renvoie un élément
tiré au hasard parmi les éléments de la liste <span style="font-family:monospace">L</span>.<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">choice([1,2,3,4,5,6])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-family:monospace">randint</span><br>
<span style="font-family:monospace">randint(a,b)</span> renvoie un nombre entier (pseudo)-aléatoire 
compris entre <span style="font-family:monospace">a</span> et <span style="font-family:monospace">b</span> (bornes incluses).<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">randint(1,10)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-family:monospace">shuffle</span><br>
<span style="font-family:monospace">shuffle(L)</span> applique une permutation aléatoire à la liste <span style="font-family:monospace">L</span>.<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">shuffle([1,2,3,4,5,6])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-family:monospace">sample</span> ou <span style="font-family:monospace">rand</span><br>
<span style="font-family:monospace">sample(L,n)</span> ou <span style="font-family:monospace">rand(n,L)</span> renvoie, si <span style="font-family:monospace">n&lt;=size(L)</span>, <span style="font-family:monospace">n</span> 
éléments tirés, au hasard, sans remise parmi les éléments de la 
liste <span style="font-family:monospace">L</span> et sinon renvoie une erreur. <br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">sample([1,2,3,4,5,6,7,8,9,10],3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Remarque</span> <span style="font-family:monospace">sample(L,len(L))</span> ou <span style="font-family:monospace">rand(dim(L),L)</span> est identique 
à <span style="font-family:monospace">shuffle(L)</span>.</p><p>On tape en syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction testrand()
  local L1,L2,L3,n1,n2,a1,a2;
  n1:=random();
  n2:=random();
  a1:=randint(1,10);
  a2:=randint(1,10)
  L1:=sample([1,2,3,4,5,6],3);
  L2:=sample([1,2,3,4,5,6],3);
  L3:=shuffle([1,2,3,4,5,6]);
  return n1,n2,a1,a2,L1,L2,L3;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">testrand()
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>On tape en syntaxe Python :

</p><pre class="verbatim">def testrand() :
    # local L1,L2,L3,n1,n2,a1,a2
    n1=random.random()
    n2=random.random()
    a1=random.randint(1,10)
    a2=randint(1,10)
    L1=random.sample([1,2,3,4,5,6],3)
    L2=random.sample([1,2,3,4,5,6],3)
    L3=shuffle([1,2,3,4,5,6])
    return n1,n2,a1,a2,L1,L2,L3 
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">testrand()
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec32" Définition d’une fonction algébrique d’une variable-->
<h3 id="sec32" class="subsection">2.2.3  Définition d’une fonction algébrique d’une variable</h3><!--SEC END --><p><a id="hevea_default65"></a><a id="hevea_default66"></a>
<span style="font-weight:bold">Exemple :</span><br>
On veut définir la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>f</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>f_1</annotation></semantics></math> définie pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>&Element;</mo><mi>&Ropf;</mi></mrow><annotation encoding='application/x-tex'>x \in \mathbb{R}</annotation></semantics></math>, par 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>f</mi> <mn>1</mn></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>f_1(x)=x^2+1</annotation></semantics></math>.<br>
 <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi></mrow><annotation encoding='application/x-tex'>f</annotation></semantics></math> est le nom de la fonction et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> est le nom de l’argument de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>f</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>f_1</annotation></semantics></math> (ici <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math>
est un réel), la valeur de la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>f</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>f_1</annotation></semantics></math> est <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>x^2+1</annotation></semantics></math>.<br>
<span style="font-weight:bold">Remarque</span> : En mathématique on dit que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> est une variable.<br>
 En syntaxe <span style="font-family:monospace">Xcas</span>, on tape simplement :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f1(x):=x^2+1;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
 <br>
On pourrait aussi définir <span style="font-family:monospace">f1</span> par un programme
avec <span style="font-family:monospace">fonction...ffonction</span> et <span style="font-family:monospace">retourne</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">fonction f1(x) retourne x^2+1; ffonction;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python<br>

</p><pre class="verbatim">def f1(x):
    return x^2+1
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f1(5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec33" Définition d’une fonction algébrique de 2 variables-->
<h3 id="sec33" class="subsection">2.2.4  Définition d’une fonction algébrique de 2 variables</h3><!--SEC END --><p><a id="hevea_default67"></a><a id="hevea_default68"></a><a id="hevea_default69"></a><a id="hevea_default70"></a><a id="hevea_default71"></a><a id="sec:valdef"></a>
<span style="font-weight:bold">Exemple</span> :<br>
On veut définir la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>f</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>f_2</annotation></semantics></math> définie pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy="false">)</mo><mo>&Element;</mo><msup><mi>&Ropf;</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>(x,y) \in \mathbb{R}^2</annotation></semantics></math>, 
par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>f</mi> <mn>2</mn></msub><mo stretchy="false">(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy="false">)</mo><mo>=</mo><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>y</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>f_2(x,y)=x^2+y^2</annotation></semantics></math>.<br>
 <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>f</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>f_2</annotation></semantics></math> est le nom de la fonction et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>f</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>f_2</annotation></semantics></math> a 2 arguments réels : <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>,</mo><mi>y</mi></mrow><annotation encoding='application/x-tex'>x,y</annotation></semantics></math> (en 
mathématique on dit que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>,</mo><mi>y</mi></mrow><annotation encoding='application/x-tex'>x,y</annotation></semantics></math> sont les variables de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>f</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>f_2</annotation></semantics></math>). La valeur 
de la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>f</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>f_2</annotation></semantics></math> est <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>y</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>x^2+y^2</annotation></semantics></math>.<br>
On tape simplement :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f2(x,y):=x^2+y^2
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Ou on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">fonction f2(x,y) retourne x^2+y^2; ffonction
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Valeur par défaut d’une variable</span><br>
On peut définir la <span style="font-weight:bold">valeur par défaut</span> de la variable <span style="font-family:monospace">y</span> et ainsi
donner le même nom <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi></mrow><annotation encoding='application/x-tex'>f</annotation></semantics></math> aux 2 fonctions <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>f</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>f_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>f</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>f_2</annotation></semantics></math> définies 
précédement.<br>
Ainsi la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi></mrow><annotation encoding='application/x-tex'>f</annotation></semantics></math> sera définie par :<br>
si elle a une variable <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> alors <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>f(x)=x^2+1</annotation></semantics></math> et <br>
si elle a 2 variables <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>,</mo><mi>y</mi></mrow><annotation encoding='application/x-tex'>x,y</annotation></semantics></math> alors <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy="false">)</mo><mo>=</mo><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>y</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>f(x,y)=x^2+y^2</annotation></semantics></math>.<br>
En syntaxe <span style="font-family:monospace">Xcas</span>, on tape alors simplement :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f(x,y=1):=x^2+y^2
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Ou on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">fonction f(x,y=1) retourne x^2+y^2;ffonction
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f(3,4)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f(3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python:<br>

</p><pre class="verbatim">def f(x,y=1) : 
    return x^2+y^2;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f(3,4)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f(3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Autre exemple</span> :<br>
On veut définir la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> définie pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo stretchy="false">)</mo><mo>&Element;</mo><msup><mi>&Nopf;</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>(a,b) \in \mathbb{N}^2</annotation></semantics></math> par 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo stretchy="false">)</mo><mo>=</mo><mi>q</mi><mo>,</mo><mi>r</mi></mrow><annotation encoding='application/x-tex'>g(a,b)=q,r</annotation></semantics></math> où <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>q</mi><mo>,</mo><mi>r</mi></mrow><annotation encoding='application/x-tex'>q,r</annotation></semantics></math> désigne le quotient et le reste de la division 
euclidienne de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math>.<br>
On tape simplement :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">g(a,b):=iquorem(a,b);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
ou bien avec <span style="font-family:monospace">fonction...ffonction</span> et <span style="font-family:monospace">retourne</span> : <br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">fonction g(a,b) retourne iquorem(a,b); ffonction;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> est le nom de la fonction, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>,</mo><mi>b</mi></mrow><annotation encoding='application/x-tex'>a,b</annotation></semantics></math> sont les noms des arguments de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> (<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> et
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> sont des entiers) et <span style="font-family:monospace">iquorem</span> renvoie le quotient et le reste de la 
division euclidienne de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> sous la forme d’une liste.<br>
On a aussi les instructions :<br>
<span style="font-family:monospace">iquo(a,b)</span> qui renvoie le quotient de la division euclidienne de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> par 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math>.<br>
<span style="font-family:monospace">irem(a,b)</span> qui renvoie le reste de la division euclidienne de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math>.<br>
et on a donc <span style="font-family:monospace">iquorem(a,b)</span> est identique à <span style="font-family:monospace">[iquo(a,b),irem(a,b)]</span>.<br>
<br><textarea onkeypress="UI.ckenter(event,this,2)" 
style="width:400px;font-size:large">g(25,3) 
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value); tmp=UI.latexeval(tmp);nextSibling.innerHTML='&nbsp;'+tmp; if (UI.usemathjax) MathJax.Hub.Queue(['Typeset',MathJax.Hub,nextSibling])">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec34" Définition d’une fonction algébrique 
sans lui donner un nom-->
<h3 id="sec34" class="subsection">2.2.5  Définition d’une fonction algébrique 
sans lui donner un nom</h3><!--SEC END --><p><a id="hevea_default72"></a><a id="hevea_default73"></a>
On peut définir une fonction sans la nommer, cela permet de la
passer en argument d’une autre commande (par exemple une commande
de recherche de racines par dichotomie).<br>
En syntaxe <span style="font-family:monospace">Xcas</span><br>
Par exemple pour définir la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>&minus;</mo><mi>&gt;</mi><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>x&#x2d;&amp;gt;x^2+1</annotation></semantics></math>, on écrit simplement :<br>
<span style="font-family:monospace">x-&gt;x</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+1</span>.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">x->x^2+1
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On tape pour avoir la valeur de cette fonction en <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>=</mo><mn>5</mn></mrow><annotation encoding='application/x-tex'>x=5</annotation></semantics></math> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">(x->x^|2+1)(5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-family:monospace">(x-&gt;x</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+1)(5)</span><br>
Si on veut donner un nom à la fonction, on tape :<br>
<span style="font-family:monospace">f(x):=x</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+1</span><br>
 puis, on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large"> f(5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

En syntaxe à la <span style="font-family:monospace">Python</span><br>
Par exemple pour définir la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>&minus;</mo><mi>&gt;</mi><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>x&#x2d;&amp;gt;x^2+1</annotation></semantics></math>, on écrit :<br>
<span style="font-family:monospace">lambda x : x*x+1</span>.<br>
Le logiciel <span style="font-family:monospace">Xcas</span> le traduit en <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>&minus;</mo><mi>&gt;</mi><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>x&#x2d;&amp;gt;x^2+1</annotation></semantics></math>.<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">(lambda x : x*x+1)(5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Si on veut donner un nom à la fonction, on tape :<br>

</p><pre class="verbatim">def f(x):
    return x*x+1
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


puis, on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f(5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-weight:bold">Remarque : il n’y a pas de risques de confusion !</span> <br>
Si vous avez une variable <span style="font-family:monospace">lambda</span> qui est affectée, l’écriture :<br>
<span style="font-family:monospace">(lambda x : x*x+1)(5)</span>, ne modifie pas cette variable.<br>
On tape pour définir la fonction <span style="font-family:monospace">lambda</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">lambda(x):=x+1
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On tape pour avoir la valeur de la fonction <span style="font-family:monospace">lambda</span> en <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>=</mo><mn>5</mn></mrow><annotation encoding='application/x-tex'>x=5</annotation></semantics></math> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">lambda(5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On tape pour définir une fonction sans nom :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">lambda x : x*x+1
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On tape pour avoir sa valeur en <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>=</mo><mn>5</mn></mrow><annotation encoding='application/x-tex'>x=5</annotation></semantics></math> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">(lambda x : x*x+1)(5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec35" Définition d’une fonction algébrique par morceaux avec <span style="font-family:monospace">quand</span>-->
<h3 id="sec35" class="subsection">2.2.6  Définition d’une fonction algébrique par morceaux avec <span style="font-family:monospace">quand</span></h3><!--SEC END --><p><a id="hevea_default74"></a><a id="hevea_default75"></a>
<span style="font-family:monospace">quand</span> a 3 arguments : une condition (même symbolique) et 2 expressions : <br>
<span style="font-family:monospace">quand(Cond,Expr1,Expr2)</span><br>
Si la condition <span style="font-family:monospace">Cond</span> est vraie alors <span style="font-family:monospace">quand</span> renvoie <span style="font-family:monospace">Expr1</span>,
si la condition <span style="font-family:monospace">Cond</span> est fausse alors <span style="font-family:monospace">quand</span> renvoie <span style="font-family:monospace">Expr2</span>.</p><p>Exemple : écriture alternative pour la fonction <span style="font-family:monospace">Abs1</span> 
définie par <span style="font-family:monospace">Abs1</span><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mo stretchy="false">&vert;</mo><mi>x</mi><mo>&minus;</mo><mn>1</mn><mo stretchy="false">&vert;</mo><mo>&minus;</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>(x)=|x&#x2d;1|&#x2d;1</annotation></semantics></math>, on a :
</p><ul class="itemize"><li class="li-itemize">
si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mi>&gt;</mi><mn>1</mn></mrow><annotation encoding='application/x-tex'>x&amp;gt;1</annotation></semantics></math> on a <span style="font-family:monospace">Abs1</span><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mi>x</mi><mo>&minus;</mo><mn>1</mn><mo>&minus;</mo><mn>1</mn><mo>=</mo><mi>x</mi><mo>&minus;</mo><mn>2</mn></mrow><annotation encoding='application/x-tex'>(x)=x&#x2d;1&#x2d;1=x&#x2d;2</annotation></semantics></math>
</li><li class="li-itemize">si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>&leq;</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>x \leq 1</annotation></semantics></math> on a <span style="font-family:monospace">Abs1</span><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mi>x</mi><mo>+</mo><mn>1</mn><mo>&minus;</mo><mn>1</mn><mo>=</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mi>x</mi></mrow><annotation encoding='application/x-tex'>(x)=&#x2d;x+1&#x2d;1=&#x2d;x</annotation></semantics></math>
</li></ul><p>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Abs1(x):= quand(x > 1, x-2,-x);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
ou bien avec <span style="font-family:monospace">fonction...ffonction</span> et <span style="font-family:monospace">retourne</span> : <br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">fonction Abs1(x) retourne quand(x > 1,x-2,-x); ffonction;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Abs1(1/2),Abs1(1),Abs1(3/2),Abs1(-2),Abs1(2) 
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">plotfunc(Abs1(x),x=-5..7)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-weight:bold">Remarque différence entre </span><span style="font-weight:bold"><span style="font-family:monospace">ifte</span></span><span style="font-weight:bold"> et </span><span style="font-weight:bold"><span style="font-family:monospace">quand</span></span><br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f(x):=ifte(x>0,1,0);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f(3),f(-2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f(x)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Pourquoi une erreur ?<br>
Ici <span style="font-family:monospace">x</span> n’a pas de valeur : avec <span style="font-family:monospace">ifte</span> ou <span style="font-family:monospace">if then else end_if</span> 
il faut que la variable <span style="font-family:monospace">x</span> soit affectée pour pouvoir tester la 
condition (quand on définit une fonction ce qui suit le := n’est pas 
évalué donc la définition de <span style="font-family:monospace">f(x)</span> ne pose pas de problème).<br>
Pour la définition de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> avec <span style="font-family:monospace">when....</span>, la variable <span style="font-family:monospace">x</span> n’a pas
besoin dêtre affectée. Il n’y a donc pas d’erreur.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">g(x):=quand(x>0,1,0)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">g(3),g(-2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">g(x)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--BEGIN NOTES chapter-->
<hr class="footnoterule"><dl class="thefootnotes"><dt class="dt-thefootnotes">
<a id="note1" href="#text1">1</a></dt><dd class="dd-thefootnotes"><div class="footnotetext">En toute rigueur ce sont des nombres écrits en base 2 et non en base 10 mais on peut l’ignorer au niveau du lycée</div></dd><dt class="dt-thefootnotes"><a id="note2" href="#text2">2</a></dt><dd class="dd-thefootnotes"><div class="footnotetext">On peut utiliser la syntaxe à la <span style="font-family:monospace">Python</span> au 
sein de <span style="font-family:monospace">Xcas</span>, mais il faut déclarer les variables locales 
avec <span style="font-family:monospace"># local</span> (bien mettre un espace entre <span style="font-family:monospace">#</span> et <span style="font-family:monospace">local</span>) et 
n’utiliser que <span style="font-family:monospace">"</span> (et non <span style="font-family:monospace">’</span>) comme délimiteur de chaînes de 
caractères.</div></dd></dl>
<!--END NOTES-->
<!--TOC chapter id="sec36" Les instructions de programmation sur des exemples-->
<h1 id="sec36" class="chapter">Chapitre 3  Les instructions de programmation sur des exemples</h1><!--SEC END --><p> <a id="chap:prog"></a>
On donne ici les instructions en syntaxe Xcas, et en syntaxe Python.
</p>
<!--TOC section id="sec37" Commentaires et documentation.-->
<h2 id="sec37" class="section">3.1  Commentaires et documentation.</h2><!--SEC END -->
<!--TOC subsection id="sec38" Les commentaires dans un programme.-->
<h3 id="sec38" class="subsection">3.1.1  Les commentaires dans un programme.</h3><!--SEC END --><p><a id="hevea_default76"></a><a id="hevea_default77"></a>
Pour faire un commentaire, on écrit <span style="font-family:monospace">//</span> 
(ou <span style="font-family:monospace">#</span> si on a choisi la syntaxe Python), tout ce qui suit
est le commentaire. </p>
<!--TOC subsection id="sec39" Documenter une fonction avec la commande <span style="font-family:monospace">help</span>-->
<h3 id="sec39" class="subsection">3.1.2  Documenter une fonction avec la commande <span style="font-family:monospace">help</span></h3><!--SEC END --><p>
<a id="hevea_default78"></a>
<span style="font-family:monospace">help(nom_prog)</span> renvoie la 1ère ligne d’un programme
(hors commentaire). On peut donc indiquer à la personne utilisant un
programme ce que fait ce programme en écrivant
comme première ligne du programme une chaîne de caractères 
commentant la fonction.<br>
Exemple avec la fonction disciminant <span style="font-family:monospace">Delta(a,b,c)</span> qui calcule <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>b</mi> <mn>2</mn></msup><mo>&minus;</mo><mn>4</mn><mi>a</mi><mi>c</mi></mrow><annotation encoding='application/x-tex'>b^2&#x2d;4ac</annotation></semantics></math>.<br>
On tape en syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Delta(a,b,c) 
  // discriminant
  "calcule b^2-4ac"; 
  return b^2-4a*c;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">help(Delta)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On tape en syntaxe Python :

</p><pre class="verbatim">def Delta(a,b,c) :
    # discriminant
    "calcule b^2-4ac" 
    return b^2-4a*c
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">help(Delta)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec40" Stocker une valeur dans une variable avec <span style="font-family:monospace">:=</span>-->
<h2 id="sec40" class="section">3.2  Stocker une valeur dans une variable avec <span style="font-family:monospace">:=</span></h2><!--SEC END --><p><a id="hevea_default79"></a>
L’opérateur infixé <span style="font-family:monospace">:=</span> stocke le deuxième argument dans la variable 
donnée comme premier argument.<br>
On peut aussi stocker plusieurs valeurs dans plusieurs variables, par exemple :
En syntaxe <span style="font-family:monospace">Xcas</span> :<br>
<span style="font-family:monospace">a,b,c:=1,2,3</span> ou <span style="font-family:monospace">(a,b,c):=(1,2,3)</span> ou <span style="font-family:monospace">[a,b,c]:=[1,2,3]</span> <br>
En syntaxe Python :<br>
<span style="font-family:monospace">(a,b,c)=(1,2,3)</span> ou <span style="font-family:monospace">[a,b,c]=[1,2,3]</span></p><p><span style="font-weight:bold">Exemple :</span><br>
En syntaxe <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a:=3
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">b:=5
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a,b:=a+b,b-a
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a,b
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

En syntaxe Python :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a=3
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">b=5
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">(a,b)=(a+b,b-a)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a,b
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec41" Enlever une valeur stockée dans une variable avec <span style="font-family:monospace">purge</span>-->
<h2 id="sec41" class="section">3.3  Enlever une valeur stockée dans une variable avec <span style="font-family:monospace">purge</span></h2><!--SEC END --><p><a id="hevea_default80"></a><a id="hevea_default81"></a>
En syntaxe <span style="font-family:monospace">Xcas</span> : l’instruction <span style="font-family:monospace">purge(a)</span> permet d’enlever une valeur stockée dans la variable <span style="font-family:monospace">a</span>. La variable <span style="font-family:monospace">a</span> redevient une variable libre i.e. une variable non affectée.<br>
En syntaxe Python : l’instruction <span style="font-family:monospace">del a</span> permet d’enlever une 
valeur stockée dans la variable <span style="font-family:monospace">a</span>.<br>
<span style="font-weight:bold">Exemple :</span><br>
En syntaxe <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a:=3
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">b:=5
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">purge(a)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a,b
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a=3
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">b=5
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">del a
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a,b
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC section id="sec42" Suite d’instructions avec <span style="font-family:monospace">;</span> ou <span style="font-family:monospace">:;</span>-->
<h2 id="sec42" class="section">3.4  Suite d’instructions avec <span style="font-family:monospace">;</span> ou <span style="font-family:monospace">:;</span></h2><!--SEC END --><p><a id="hevea_default82"></a><a id="hevea_default83"></a>
En syntaxe <span style="font-family:monospace">Xcas</span>, pour effectuer une suite d’instructions, il suffit 
d’écrire ces instructions les unes à la suite des autres, en terminant 
chaque instruction par <code>;</code><br>
En syntaxe <span style="font-family:monospace">Xcas</span>, on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a:=2; b:=3; a*b;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python, on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">#
a=2 
b=3
a*b
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Notez le signe # qui
force l’interpréteur à passer en mode compatible Python.</p><p><span style="font-weight:bold">Remarque</span> :<br>
Lorsque la réponse est trop longue, on peut aussi utiliser <span style="font-family:monospace">:;</span> et 
on obtient <span style="font-family:monospace">Done</span> comme réponse.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a:=2:; b:=[1,2,3,4,5]:; a*b;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Notez qu’à l’intérieur d’un programme écrit en syntaxe Python
le <code>;</code> n’est pas nécessaire, il suffit de séparer les
instructions par un passage à la ligne, en respectant la même indentation
que la première instruction.</p>
<!--TOC section id="sec43" L’instruction <span style="font-family:monospace">retourne</span> ou <span style="font-family:monospace">return</span>-->
<h2 id="sec43" class="section">3.5  L’instruction <span style="font-family:monospace">retourne</span> ou <span style="font-family:monospace">return</span></h2><!--SEC END --><p><a id="hevea_default84"></a>
<a id="hevea_default85"></a>
L’instruction <span style="font-family:monospace">retourne</span> arrête immédiatement 
l’exécution du programme et renvoie la
valeur de l’instruction située après <span style="font-family:monospace">retourne</span>.</p><p><span style="font-weight:bold">Exemple :</span><br>
En syntaxe <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">fonction Delta(a,b,c) retourne b^2-4*a*c; ffonction;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">fonction Abs(x) 
si x > 0 alors retourne x;fsi;
retourne -x;
ffonction;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Delta(3,5,2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Abs(-3),Abs(3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

En syntaxe Python :<br>

</p><pre class="verbatim">def Delta(a,b,c) :
    return b^2-4*a*c
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



</p><pre class="verbatim">def Abs(x) :
    if x&gt;0 :
        return x
    return -x
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Delta(3,5,2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">(Abs(-3),Abs(3))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec44" L’instruction <span style="font-family:monospace">local</span>-->
<h2 id="sec44" class="section">3.6  L’instruction <span style="font-family:monospace">local</span></h2><!--SEC END --><p><a id="hevea_default86"></a><a id="hevea_default87"></a><a id="hevea_default88"></a>
<span style="font-weight:bold">Notion de variables locales:</span><br>
Supposons qu’on souhaite définir une fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>h</mi></mrow><annotation encoding='application/x-tex'>h</annotation></semantics></math> de deux variables <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>,</mo><mi>b</mi></mrow><annotation encoding='application/x-tex'>a,b</annotation></semantics></math>
(<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> sont des entiers) qui renvoie le numérateur et le dénominateur 
de la fraction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mfrac><mi>a</mi><mi>b</mi></mfrac></mrow><annotation encoding='application/x-tex'>\frac{a}{b}</annotation></semantics></math> simplifiée.<br>
Pour cela il faut diviser <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> par leur pgcd qui est <span style="font-family:monospace">gcd(a,b)</span>.</p><p>En syntaxe <span style="font-family:monospace">Xcas</span>, on peut écrire 
<span style="font-weight:bold">sans utiliser de variables locales</span> :<br>

</p><pre class="verbatim">fonction h0(a,b) 
  retourne (a/gcd(a,b),b/gcd(a,b)); 
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


En syntaxe Python

</p><pre class="verbatim">def h0(a,b) :
     return (a/gcd(a,b),b/gcd(a,b))
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


Mais on observe que cela nécessite de faire deux fois le calcul de 
<span style="font-family:monospace">gcd(a,b)</span>.</p><p>Pour éviter de faire faire à l’ordinateur deux fois le même
calcul, on va utiliser une variable locale <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi></mrow><annotation encoding='application/x-tex'>c</annotation></semantics></math> qui servira à 
stocker le calcul intermédiaire <span style="font-family:monospace">gcd(a,b)</span> 
avec l’instruction : <span style="font-family:monospace">c:=gcd(a,b)</span> (<span style="font-family:monospace">:=</span> est le 
symbole de l’affectation et <span style="font-family:monospace">gcd(a,b)</span> renvoie le pgcd de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math>).<br>
Cette variable n’est pas visible à l’extérieur du programme, les
modifications faites sur <span style="font-family:monospace">c</span> dans le programme n’ont aucun effet
sur la variable <span style="font-family:monospace">c</span> de la session.<br>
On écrit en syntaxe Xcas <span style="font-family:monospace">local c;</span> (ne pas oublier le 
<span style="font-family:monospace">;</span>). Le langage Python déclare implicitement les variables
d’une fonction comme variables locales, aussi en syntaxe Python dans
Xcas la déclaration de variables locales se fait par
un commentaire Python <span style="font-family:monospace"># local c;</span>.</p><p>D’où la définition de la fonction <span style="font-family:monospace">h</span> <span style="font-weight:bold">en utilisant des variables 
locales</span><br>
En syntaxe <span style="font-family:monospace">Xcas</span> :<br>

</p><pre class="verbatim">fonction h(a,b) 
  local c;
  c:=gcd(a,b);
  retourne (a/c,b/c); 
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a:=12;b:=22;c:=32;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">h0(25,15);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">h(25,15);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a,b,c
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On voit ainsi que les valeurs de <span style="font-family:monospace">a,b,c</span> n’ont pas été changées par
l’exécution des fonctions <span style="font-family:monospace">h0</span> ou <span style="font-family:monospace">h</span>.
En syntaxe Python :<br>

</p><pre class="verbatim">def h(a,b) :
    # local c
    c:=gcd(a,b);
    return (a/c),b/c)
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a:=12;b:=22;c:=32;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">h0(25,15);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">h(25,15);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">a,b,c
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Autre exemple :</span><br>
En syntaxe <span style="font-family:monospace">Xcas</span> :<br>

</p><pre class="verbatim">fonction Racine(a,b,c) 
  //racine x1,x2 de ax^2+bx+c=0
  "calcule b^2-4ac,x1,x2"; 
  local d,x1;x2;
  d=b^2-4a*c;
  x1=(-b+sqrt(d))/(2a);
  x2=(-b-sqrt(d))/(2a);
  retourne b^2-4a*c,x1,x2;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">help(Racine), Racine(2,1,-3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Racine(1,2,3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python :<br>

</p><pre class="verbatim">def Racine(a,b,c) :
    # racine x1,x2 de ax^2+bx+c=0
    # local d,x1,x2  
    "calcule b^2-4ac,x1,x2"; 
    d=b^2-4a*c
    x1=(-b+sqrt(d))/(2a)
    x2=(-b-sqrt(d))/(2a)
    retourne b^2-4a*c,x1,x2
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">help(Racine), Racine(2,1,-3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Racine(1,2,3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec45" L’instruction <span style="font-family:monospace">pour</span>-->
<h2 id="sec45" class="section">3.7  L’instruction <span style="font-family:monospace">pour</span></h2><!--SEC END --><p><a id="hevea_default89"></a><a id="hevea_default90"></a><a id="hevea_default91"></a>
<span style="font-weight:bold">Exemple de pour : la somme des nombres impairs</span><br>
On veut, dans cet exemple, définir une fonction <span style="font-family:monospace">Simpair(n)</span> d’une 
variable <span style="font-family:monospace">n</span> (<span style="font-family:monospace">n</span> est un entier) qui calcule la somme des <span style="font-family:monospace">n</span> 
premiers entiers impairs i.e. <span style="font-family:monospace">1+3+...+2n-1</span>.<br>
Pour cela, on utilise une variable locale <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi></mrow><annotation encoding='application/x-tex'>S</annotation></semantics></math> que l’on initialise à 0 :<br>
<span style="font-family:monospace">S:=0;</span><br>
puis on va faire <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> étapes en utilisant cette variable locale <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi></mrow><annotation encoding='application/x-tex'>S</annotation></semantics></math>.<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi></mrow><annotation encoding='application/x-tex'>S</annotation></semantics></math> va contenir successivement :<br>
étape 1 <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mo>:</mo><mo>=</mo><mi>S</mi><mo>+</mo><mo stretchy="false">(</mo><mn>2</mn><mo>*</mo><mn>1</mn><mo>&minus;</mo><mn>1</mn><mo stretchy="false">)</mo><mo>;</mo></mrow><annotation encoding='application/x-tex'>S:=S+(2*1&#x2d;1);</annotation></semantics></math> donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi></mrow><annotation encoding='application/x-tex'>S</annotation></semantics></math> contient 1 (0+1)<br>
étape 2 <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mo>:</mo><mo>=</mo><mi>S</mi><mo>+</mo><mo stretchy="false">(</mo><mn>2</mn><mo>*</mo><mn>2</mn><mo>&minus;</mo><mn>1</mn><mo stretchy="false">)</mo><mo>;</mo></mrow><annotation encoding='application/x-tex'>S:=S+(2*2&#x2d;1);</annotation></semantics></math> donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi></mrow><annotation encoding='application/x-tex'>S</annotation></semantics></math> contient 4 (1+3)<br>
...<br>
étape <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>k</mi></mrow><annotation encoding='application/x-tex'>k</annotation></semantics></math> <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mo>:</mo><mo>=</mo><mi>S</mi><mo>+</mo><mo stretchy="false">(</mo><mn>2</mn><mo>*</mo><mi>k</mi><mo>&minus;</mo><mn>1</mn><mo stretchy="false">)</mo><mo>;</mo></mrow><annotation encoding='application/x-tex'>S:=S+(2*k&#x2d;1);</annotation></semantics></math> donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi></mrow><annotation encoding='application/x-tex'>S</annotation></semantics></math> contient <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>1</mn><mo>+</mo><mn>3</mn><mo>+</mo><mo>.</mo><mn>.2</mn><mi>k</mi><mo>&minus;</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>1+3+..2k&#x2d;1</annotation></semantics></math><br>
...<br>
étape <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mo>:</mo><mo>=</mo><mi>S</mi><mo>+</mo><mn>2</mn><mo>*</mo><mi>n</mi><mo>&minus;</mo><mn>1</mn><mo>;</mo></mrow><annotation encoding='application/x-tex'>S:=S+2*n&#x2d;1;</annotation></semantics></math> donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi></mrow><annotation encoding='application/x-tex'>S</annotation></semantics></math> contient <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>1</mn><mo>+</mo><mn>3</mn><mo>+</mo><mo>.</mo><mn>.2</mn><mi>n</mi><mo>&minus;</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>1+3+..2n&#x2d;1</annotation></semantics></math><br>
En syntaxe <span style="font-family:monospace">Xcas</span>, on utilise une boucle <span style="font-family:monospace">pour</span> :<br>
<span style="font-family:monospace">pour k de 1 jusque n faire S:=S+2*k-1; fpour;</span><br>

En syntaxe Python, on utilise une boucle <span style="font-family:monospace">for</span> :
</p><pre class="verbatim">for k in range(1,n+1): 
    S:=S+2*k-1
</pre><p>
Dans cette boucle <span style="font-family:monospace">k</span> sera successivement égal à <span style="font-family:monospace">1, 2, 3,...n</span>.<br>
On dit que l’instruction <span style="font-family:monospace">S:=S+2*k-1</span> figurant dans le corps la boucle 
sera exécuté <span style="font-family:monospace">n</span> fois.<br>
<span style="font-weight:bold">Comment fonctionne cette boucle</span> <span style="font-family:monospace">pour</span> ?
</p><ul class="itemize"><li class="li-itemize">
la variable <span style="font-family:monospace">k</span> est initialisée à <span style="font-family:monospace">1</span>,
</li><li class="li-itemize">les instructions du corps de la boucle sont effectuées 
(ici il y en a une seule <span style="font-family:monospace">S:=S+2*k-1</span>),
</li><li class="li-itemize"><span style="font-family:monospace">k</span> est est incrémenté automatiquement de 1 (<span style="font-family:monospace">k:=k+1</span>),
</li><li class="li-itemize">le test <span style="font-family:monospace">k&lt;=n</span> est effectué :
si <span style="font-family:monospace">k&lt;=n</span> est vrai, les instructions du corps de la boucle sont à 
nouveau effectuées etc ... <br>
sinon on effectue les instructions qui suivent <span style="font-family:monospace">fpour</span>.
</li></ul><p>
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Simpair(n) 
  local S,k;
  S:=0; 
  pour k de 1 jusque n faire 
    S:=S+2*k-1; 
  fpour;
  retourne S; 
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Simpair(5),Simpair(6),Simpair(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

En syntaxe Python :

</p><pre class="verbatim">def Simpair(n):
    # local S,k
    S=0
    for k in range(1,n+1):
        S=S+2*k-1 
    return(S)
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Simpair(5),Simpair(6),Simpair(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On pourra vérifier le résultat, en utilisant la commande <span style="font-family:monospace">sum</span> de
<span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">sum(2*k-1,k=1..5),sum(2*k-1,k=1..6),sum(2*k-1,k=1..100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

<span style="font-weight:bold">Intermède mathématique</span><br>
1,3,5,7,9,11,
Au vue des résultats obtenus pouvez-vous deviner la valeur de 
<span style="font-family:monospace">s(100)</span> ?<br>
Pouvez-vous deviner et montrer la formule qui donne <span style="font-family:monospace">s(n)</span> ?<br>
On devine : <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>s</mi><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo><mo>=</mo><mn>1</mn><mo>+</mo><mn>3</mn><mo>+</mo><mo>.</mo><mo>.</mo><mn>.2</mn><mi>n</mi><mo>&minus;</mo><mn>1</mn><mo>=</mo><msup><mi>n</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>s(n)=1+3+...2n&#x2d;1=n^2</annotation></semantics></math><br>
On sait que pour tout <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>k</mi><mo>&Element;</mo><mi>&Nopf;</mi></mrow><annotation encoding='application/x-tex'>k \in \mathbb{N}</annotation></semantics></math> on a :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>k</mi> <mn>2</mn></msup><mo>&minus;</mo><mo stretchy="false">(</mo><mi>k</mi><mo>&minus;</mo><mn>1</mn><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>=</mo><mo stretchy="false">(</mo><mo stretchy="false">(</mo><mi>k</mi><mo>&minus;</mo><mn>1</mn><mo stretchy="false">)</mo><mo>+</mo><mn>1</mn><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>&minus;</mo><mo stretchy="false">(</mo><mi>k</mi><mo>&minus;</mo><mn>1</mn><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>=</mo><mn>2</mn><mi>k</mi><mo>&minus;</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>k^2&#x2d;(k&#x2d;1)^2=((k&#x2d;1)+1)^2&#x2d;(k&#x2d;1)^2=2k&#x2d;1</annotation></semantics></math> et<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>k</mi><mo>+</mo><mn>1</mn><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>k</mi> <mn>2</mn></msup><mo>=</mo><mn>2</mn><mi>k</mi><mo>+</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>(k+1)^2&#x2d;k^2=2k+1</annotation></semantics></math><br>
Donc :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>1</mn><mo>=</mo><msup><mn>1</mn> <mn>2</mn></msup><mo>&minus;</mo><msup><mn>0</mn> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>1=1^2&#x2d;0^2</annotation></semantics></math> (<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>k</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>k=1</annotation></semantics></math>),<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>3</mn><mo>=</mo><msup><mn>2</mn> <mn>2</mn></msup><mo>&minus;</mo><msup><mn>1</mn> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>3=2^2&#x2d;1^2</annotation></semantics></math> (<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>k</mi><mo>=</mo><mn>2</mn></mrow><annotation encoding='application/x-tex'>k=2</annotation></semantics></math>),<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>5</mn><mo>=</mo><msup><mn>3</mn> <mn>2</mn></msup><mo>&minus;</mo><msup><mn>2</mn> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>5=3^2&#x2d;2^2</annotation></semantics></math> (<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>k</mi><mo>=</mo><mn>3</mn></mrow><annotation encoding='application/x-tex'>k=3</annotation></semantics></math>),<br>
...<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>2</mn><mi>k</mi><mo>&minus;</mo><mn>1</mn><mo>=</mo><msup><mi>k</mi> <mn>2</mn></msup><mo>&minus;</mo><mo stretchy="false">(</mo><mi>k</mi><mo>&minus;</mo><mn>1</mn><msup><mo stretchy="false">)</mo> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>2k&#x2d;1=k^2&#x2d;(k&#x2d;1)^2</annotation></semantics></math><br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>2</mn><mi>k</mi><mo>+</mo><mn>1</mn><mo>=</mo><mo stretchy="false">(</mo><mi>k</mi><mo>+</mo><mn>1</mn><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>&minus;</mo><mo stretchy="false">(</mo><mi>k</mi><msup><mo stretchy="false">)</mo> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>2k+1=(k+1)^2&#x2d;(k)^2</annotation></semantics></math><br>
...<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>2</mn><mi>n</mi><mo>&minus;</mo><mn>1</mn><mo>=</mo><msup><mi>n</mi> <mn>2</mn></msup><mo>&minus;</mo><mo stretchy="false">(</mo><mi>n</mi><mo>&minus;</mo><mn>1</mn><msup><mo stretchy="false">)</mo> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>2n&#x2d;1=n^2&#x2d;(n&#x2d;1)^2</annotation></semantics></math><br>
Donc :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>s</mi><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo><mo>=</mo><mn>1</mn><mo>+</mo><mn>3</mn><mo>+</mo><mo>.</mo><mo>.</mo><mn>.2</mn><mi>n</mi><mo>&minus;</mo><mn>1</mn><mo>=</mo><mn>1</mn><mo>+</mo><mo stretchy="false">(</mo><mi>n</mi><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>=</mo><mn>1</mn><mo>+</mo><mo stretchy="false">(</mo><mn>4</mn><mo>&minus;</mo><mn>1</mn><mo stretchy="false">)</mo><mo>+</mo><mo stretchy="false">(</mo><mn>9</mn><mo>&minus;</mo><mn>4</mn><mo stretchy="false">)</mo><mo>.</mo><mo>.</mo><mo>.</mo><mo>+</mo><mo stretchy="false">(</mo><msup><mi>n</mi> <mn>2</mn></msup><mo>&minus;</mo><mo stretchy="false">(</mo><mi>n</mi><mo>&minus;</mo><mn>1</mn><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo stretchy="false">)</mo><mo>=</mo><msup><mi>n</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>s(n)=1+3+...2n&#x2d;1=1+(n)^2=1+(4&#x2d;1)+(9&#x2d;4)...+(n^2&#x2d;(n&#x2d;1)^2)=n^2</annotation></semantics></math><br>
En classe de terminales, on peut montrer cette formule par récurrence :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>s</mi><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>s(1)=1</annotation></semantics></math> si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>s</mi><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo><mo>=</mo><mo stretchy="false">(</mo><mi>n</mi><msup><mo stretchy="false">)</mo> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>s(n)=(n)^2</annotation></semantics></math> alors on a :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>s</mi><mo stretchy="false">(</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mi>s</mi><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo><mo>+</mo><mn>2</mn><mo stretchy="false">(</mo><mi>n</mi><mo>+</mo><mn>1</mn><mo stretchy="false">)</mo><mo>&minus;</mo><mn>1</mn><mo>=</mo><mo stretchy="false">(</mo><mi>n</mi><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>+</mo><mn>2</mn><mi>n</mi><mo>+</mo><mn>1</mn><mo>=</mo><mo stretchy="false">(</mo><mi>n</mi><mo>+</mo><mn>1</mn><msup><mo stretchy="false">)</mo> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>s(n+1)=s(n)+2(n+1)&#x2d;1=(n)^2+2n+1=(n+1)^2</annotation></semantics></math><br>
La formule est donc montrée par récurrence.</p>
<!--TOC section id="sec46" L’instruction <span style="font-family:monospace">pour</span> avec un <span style="font-family:monospace">pas</span>-->
<h2 id="sec46" class="section">3.8  L’instruction <span style="font-family:monospace">pour</span> avec un <span style="font-family:monospace">pas</span></h2><!--SEC END --><p><a id="hevea_default92"></a>
<span style="font-weight:bold">Exemple de pour avec un pas : la somme des nombres impairs </span><br>
Revenons à l’exemple précédent :<br>
 définir une fonction <span style="font-family:monospace">Simpair(n)</span> d’une variable <span style="font-family:monospace">n</span> (<span style="font-family:monospace">n </span> est 
un entier) qui calcule la somme : <span style="font-family:monospace">1+3+...+2n-1</span>.<br>
Avec la syntaxe <span style="font-family:monospace">Xcas</span>, on peut faire varier la variable <span style="font-family:monospace">k</span> avec un 
pas de 2, en commencant par 1 jusque <span style="font-family:monospace">2n-1</span>, on écrit :<br>
<span style="font-family:monospace">pour k de 1 jusque 2*n-1n pas 2 faire fpour;</span><br>
Dans ce cas la valeur de <span style="font-family:monospace">S</span> doit être augmentée à chaque pas de la 
valeur <span style="font-family:monospace">k</span>.<br>
On tape en syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Simpair1(n) 
 local S,k;
 S:=0; 
 pour k de 1 jusque 2*n-1 pas 2 faire 
   S:=S+k; 
 fpour;
 retourne S; 
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Simpair(5),Simpair(6),Simpair(7)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On tape en syntaxe Python :

</p><pre class="verbatim">def Simpair1(n):
    # local S,k
    S=0
    for k in range(1,2*n,2):
       S=S+k 
    return(S)
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Simpair(5),Simpair(6),Simpair(7)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-weight:bold">Autre exemple de pour avec un pas : le ticket de caisse</span><br>
On veut faire le programme d’un ticket de caisse lors d’achats dans 
un magasin qui ne pratique pas de réduction pour les achats en gros.<br>
Le programme du <span style="font-family:monospace">ticketcaisse</span> a comme paramètre une liste <span style="font-family:monospace">L</span> donnant
le nombre d’un même article suivi du prix de cet article, par exemple :<br>
 si <span style="font-family:monospace">L:=[2,24,1,15,5,10]</span> cela signifie qu’il y 2 articles à 24 euros, 1 
article à 15 euros et 5 articles à 10 euros.<br>
Soit <span style="font-family:monospace">n:=dim(L)</span>, dans cet esxemple <span style="font-family:monospace">n:=6</span>.<br>
On va parcourir la liste avec une variable <span style="font-family:monospace">k</span> : <span style="font-family:monospace">L[k]</span> sera le nombre 
d’articles ayant comme prix <span style="font-family:monospace">L[ k+1]</span> : il faut donc, dans cet exemple,
que <span style="font-family:monospace">k</span> prenne successivement pour valeur <span style="font-family:monospace">0, 2, 4=n-2</span>.<br>
Pour cela on initialise la somme à payer avec 0 : <span style="font-family:monospace">S:=0</span> puis<br>
 on utilise une boucle <span style="font-family:monospace">pour</span> avec un <span style="font-family:monospace">pas</span> de 2 :<br>
<span style="font-family:monospace">pour k de 0 jusque n-2 pas 2 faire S:=S+L[k]*L[k+1]; fpour;</span><br>
Dans cette boucle <span style="font-family:monospace">pour</span>, la variable <span style="font-family:monospace">k</span> est initialisée à 
<span style="font-family:monospace">0</span>, puis les instructions du corps de la boucle sont effectuées,
puis <span style="font-family:monospace">k</span> est incrémenté automatiquement de <span style="font-family:monospace">2</span> (<span style="font-family:monospace">k:=k+2</span>),<br>
puis on fait le test <span style="font-family:monospace">k&lt;=n-2</span> si oui les instructions du corps de la boucle 
sont à nouveau effectuées etc ... sinon on effectue les instructions qui 
suivent <span style="font-family:monospace">fpour</span>.<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Ticketcaisse(L) 
 local S,n,k;
 n:=dim(L);
 S:=0;
 pour k de 0 jusque n-2 pas 2 faire S:=S+L[k]*L[k+1]; fpour;
 retourne S; 
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketcaisse([1,12,3,5,2,8])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">1*12+3*5+2*8
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python :

</p><pre class="verbatim">def Ticketcaisse(L) :
    # local S,n,k
    n=size(L)
    S=0
    for k in range(0,n-1,2) :
        S=S+L[k]*L[k+1]
    retourne S 
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketcaisse([1,12,3,5,2,8])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">1*12+3*5+2*8
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec47" L’instruction <span style="font-family:monospace">si</span>-->
<h2 id="sec47" class="section">3.9  L’instruction <span style="font-family:monospace">si</span></h2><!--SEC END --><p><a id="hevea_default93"></a><a id="hevea_default94"></a><a id="hevea_default95"></a><a id="hevea_default96"></a><a id="hevea_default97"></a><a id="hevea_default98"></a><a id="sec:Prix"></a>
Lorsque l’on veut faire des instructions seulement si une condition est 
réalisée on utilise l’instruction <span style="font-family:monospace">si</span>.<br>
Cette instruction a 2 formes :<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :<br>
<span style="font-family:monospace">si &lt;condition&gt; alors &lt;instruction&gt;; fsi;</span><br>
et<br>
 <span style="font-family:monospace">si &lt;condition&gt; alors &lt;instruction1&gt;; sinon &lt;instruction2&gt; fsi;</span><br>
<span style="font-weight:bold">Comment fonctionne le test </span><span style="font-weight:bold"><span style="font-family:monospace">si ... alors ... fsi</span></span><span style="font-weight:bold"> ?</span>
</p><ul class="itemize"><li class="li-itemize">
On évalue la condition : une condition a 2 valeurs possibles <span style="font-family:monospace">vrai</span>
ou <span style="font-family:monospace">faux</span> c’est ce que l’on nomme un booléen,
</li><li class="li-itemize">Si la condition est vraie : on effectue les <span style="font-family:monospace">&lt;instruction&gt;</span>,
et si la condition est fausse : on ne fait rien,
</li><li class="li-itemize">On effectue ensuite les instructions qui suivent <span style="font-family:monospace">fsi;</span>.
</li></ul><p>
<span style="font-weight:bold">Comment fonctionne le test </span><span style="font-weight:bold"><span style="font-family:monospace">si ... alors ...sinon ... fsi</span></span><span style="font-weight:bold"> ?</span>
</p><ul class="itemize"><li class="li-itemize">
On évalue la condition : une condition a 2 valeurs possibles <span style="font-family:monospace">vrai</span>
ou <span style="font-family:monospace">faux</span> c’est ce que l’on nomme un booléen,
</li><li class="li-itemize">Si la condition est vraie : on effectue les <span style="font-family:monospace">&lt;instruction1&gt;</span> et si 
la condition est fausse : on effectue les <span style="font-family:monospace">&lt;instruction2&gt;</span>,
</li><li class="li-itemize">On effectue ensuite les instructions qui suivent <span style="font-family:monospace">fsi;</span>.
</li></ul><p>
En syntaxe Python :
</p><pre class="verbatim">if &lt;condition&gt; : 
   &lt;instruction&gt;
</pre><p>
et
</p><pre class="verbatim">if &lt;condition&gt; : 
   &lt;instruction1&gt;
else :
    &lt;instruction2&gt;
</pre><p><span style="font-weight:bold">Exemple de </span><span style="font-weight:bold"><span style="font-family:monospace">si alors fsi</span></span><span style="font-weight:bold"> : somme des nombres premiers &lt;= n</span><br>
<span style="font-weight:bold">Rappel</span> Un nombre premier est un entier <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> qui admet 2 diviseurs qui sont
1 et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math>, par exemple : 17 est un nombre premier et 1 4 ne sont pas des nombres 
premiers.<br>
On veut définir une fonction <span style="font-family:monospace">Spremier(n)</span> d’une variable <span style="font-family:monospace">n</span> 
(<span style="font-family:monospace">n </span> est un entier) qui calcule la somme des nombres premiers inférieurs
ou égaux à <span style="font-family:monospace">n</span> : <span style="font-family:monospace">2+3+5+7+11...+p</span> pour <span style="font-family:monospace">p</span> premier et 
<span style="font-family:monospace">p&lt;=n</span>. Pour cela on utilisera la fonction booléenne <span style="font-family:monospace">est_premier</span>
de <span style="font-family:monospace">Xcas</span> qui teste si un nombre entier est premier.<br>
Si <span style="font-family:monospace">est_premier(k)==vrai</span> et si <span style="font-family:monospace">k&lt;=n</span> alors la valeur de <span style="font-family:monospace">S</span> doit 
être augmentée de la valeur <span style="font-family:monospace">k</span>.<br>
Pour cela, on utilise une variable locale <span style="font-family:monospace">S</span> (la somme) et le test.<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :<br>
<span style="font-family:monospace">si est_premier(k) alors S:=S+k fsi;</span><br>
En syntaxe Python :<br>
</p><pre class="verbatim">if est_premier(k): 
    S:=S+k
</pre><p>À part le nombre 2 les nombres premiers sont impairs, donc on initialise 
<span style="font-family:monospace">S</span> à 2 puis, on fait varier <span style="font-family:monospace">k</span> de 3 jusque <span style="font-family:monospace">n</span> avec 
un pas de 2.<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Spremier(n) 
 local S,k;
 S:=2; 
 pour k de 3 jusque n pas 2 faire 
   si est_premier(k) alors S:=S+k fsi; 
 fpour;
 retourne S; 
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Spremier(10),Spremier(11),Spremier(20)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python :

</p><pre class="verbatim">def Spremier(n):
    # local S,k
    S=2
    for k in range(3,n+1,2):
        if est_premier(k) :
            S=S+k 
    return(S)
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Spremier(10),Spremier(11),Spremier(20)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Exercice : combien y-a-t-il de nombres premiers &lt;= n ?</span><br>
Modifier l’algorithme précédent pour définir la fonction 
<span style="font-family:monospace">Nbpremiers(n)</span> d’une variable <span style="font-family:monospace">n</span> (<span style="font-family:monospace">n </span> est un entier) qui 
calcule le nombre de nombres premiers qui sont inférieurs
ou égaux à <span style="font-family:monospace">n</span>.<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Nbpremiers(n) 
 local S,k,N;
 si n&lt;2 alors retourne 0 fsi;
 N:=1; 
 pour k de 3 jusque n pas 2 faire 
   si est_premier(k) alors N:=N+1 fsi; 
 fpour;
 retourne N; 
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Nbpremiers(10),Nbpremiers(20),Nbpremiers(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python :

</p><pre class="verbatim">def Nbpremiers(n):
    # local S,k,N
    if n&lt;2 :
        retourne 0
    N=1
    for k in range(3,n+1,2) :
        if est_premier(k) :
            N=N+1 
    return(N)
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Nbpremiers(10),Nbpremiers(20),Nbpremiers(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On pourra vérifier le résultat, en utilisant la commande <span style="font-family:monospace">nprimes</span> de
<span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">nprimes(10),nprimes(20),nprimes(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-weight:bold">Autre exemple du test </span><span style="font-weight:bold"><span style="font-family:monospace">si alors sinon fsi</span></span><span style="font-weight:bold"> : le ticket de caisse</span><br>
Dans un magasin on favorise les achats en gros :<br>
si un article <span style="font-family:monospace">a</span> a comme prix affiché <span style="font-family:monospace">P</span> euros, pour l’achat d’au 
moins 3 articles <span style="font-family:monospace">a</span>, vous avez une réduction de 10%.<br>
On veut, dans cet exemple, définir une fonction <span style="font-family:monospace">Prix</span> de 2 variables 
<span style="font-family:monospace">n</span> (<span style="font-family:monospace">n</span> est un entier) et <span style="font-family:monospace">P</span> un réel qui calcule le prix de 
<span style="font-family:monospace">n</span> article(s).<br>
Pour cela, on utilise :<br>
En syntaxe <span style="font-family:monospace">Xcas</span>, une variable locale <span style="font-family:monospace">S</span> qui sera la somme à 
débourser et le test :<span style="font-family:monospace">si alors sinon fsi;</span><br>
En syntaxe Python, on utilise le test :<br>
</p><pre class="verbatim">if &lt;condition&gt; :
    &lt;instruction1&gt; 
else : 
    &lt;instruction2&gt;
</pre><p>
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Prix(n,P) 
 local S;
 si n&gt;=3 alors S:=n*P*0.9; 
 sinon S:=n*P; fsi;
 retourne S;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Prix(3,8),Prix(2,8)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">3*8-3*8*0.1,2*8
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python :

</p><pre class="verbatim">def Prix(n,P) :
    # local S
    if n&gt;=3 :
        S:=n*P*0.9
    else :
        S:=n*P
    return S
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Prix(3,8),Prix(2,8)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">3*8-3*8*0.1,2*8
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
</p>
<!--TOC section id="sec48" Utiliser une fonction utilisateur dans un programme-->
<h2 id="sec48" class="section">3.10  Utiliser une fonction utilisateur dans un programme</h2><!--SEC END --><p>
<span style="font-weight:bold">Exemple : combien de nombres premiers dans [1,b],[b+1,2b]..[(p-1)b+pb] ?</span>
On veut définir une fonction <span style="font-family:monospace">Lnbpremiers(b,p)</span> de paramètres 2 entiers
qui renvoie une liste de <span style="font-family:monospace">p</span> entiers qui sont le nombre de nombres premiers 
compris entre 1 et <span style="font-family:monospace">b</span>,<span style="font-family:monospace">b+1</span> et <span style="font-family:monospace">2b</span> ... <span style="font-family:monospace">(p-1)*b+1</span> et 
<span style="font-family:monospace">p*b</span> de nombres premiers entre 0 et <span style="font-family:monospace">p*b=n</span>.<br>
Par exemple si <span style="font-family:monospace">b=10</span> et <span style="font-family:monospace">p=3</span> <span style="font-family:monospace">Lnbpremiers(b,p)</span> doit renvoyer:
<span style="font-family:monospace">[4,4,2]</span> puisque :<br>
entre 1 et 10 il y a 4 nombres premiers (2,3,5,7),<br>
entre 11 et 20 il y a 4 nombres premiers (11,13,17,19),<br>
entre 21 et 30 il y a 2 nombres premiers (23,29).<br>

Pour cela on utilisera la fonction utilisateur <span style="font-family:monospace">Nbpremiers</span> écrite 
précédemment en exercice.<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Lnbpremiers(b,p)
  local L,k,n1,n2,n;
  L:=NULL;
  n:=p*b;
  n1:=Nbpremiers(1);
  pour k de b jusque n pas b faire 
     n2:=Nbpremiers(k);
     L:=L,n2-n1;
     n1:=n2;
  fpour;
  retourne [L];
  ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Lnbpremiers(10,30)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Lnbpremiers(100,30)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python :

</p><pre class="verbatim">def Lnbpremiers(b,p) :
    # local L,k,n1,n2,n
    L=[]
    n=p*b
    n1=Nbpremiers(1)
    for k in range(b,n+1,b) : 
        n2=Nbpremiers(k)
        L.append(n2-n1)
        n1=n2
    return L;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Lnbpremiers(10,30)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Lnbpremiers(100,30)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<span style="font-weight:bold">Autre exemple : le ticket de caisse</span><br>
On veut faire le programme du ticket de caisse lorsque le magasin pratique 
l’achat en gros (la liste <span style="font-family:monospace">L</span> doit spécifier le nombre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> d’un même 
article de prix <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi></mrow><annotation encoding='application/x-tex'>P</annotation></semantics></math>).<br>
En utilisant la fonction <span style="font-family:monospace">Prix(n,P)</span> écrite précédemment (cf 
<a href="#sec%3APrix">3.9</a>), modifier le programme précédent lorsque le magasin 
pratique l’achat en gros.<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Ticketengros(L) 
 local S,n,k; 
 n:=dim(L);
 S:=0;
 pour k de 0 jusque n-2 pas 2 faire 
   S:=S+Prix(L[k],L[k+1]); 
 fpour;
 retourne S; 
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketengros([1,12,3,5,2,8])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">12+3*5*0.9+2*8
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python :

</p><pre class="verbatim">def Ticketengros(L) :
    # local S,n,k 
    n=dim(L)
    S=0
    for k in range(0,n-1,2) : 
        S=S+Prix(L[k],L[k+1]) 
    return S 
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketengros([1,12,3,5,2,8])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">12+3*5*0.9+2*8
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec49" L’instruction <span style="font-family:monospace">tantque</span>-->
<h2 id="sec49" class="section">3.11  L’instruction <span style="font-family:monospace">tantque</span></h2><!--SEC END --><p><a id="hevea_default99"></a><a id="hevea_default100"></a><a id="hevea_default101"></a><a id="sec:Somme"></a>
<span style="font-weight:bold">Notion de boucle </span><span style="font-weight:bold"><span style="font-family:monospace">tantque</span></span><br>
On utilise une boucle <span style="font-family:monospace">tantque</span> lorsque l’on ne connaît pas à 
l’avance le nombre d’itérations à effectuer et que l’on arrête les 
itérations quand une condition devient fausse.<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :<br>
<span style="font-family:monospace">tantque &lt;condition&gt; faire &lt;instructions&gt; ftantque;</span><br>
En syntaxe Python :<br>
</p><pre class="verbatim">while  &lt;condition&gt; :
    &lt;instructions&gt;
</pre><p>
<span style="font-weight:bold">Comment fonctionne une boucle </span><span style="font-weight:bold"><span style="font-family:monospace">tantque</span></span><span style="font-weight:bold"> ?</span>
</p><ul class="itemize"><li class="li-itemize">
On évalue la condition : une condition a 2 valeurs possibles <span style="font-family:monospace">vrai</span>
ou <span style="font-family:monospace">faux</span> c’est ce que l’on nomme un booléen,
</li><li class="li-itemize">Si la condition est vraie : on effectue <span style="font-family:monospace">&lt;instructions&gt;</span>
et on revient au test,
si la condition est fausse : on passe directement aux 
instructions qui suivent 
<span style="font-family:monospace">ftantque;</span>.
</li></ul><p>
ou bien on peut dire en langage courant que :<br>
<span style="font-family:monospace">&lt;condition&gt;</span> est une condition de continuation de la boucle.
tant que la condition est vérifiée, on fait les instructions de la boucle.<br>
<span style="font-weight:bold">Traduction d’une boucle </span><span style="font-weight:bold"><span style="font-family:monospace">pour</span></span><span style="font-weight:bold"> en une boucle </span><span style="font-weight:bold"><span style="font-family:monospace">tantque</span></span><br>
<span style="font-weight:bold">Exemple : somme des éléments d’une liste</span>
Soit une liste <span style="font-family:monospace">L</span> de nombres réels.<br>
On veut faire la somme des réels de <span style="font-family:monospace">L</span>.<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :<br>
On tape en utilisant une boucle <span style="font-family:monospace">pour</span> :

</p><pre class="verbatim">fonction Somme(L) 
 local n,j,S;
 n:=dim(L);
 S:=0;
 pour j de 0 jusque n-1 faire
   S:=S+L[j];
 fpour;
 retourne S;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


On tape en utilisant une boucle <span style="font-family:monospace">tantque</span> :

</p><pre class="verbatim">fonction Somme1(L) 
 local n,j,S;
 n:=dim(L);
 S:=0;
 j:=0;
 tantque j &lt;= n-1 faire
   S:=S+L[j];
   j:=j+1;
 ftantque;
 retourne S;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


On peut aussi écrire <span style="font-family:monospace">Somme2</span>, mais <span style="font-weight:bold">Attention</span> 
à l’ordre des instructions de la boucle <span style="font-family:monospace">tantque</span> et au test d’arrêt :

</p><pre class="verbatim">fonction Somme2(L) 
 local n,j,S;
 n:=dim(L);
 j:=0;
 S:=L[0];
 tantque j &lt; n-1 faire
   j:=j+1;
   S:=S+L[j];
 ftantque;
 retourne S;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[10,13,22,15,5,27,45,31,78]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Somme(L)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Somme1(L)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Somme2(L)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python :<br>
On tape en utilisant une boucle <span style="font-family:monospace">pour</span> :

</p><pre class="verbatim">def Somme(L) :
    # local n,j,S
    n=dim(L)
    S=0
    for j in range(n) :
        S:=S+L[j]
    return S
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


On tape en utilisant une boucle <span style="font-family:monospace">tantque</span> :

</p><pre class="verbatim">def Somme1(L) :
    # local n,j,S
    n=dim(L)
    S=0
    j=0
    while j &lt;= n-1 :
        S=S+L[j]
        j=j+1
    return S
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


On peut aussi écrire <span style="font-family:monospace">Somme2</span>, mais <span style="font-weight:bold">Attention</span> 
à l’ordre des instructions de la boucle <span style="font-family:monospace">tantque</span> et au test d’arrêt :

</p><pre class="verbatim">def Somme2(L) :
    # local n,j,S
    n=dim(L)
    j=0
    S=L[0]
    while j &lt; n-1 :
        j=j+1
        S=S+L[j]
    return S;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[10,13,22,15,5,27,45,31,78]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Somme(L)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Somme1(L)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Somme2(L)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On peut vérifier ces résultats avec la fonction <span style="font-family:monospace">sum</span> de <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">sum([10,13,22,15,5,27,45,31,78]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<span style="font-weight:bold">Autre exemple : trouver le n-ième nombre premier</span>
On veut définir une fonction <span style="font-family:monospace">Niemeprem(n)</span> qui renvoie le 
<span style="font-family:monospace">n</span>ième nombre premier.<br>
On utilise, pour cela la fonction booléenne <span style="font-family:monospace">est_premier</span> (ou 
<span style="font-family:monospace">is_prime</span>) de <span style="font-family:monospace">Xcas</span> qui teste si un nombre entier est premier.<br>
A part le nombre 2, les nombres premiers sont impairs, donc on traite le cas de 
2, puis on initialise <span style="font-family:monospace">k</span> à 3 et on fait varier <span style="font-family:monospace">k</span> avec un pas de 2.
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Niemeprem(n)
  local k,p;
  si n==1 alors retourne 2; fsi;
  k:=3;p:=1;
  tantque p&lt;n faire
    si est_premier(k) alors p:=p+1; fsi;
    k:=k+2;
  ftantque;
  retourne k-2;
ffonction:;  
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Niemeprem(10),Niemeprem(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe <span style="font-family:monospace">Xcas</span> avec un <span style="font-family:monospace">pour</span> : 

</p><pre class="verbatim">fonction Niemeprem1(n)
  local k,p;
  si n==1 alors retourne 2; fsi;
  p:=1;
  pour k de 3 jusque 100*n pas 2 faire
    si est_premier(k) alors p:=p+1; fsi;
    si p==n alors break; fsi;
  fpour;
  retourne k;
ffonction:;  
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Niemeprem1(10),Niemeprem1(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python :

</p><pre class="verbatim">def Niemeprem(n) :
    # local k,p
    if n==1 :
        return 2
    k=3
    p=1
    while p&lt;n :
        if isprime(k) : 
            p=p+1
        k:=k+2
    return k-2
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Niemeprem(10),Niemeprem(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On pourra vérifier le résultat du programme car cette fonction existe 
dans <span style="font-family:monospace">Xcas</span> c’est <span style="font-family:monospace">ithprime(n)</span><br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">ithprime(10),ithprime(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python avec un <span style="font-family:monospace">for</span>:

</p><pre class="verbatim">def Niemeprem1(n) :
    # local k,p
    if n==1 :
        return 2
    p=1
    for k in range(3,100*n,2) :
        if isprime(k) :
           p:=p+1
        if p==n :
           break;
    return k;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Niemeprem1(10),Niemeprem1(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
</p>
<!--TOC section id="sec50" Un exercice et un problème-->
<h2 id="sec50" class="section">3.12  Un exercice et un problème</h2><!--SEC END -->
<!--TOC subsection id="sec51" Exercice-->
<h3 id="sec51" class="subsection">3.12.1  Exercice</h3><!--SEC END --><p>
On veut définir une fonction <span style="font-family:monospace">Snpremiers(n)</span> d’une variable <span style="font-family:monospace">n</span> 
(<span style="font-family:monospace">n </span> est un entier positif) qui calcule la somme des <span style="font-family:monospace">n</span> premiers 
nombres premiers. On utilise, pour cela la fonction booléenne 
<span style="font-family:monospace">est_premier</span> (ou <span style="font-family:monospace">is_prime</span>) de <span style="font-family:monospace">Xcas</span> qui teste si un nombre 
entier est premier.<br>
A part le nombre 2, les nombres premiers sont impairs, donc on initialise 
<span style="font-family:monospace">S</span> à 2 et <span style="font-family:monospace">k</span> à 3 avec un pas de 2.<br>

En syntaxe <span style="font-family:monospace">Xcas</span>, (l’indice <span style="font-family:monospace">j</span> compte les nombres premiers,
l’indice <span style="font-family:monospace">k</span> sert à chercher les nombres qui sont premiers) :

</p><pre class="verbatim">fonction Snpremiers(n)
  local S,k,p,j;
  j:=1;
  S:=2;
  k:=3;
  tantque j&lt; n faire
     si est_premier(k) alors 
       S:=S+k;
       j:=j+1;
     fsi;
     k:=k+2;
  ftantque;
  retourne S;
ffonction:;  
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>

</p><p>
<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Snpremiers(8),Snpremiers(10),Snpremiers(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe <span style="font-family:monospace">Xcas</span>, avec un <span style="font-family:monospace">pour</span> :

</p><pre class="verbatim">fonction Snpremiers1(n)
  local S,k,p,j;
  j:=1;
  S:=2;
  pour k de 3 jusque 100*n pas 2 faire
     si est_premier(k) alors 
       S:=S+k;
       j:=j+1;
     fsi;
     si j==n alors break; fsi
  fpour;
  retourne S;
ffonction:;  
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>

 

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Snpremiers1(8),Snpremiers1(10),Snpremiers1(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python, (l’indice <span style="font-family:monospace">j</span> compte les nombres premiers,
l’indice <span style="font-family:monospace">k</span> sert à chercher les nombres premiers) :

</p><pre class="verbatim">def Snpremiers(n) :
    # local S,k,p,j
    j=1
    S=2
    k=3
    while j&lt; n :
        if is_prime(k) : 
            S=S+k
            j=j+1
        k=k+2
    return S 
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Snpremiers(8),Snpremiers(10),Snpremiers(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python avec un <span style="font-family:monospace">for</span> :

</p><pre class="verbatim">def Snpremiers1(n) :
    # local S,k,p,j
    j=1
    S=2
    for k in range(3,100*n,2) :
        if is_prime(k) : 
            S=S+k
            j=j+1
        if j==n :
            break
    return S 
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>

</p>
<!--TOC subsection id="sec52" Problème : le crible d’Eratosthène-->
<h3 id="sec52" class="subsection">3.12.2  Problème : le crible d’Eratosthène</h3><!--SEC END -->
<!--TOC subsection id="sec53" Description-->
<h3 id="sec53" class="subsection">3.12.3  Description</h3><!--SEC END --><p>
Pour trouver les nombres premiers inférieurs ou égaux à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi></mrow><annotation encoding='application/x-tex'>N</annotation></semantics></math> :
</p><ol class="enumerate" type=1><li class="li-enumerate">
On écrit les nombres de 2 à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi></mrow><annotation encoding='application/x-tex'>N</annotation></semantics></math> dans une liste <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>T</mi><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>TAB</annotation></semantics></math>.
</li><li class="li-enumerate">On met 2 dans la case <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi></mrow><annotation encoding='application/x-tex'>P</annotation></semantics></math> .
</li><li class="li-enumerate">Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi><mo>&times;</mo><mi>P</mi><mo>&leq;</mo><mi>N</mi></mrow><annotation encoding='application/x-tex'>P \times P \leq N</annotation></semantics></math> il faut traiter les éléments de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi></mrow><annotation encoding='application/x-tex'>P</annotation></semantics></math> à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi></mrow><annotation encoding='application/x-tex'>N</annotation></semantics></math> :
on barre tous les multiples de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi></mrow><annotation encoding='application/x-tex'>P</annotation></semantics></math> à partir de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi><mo>&times;</mo><mi>P</mi></mrow><annotation encoding='application/x-tex'>P \times P</annotation></semantics></math>.
</li><li class="li-enumerate">On augmente <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi></mrow><annotation encoding='application/x-tex'>P</annotation></semantics></math> de 1.<br>
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi><mo>&times;</mo><mi>P</mi></mrow><annotation encoding='application/x-tex'>P\times P</annotation></semantics></math> est strictement supérieur à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi></mrow><annotation encoding='application/x-tex'>N</annotation></semantics></math>, on arrête
</li><li class="li-enumerate">On met le plus petit élément non barré de la liste dans la case
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi></mrow><annotation encoding='application/x-tex'>P</annotation></semantics></math>. On reprend à l’étape 3.
</li><li class="li-enumerate">on met les éléments non nuls de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>T</mi><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>TAB</annotation></semantics></math> dans une liste <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi><mi>R</mi><mi>E</mi><mi>M</mi></mrow><annotation encoding='application/x-tex'>PREM</annotation></semantics></math>.
</li></ol>
<!--TOC subsection id="sec54" Écriture de l’algorithme-->
<h3 id="sec54" class="subsection">3.12.4  Écriture de l’algorithme</h3><!--SEC END --><pre class="verbatim">Fonction crible(N)
 local TAB PREM I P
 // TAB et PREM sont des listes
 //=&gt; est le STO des calculatrices
 [] =&gt;TAB
 [] =&gt;PREM
 //on suppose que les indices d'une liste debutent par 0
 pour I de 0 a N faire 
  TAB:=concat(TAB, I)
 fpour
 //On met 0 dans TAB[1] car 1 n'est pas premier
 //barrer 1 a ete realise en le remplacant par 0
 TAB[1]:=0
 //TAB est la liste 0 0 2 3 4 ...N 
 P:=2
 // On a fait les points 1 et 2
 tantque P*P &lt;= N faire
  pour I de P jusque E(N/P) faire
    //E(N/P) designe la partie entiere de N/P
    TAB[I*P]:=0
  fpour
  // On a donc barre tous les multiples de P a partir de P*P
  P:=P+1
  //On cherche le plus petit nombre &lt;= N non barre (i.e. non nul)
  // entre P et N
  tantque (P*P &lt;= N) et (TAB[P]=0) faire
    P=P+1
  ftantque
 ftantque
 //on ecrit le resultat dans une liste PREM
 pour I de 2 a N faire
  si TAB[I]!= 0 alors 
     PREM:=concat(PREM, I)
  fsi
 fpour
 retourne PREM
</pre>
<!--TOC subsection id="sec55" En syntaxe <span style="font-family:monospace">Xcas</span>-->
<h3 id="sec55" class="subsection">3.12.5  En syntaxe <span style="font-family:monospace">Xcas</span></h3><!--SEC END -->
<!--TOC subsubsection id="sec56" Première version-->
<h4 id="sec56" class="subsubsection">Première version</h4><!--SEC END --><pre class="verbatim">//renvoie la liste des nombres premiers&lt;=n selon Eratosthene
crible0(n):={
  local tab,prem,p,j;
  tab:=[0,0];
  prem:=[];
  pour j de 2 jusque n faire
    tab:=append(tab,j);
  fpour;
  p:=2;
  tantque (p*p&lt;=n) faire
    pour j de p jusque floor(n/p) faire
      tab[j*p]:=0;
    fpour
    p:=p+1;
    tantque ((p*p&lt;=n) et (tab[p]==0)) faire
      p:=p+1;
    ftantque;
  ftantque;
  pour j de 2 jusque n faire
    si (tab[j]!=0) alors 
      prem:=append(prem,j);
    fsi
  fpour
  retourne(prem);
}:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">crible0(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">time(crible0(1000))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
L’instruction <code>time</code><a id="hevea_default102"></a> affiche le temps d’exécution
de la commande.</p>
<!--TOC subsubsection id="sec57" Une version plus efficace-->
<h4 id="sec57" class="subsubsection">Une version plus efficace</h4><!--SEC END --><ol class="enumerate" type=1><li class="li-enumerate">
On utilise <span style="font-family:monospace">seq</span> pour définir <span style="font-family:monospace">tab</span> et on remplace les 
affectations <span style="font-family:monospace">:=</span> par des affectations par référence <span style="font-family:monospace">=&lt;</span>. 
<pre class="verbatim">tab:=[0,0];
pour j de 2 jusque n faire
 tab:=append(tab,j);
fpour;
</pre>
par
<pre class="verbatim">tab:=seq(j,j,0,n);
tab[0]=&lt;0; tab[1]=&lt;0;
</pre>
</li><li class="li-enumerate">On remplace tout d’abord les affectations <span style="font-family:monospace">:=</span> d’éléments d’une 
liste par une affectation par référence <span style="font-family:monospace">=&lt;</span> c’est à dire sans
recopier la liste à chaque fois qu’on en modifie un élément,
ce qui est plus efficace.
</li><li class="li-enumerate">Puis, lorsque qu’on barre les multiples de <span style="font-family:monospace">p</span> premier on remplace les
multiplications de <span style="font-family:monospace">tab[eval(j*p)]:=0;</span> par des additions on faisant varier 
<span style="font-family:monospace">j</span> avec un pas :
On remplace donc 
<pre class="verbatim">pour j de p jusque floor(n/p) faire
   tab[j*p]:=0;
fpour;
</pre>
par
<pre class="verbatim">pour j de p*p jusque n pas p faire
    tab[j]=&lt;0;
fpour;
</pre>
</li></ol><p>
On obtient :

</p><pre class="verbatim">//renvoie la liste des nombres premiers&lt;=n selon Eratosthene
crible(n):={
  local tab,prem,p,j;
  tab:=seq(j,j,0,n);
  tab[0]=&lt;0; tab[1]=&lt;0; 
  prem:=[];
  p:=2;
  tantque (p*p&lt;=n) faire
    pour j de p*p jusque n pas p faire
      tab[j]=&lt;0;
    fpour
    p:=p+1;
    tantque ((p*p&lt;=n) et (tab[p]==0)) faire
      p=&lt;p+1;
    ftantque;
  ftantque;
  pour j de 2 jusque n faire
    si (tab[j]!=0) alors 
      prem:=append(prem,j);
    fsi
  fpour
  retourne(prem);
}:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">crible(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">time(crible(1000))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC subsection id="sec58" En syntaxe Python-->
<h3 id="sec58" class="subsection">3.12.6  En syntaxe Python</h3><!--SEC END -->
<!--TOC subsubsection id="sec59" Première version-->
<h4 id="sec59" class="subsubsection">Première version</h4><!--SEC END --><pre class="verbatim"># renvoie la liste des nombres premiers&lt;=n selon Eratosthene
def crible0(n) :
    # local tab,prem,p,j
    tab =[0,0]
    prem =[]
    for j in range(2,n+1) :
        tab.append(j)
    p=2
    while p*p&lt;=n :
        for j in range(p,floor(n/p)+1) :
            tab[j*p]=0 
        p=p+1
        while p*p&lt;=n and tab[p]==0 :
            p=p+1
    for j in range(2,n+1) :
        if tab[j]!=0 : 
            prem.append(j)
    return prem
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">crible0(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">time(crible0(1000))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC subsubsection id="sec60" Une version plus efficace-->
<h4 id="sec60" class="subsubsection">Une version plus efficace</h4><!--SEC END --><pre class="verbatim"># renvoie la liste des nombres premiers&lt;=n selon Eratosthene
def crible(n) :
    # local tab,prem,p,j
    tab=range(0,n+1)
    tab[0]=&lt;0; tab[1]=&lt;0 
    prem=[]
    p=2
    while p*p&lt;=n :
        for j in range(p*p,n+1,p) :
            tab[j]=&lt;0
        p=p+1
        while p*p&lt;=n and tab[p]==0 :
            p=p+1
    for j in range(2,n+1) :
        if tab[j]!=0 :
            prem.append(j)
    return prem;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">crible(100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">time(crible(1000))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec61" Autre exemple de boucle <span style="font-family:monospace">tantque</span> : le ticket de caisse-->
<h2 id="sec61" class="section">3.13  Autre exemple de boucle <span style="font-family:monospace">tantque</span> : le ticket de caisse</h2><!--SEC END --><p>
En fin de mois, Paul n’a plus qu’une somme <span style="font-family:monospace">a</span> dans son porte-monnaie.
Paul fait sa liste de courses <span style="font-family:monospace">Lc</span> en mettant au début ce qu’il 
veut vraiement acheter et à la fin de sa liste, il met les achats qu’il doit 
faire à plus long terme. Dans le magasin (qui ne fait pas de réduction), sa
liste de courses <span style="font-family:monospace">Lc</span> devient une liste de prix <span style="font-family:monospace">L</span>.<br>
Dans ce cas, on ne peut pas utiliser une boucle avec <span style="font-family:monospace">pour</span> car on ne 
sait pas au départ combien de fois on doit effectuer la boucle.<br>
On note <span style="font-family:monospace">S</span> la variable qui stockera successivement la somme des prix des 
premiers éléments de <span style="font-family:monospace">L</span> : pour cela on utilise la fonction 
<span style="font-family:monospace">Somme(L)</span> écrite précedemment (cf <a href="#sec%3ASomme">3.11</a>).<br>
Il veut faire un programme qui arrête sa liste dès que <span style="font-family:monospace">S&gt;a</span> en coupant 
<span style="font-family:monospace">L</span> en 2 listes :
<span style="font-family:monospace">La</span> liste des objets de ce qu’il achète réellement pour un montant 
<span style="font-family:monospace">S&lt;=a</span> et <span style="font-family:monospace">Lfin</span> liste des objets qu’il n’achète pas (<span style="font-family:monospace">Lfin</span> est 
une liste vide lorsque <span style="font-family:monospace">Somme(L)&lt;=a</span>).<br>
<span style="font-family:monospace">Ticketfindemois(L,a)</span> doit renvoyer <span style="font-family:monospace">La,Lfin,P</span> où <span style="font-family:monospace">P</span> est la 
somme à payer.<br>
"arrêt" se traduit ici par <span style="font-family:monospace">Lfin ==[] ou S&gt;a</span> donc<br>
"continuation" se traduit ici par <span style="font-family:monospace">Lfin!=[] et S&lt;=a</span>.<br>
On teste tout d’abord si Paul a assez d’argent pour payer toute sa liste :
pour cela, on utilise le programme <span style="font-family:monospace">Somme</span> précédent 
(cf <a href="#sec%3ASomme">3.11</a>).<br>
Paul a assez d’argent pour payer toute sa liste lorsque <span style="font-family:monospace">Somme(L)&lt;=a</span> 
et alors on a <span style="font-family:monospace">La :=L</span>, <span style="font-family:monospace">Lfin :=[]</span> et <span style="font-family:monospace">P:=Somme(L)</span>.<br>
Si <span style="font-family:monospace">Somme(L)&gt;a</span>, Paul n’a pas assez d’argent donc <span style="font-family:monospace">Lfin!=[]</span> est 
vrai et la condition d’arrêt est : <span style="font-family:monospace">S&lt;=a</span>.
On écrit <span style="font-family:monospace">Ticketfindemois(L,a)</span> pour que <span style="font-family:monospace">k</span> soit le 
nombre d’articles achetés lorsqu’ on sort du <span style="font-family:monospace">tantque</span>.<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Ticketfindemois(L,a) 
 local S,n,k,Lfin,La;
 S:=Somme(L);
 si S &lt;=a alors retourne L,[],S fsi;
 n:=dim(L);
 k:=0;
 S:=L[0];
 tantque S &lt;=a faire 
   k:=k+1;
   S:=S+L[k];
  ftantque;
 La:=gauche(L,k);
 Lfin:=droit(L,n-k);
 retourne La,Lfin,S-L[k];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L1:=[15,10,2,7,5,1.2,3,5.5,10,4,5.3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketfindemois(L1,50)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L2:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketfindemois(L2,60)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python :

</p><pre class="verbatim">def Ticketfindemois(L,a) : 
    # local S,n,k,Lfin,La
    S=Somme(L)
    if S &lt;=a :
        return L,[],S
    n=dim(L)
    k=0
    S=L[0]
    while S &lt;=a : 
        k=k+1
        S=S+L[k]
    La:=gauche(L,k)
    Lfin:=droit(L,n-k)
    return La,Lfin,S-L[k]
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L1:=[15,10,2,7,5,1.2,3,5.5,10,4,5.3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketfindemois(L1,50)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L2:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketfindemois(L2,60)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On peut aussi écrire mais <span style="font-weight:bold">Attention</span> à 
l’ordre des instructions dans le <span style="font-family:monospace">tantque</span>. 
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Ticketfindemois1(L,a) 
 local S,n,k,Lfin,La;
 S:=Somme(L);
 si S &lt;=a alors retourne L,[],S fsi;
 n:=dim(L);
 S:=0;
 k:=0;
 tantque S &lt;=a faire 
   S:=S+L[k];
   k:=k+1;
 ftantque;
 La:=gauche(L,k-1);
 Lfin:=droit(L,n-k+1);
 retourne La,Lfin,S-L[k-1];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L1:=[15,10,2,7,5,1.2,3,5.5,10,4,5.3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L2:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketfindemois1(L1,50)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketfindemois1(L2,60)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Dans <span style="font-family:monospace">Ticketfindemois1</span>, c’est <span style="font-family:monospace">k-1</span> et non <span style="font-family:monospace">k</span>, qui est pas la 
valeur du nombre d’articles achetés lorsqu’on sort du <span style="font-family:monospace">tantque</span>.<br>
En effet, lorsqu’on s’arrête <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi></mrow><annotation encoding='application/x-tex'>S</annotation></semantics></math> devient 
supérieur à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> : il ne faut donc pas acheter l’article <span style="font-family:monospace">L[k]</span>.<br>
Donc <span style="font-family:monospace">La:=gauche(L,k-1);</span> et <span style="font-family:monospace">Lfin:=droit(L,n-k+1)</span>.<br>

<span style="font-weight:bold">Remarque</span><br>
On aurait pu aussi écrire sans utiliser <span style="font-family:monospace">Somme</span>
mais c’est plus compliqué car la condition du <span style="font-family:monospace">tantque</span> porte sur <span style="font-family:monospace">k</span>
et sur <span style="font-family:monospace">S</span> !!!
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Ticketfindemois2(L,a) 
  local S,n,k,La,Lfin,P;
  n:=dim(L);
  k:=0;
  S:=L[0];
  tantque S&lt;=a et k&lt;n-1 faire
    k:=k+1;
    S:=S+L[k];
  ftantque;
  si S&lt;=a alors retourne L,[],S fsi;
  La:=gauche(L,k);
  Lfin:=droit(L,n-k);
  P:=S-L[k];
 retourne La,Lfin,P;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


À chaque étape on a :<br>
Au début, on a :<br>
<span style="font-family:monospace">k:=0;S:=L[0];</span> donc <span style="font-family:monospace">S</span> est le prix de <span style="font-family:monospace">1</span> article.<br>
lorsqu’on fait <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>k</mi></mrow><annotation encoding='application/x-tex'>k</annotation></semantics></math> fois la boucle on a :<br>
<span style="font-family:monospace">S:=L[0]+..L[k];</span> donc <span style="font-family:monospace">S</span> est la somme de <span style="font-family:monospace">k+1</span> articles.<br>
Quand on sort du <span style="font-family:monospace">tantque</span> on a :<br>
soit <span style="font-family:monospace">S&lt;=a</span> est vrai, donc <span style="font-family:monospace">k==n-1</span> est vrai (puisque 
<span style="font-family:monospace">(S&lt;=a et k&lt;n-1)==faux</span>).<br>
<span style="font-family:monospace">S</span> est donc la somme de toute la liste <span style="font-family:monospace">L</span> i.e. <span style="font-family:monospace">S</span> est la somme 
à payer pour l’achat de <span style="font-family:monospace">n</span> articles i.e. Paul peut acheter toute 
sa liste de courses.<br>
soit <span style="font-family:monospace">S&gt;a</span> et <span style="font-family:monospace">k&lt;=n-1</span> alors <span style="font-family:monospace">S</span> représente la somme des prix des 
<span style="font-family:monospace">k+1</span> premiers articles (<span style="font-family:monospace">k+1</span> car on a commencé à l’article 
<span style="font-family:monospace">k=0</span>. Mais Paul ne peut pas acheter le dernier 
article puisque <span style="font-family:monospace">S&gt;a</span>. Le prix <span style="font-family:monospace">P</span> représente la somme des prix des 
<span style="font-family:monospace">k</span> premiers articles i.e.des articles <span style="font-family:monospace">L[0],..L[k-1]</span> ou encore des 
artices de la liste <span style="font-family:monospace">gauche(L,k)</span> donc <span style="font-family:monospace">P:=S-L[k]</span>.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L1:=[15,10,2,7,5,1.2,3,5.5,10,4,5.3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L2:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketfindemois2(L1,50)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketfindemois2(L2,60)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec62" Interruption d’une boucle-->
<h2 id="sec62" class="section">3.14  Interruption d’une boucle</h2><!--SEC END --><p><a id="hevea_default103"></a>
Si on utilise <span style="font-family:monospace">retourne</span> à l’intérieur d’une boucle dans une fonction, 
celle-ci est interrompue. Ceci permet de 
transformer des boucles "tantque" en boucle "pour" souvent plus lisibles.</p><p>Reprenons l’exemple ci-dessus,
on remarque que la boucle tantque utilise un compteur <span style="font-family:monospace">k</span>
qu’on incrémente à chaque itération comme dans une boucle <span style="font-family:monospace">pour</span>.
Il est donc naturel d’essayer de réécrire cette fonction avec
une boucle <span style="font-family:monospace">pour</span>. Il suffira de tester dans le corps de 
la boucle si la somme (avec le nouvel article)
dépasse le contenu du porte-monnaie, dans ce cas il faut s’arrêter
sans acheter le nouvel article, on interrompt la boucle et on renvoie les
résultats (on calcule la somme au fur et à mesure et donc on n’utilise pas 
la fonction <span style="font-family:monospace">Somme</span>).
Dans <span style="font-family:monospace">Ticketfindemois3</span>, c’est <span style="font-family:monospace">k</span>, qui est pas la 
valeur du nombre d’articles achetés lorsqu’on sort du <span style="font-family:monospace">pour</span>.<br>
En effet, lorsqu’on s’arrête <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi></mrow><annotation encoding='application/x-tex'>S</annotation></semantics></math> devient 
supérieur à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> : il ne faut donc pas acheter l’article <span style="font-family:monospace">L[k]</span>.<br>
Donc <span style="font-family:monospace">La:=gauche(L,k);</span> et <span style="font-family:monospace">Lfin:=droit(L,n-k)</span>.<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Ticketfindemois3(L,a)
  local k,n,S,La,Lfin;
  n:=dim(L);
  S:=0;
  pour k de 0 jusque n-1 faire
    si S+L[k]&gt;a alors 
      La:=gauche(L,k);
      Lfin:=droit(L,n-k);
      retourne La,Lfin,S;
    fsi;
    S:=S+L[k];
  fpour;
  retourne L,[],S;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L1:=[15,10,2,7,5,1.2,3,5.5,10,4,5.3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L2:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketfindemois3(L1,50)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketfindemois3(L2,60)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python:

</p><pre class="verbatim">def Ticketfindemois3(L,a):
    # local k,n,S,La,Lfin
    n=dim(L)
    S=0
    k=0
    for k in range(n) :        
        if (S+L[k])&gt;a :
            La=gauche(L,k)
            Lfin=droit(L,n-k)
            return La,Lfin,S
        S=S+L[k]
    return(L,[],S)
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L1:=[15,10,2,7,5,1.2,3,5.5,10,4,5.3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L2:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketfindemois3(L1,50)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketfindemois3(L2,60)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

Cette méthode s’applique pour toute boucle <span style="font-family:monospace">tantque</span> dont on peut
prévoir à priori un majorant du nombre d’itérations. On peut
d’ailleurs aussi l’utiliser si on se fixe un nombre maximal d’itérations
qui tient compte du temps d’exécutions, typiquement en <span style="font-family:monospace">Xcas</span>
de l’ordre du million d’itérations si on veut un
résultat en moins de quelques secondes.</p><p><span style="font-weight:bold">Remarque</span> : si on ne veut pas quitter la fonction, il est quand même
possible d’interrompre la boucle prématurément 
en utilisant l’instruction <span style="font-family:monospace">break</span>.</p>
<!--TOC section id="sec63" Autre exemple de boucle <span style="font-family:monospace">tantque</span> : le ticket de caisse-->
<h2 id="sec63" class="section">3.15  Autre exemple de boucle <span style="font-family:monospace">tantque</span> : le ticket de caisse</h2><!--SEC END --><p>
Pour avoir des clients le dimanche matin, le magasin de Paul offre selon 
les dimanches une réduction immédiate <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi></mrow><annotation encoding='application/x-tex'>r</annotation></semantics></math> qui varie selon le montant 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> des achats par exemple une réduction de 10 euros dès 60 euros 
d’achats, ou une réduction de 5 euros dès 50 euros d’achats etc...<br>
Ce magasin ne pratique pas de réduction pour des achats en gros.<br>
Pour être sûr de bénéficier de la réduction, Paul fait sa liste
de courses <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>L</mi><mi>c</mi></mrow><annotation encoding='application/x-tex'>Lc</annotation></semantics></math> en mettant au début ce qu’il veut vraiement acheter et à la
fin de sa liste, il met les achats qu’il doit faire à plus long terme
(contrairement au programme précédent, on suppose ici 
que Paul a suffisamment d’argent).<br>
<span style="font-weight:bold">Attention</span><br>
On suppose ici que la liste de courses est constituée par une suite des 
nombres <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math>,<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi></mrow><annotation encoding='application/x-tex'>P</annotation></semantics></math> où <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> est le nombre d’achats du même article de prix <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi></mrow><annotation encoding='application/x-tex'>P</annotation></semantics></math>.<br>
Il veut faire un programme qui arrête sa liste dès que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mi>&gt;</mi><mo>=</mo><mi>a</mi></mrow><annotation encoding='application/x-tex'>S&amp;gt;=a</annotation></semantics></math> en coupant 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>L</mi><mi>c</mi></mrow><annotation encoding='application/x-tex'>Lc</annotation></semantics></math> en 2 listes <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>L</mi><mi>a</mi></mrow><annotation encoding='application/x-tex'>La</annotation></semantics></math> liste des objets de ce qu’il achète réellement pour 
un montant <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi></mrow><annotation encoding='application/x-tex'>S</annotation></semantics></math> avant réduction et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>L</mi><mi>f</mi><mi>i</mi><mi>n</mi></mrow><annotation encoding='application/x-tex'>Lfin</annotation></semantics></math> liste des objets qu’il 
n’achète pas (<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>L</mi><mi>f</mi><mi>i</mi><mi>n</mi></mrow><annotation encoding='application/x-tex'>Lfin</annotation></semantics></math> est éventuellement une liste vide).<br>
Paul veut que son programme ait paramètres <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>L</mi><mi>c</mi><mo>,</mo><mi>a</mi><mo>,</mo><mi>r</mi></mrow><annotation encoding='application/x-tex'>Lc,a,r</annotation></semantics></math> et qu’il renvoie :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>L</mi><mi>a</mi></mrow><annotation encoding='application/x-tex'>La</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>L</mi><mi>f</mi><mi>i</mi><mi>n</mi></mrow><annotation encoding='application/x-tex'>Lfin</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi></mrow><annotation encoding='application/x-tex'>S</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mo>&minus;</mo><mi>r</mi></mrow><annotation encoding='application/x-tex'>S&#x2d;r</annotation></semantics></math>.<br>
Dans ce cas, on ne sait pas au départ combien de fois on doit effectuer la 
boucle.<br>
Mais on sait quand on doit s’arrêter :<br>
on arrête la boucle lorsque le prix <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi></mrow><annotation encoding='application/x-tex'>S</annotation></semantics></math> de la liste complète <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>L</mi><mi>c</mi></mrow><annotation encoding='application/x-tex'>Lc</annotation></semantics></math> 
n’atteint pas le montant <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> ou dés que le prix <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi></mrow><annotation encoding='application/x-tex'>S</annotation></semantics></math> du début de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>L</mi><mi>c</mi></mrow><annotation encoding='application/x-tex'>Lc</annotation></semantics></math> 
vérifie <span style="font-family:monospace">S&gt;=a</span>.<br>
On utilise pour cela une boucle <span style="font-family:monospace">tantque</span> :<br>
<span style="font-family:monospace">tantque &lt;condition&gt; faire &lt;instructions&gt; ftantque;</span><br>
Cela veut dire :<br>
tant que "non arrêt", on fait les instructions de la boucle.<br>
"arrêt" se traduit ici par <span style="font-family:monospace">Lfin ==[] ou S&gt;=a</span> donc, <br>
"non arrêt" se traduit ici par <span style="font-family:monospace">Lfin!=[] et S&lt;a</span>.<br>
<span style="font-weight:bold">Attention</span> la variable <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>k</mi></mrow><annotation encoding='application/x-tex'>k</annotation></semantics></math> qui va parcourir la liste <span style="font-family:monospace">L</span> devra être 
initialisée (ici <span style="font-family:monospace">k:=0;</span>) et modifiée dans le corps de la boucle (ici 
<span style="font-family:monospace">k:=k+2;</span>).<br>
La fonction <span style="font-family:monospace">Ticketdimanche</span> a 3 paramètres <span style="font-family:monospace">L,a,r</span> et renvoie
la liste <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>L</mi><mi>a</mi></mrow><annotation encoding='application/x-tex'>La</annotation></semantics></math> des courses qui ont été prises en compte,<br>
la liste <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>L</mi><mi>f</mi><mi>i</mi><mi>n</mi></mrow><annotation encoding='application/x-tex'>Lfin</annotation></semantics></math> des courses qui n’ont pas été prises en compte (cette liste peut être vide si <span style="font-family:monospace">S&lt;=a</span>)<br>
la somme <span style="font-family:monospace">S</span> des achats sans la remise et<br>
la somme <span style="font-family:monospace">S-r</span> à payer.<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Ticketdimanche(L,a,r) 
 local S,n,k,Lfin,La; 
 n:=dim(L);
 S:=0;
 k:=0;
 tantque k&lt;n et S&lt;a faire 
   S:=S+L[k]*L[k+1];
   k:=k+2;
 ftantque;
 La:=gauche(L,k);
 Lfin:=droit(L,n-k);
 si S&lt;a alors r:=0; fsi;
 retourne La,Lfin,S,S-r;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L1:=[1,15,2,7,5,1.2,3,5.5]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L2:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketdimanche(L1,50,5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketdimanche(L2,60,10)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

En syntaxe Python :

</p><pre class="verbatim">def Ticketdimanche(L,a,r) :
    # local S,n,k,Lfin,La 
    n=dim(L)
    S=0
    k=0
    while k&lt;n and S&lt;a : 
        S=S+L[k]*L[k+1]
        k=k+2
    La=gauche(L,k)
    Lfin=droit(L,n-k)
    if S&lt;a :
        r=0
    return La,Lfin,S,S-r
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L1:=[1,15,2,7,5,1.2,3,5.5]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L2:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketdimanche(L1,50,5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketdimanche(L2,60,10)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-weight:bold">Traduction du “tantque” en “pour”</span><br>
On remarque que la boucle “tantque” a un compteur <span style="font-family:monospace">k</span>, on peut donc 
la transformer en boucle “pour” avec sortie prématurée de la boucle
lorsque <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mi>&gt;</mi><mi>a</mi></mrow><annotation encoding='application/x-tex'>S&amp;gt;a</annotation></semantics></math>.<br>
<span style="font-weight:bold">Attention</span> <span style="font-family:monospace">gauche(L,k)</span> représente les <span style="font-family:monospace">k</span> premiers 
éléments de <span style="font-family:monospace">L</span> i.e c’est <span style="font-family:monospace">L[0]..L[k-1]</span>.<br>
Ici, on sort de la boucle <span style="font-family:monospace">pour</span> lorsque <span style="font-family:monospace">S&gt;=a</span> donc pour avoir la 
réduction il faut acheter <span style="font-family:monospace">L[k]</span> fois l’article <span style="font-family:monospace">L[k+1]</span>, c’est à 
dire prendre en compte la liste <span style="font-family:monospace">L[0].. L[k+1]</span> qui est une liste de
<span style="font-family:monospace">k+2</span> éléments c’est donc <span style="font-family:monospace">gauche(L,k+2)</span>.
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Ticketdimanche1(L,a,r) 
 local S,n,k,Lfin,La; 
 n:=dim(L);
 S:=0;
 pour k de 0 jusque n-1 pas 2 faire
   S:=S+L[k]*L[k+1];
   si S&gt;=a alors 
     La:=gauche(L,k+2); 
     Lfin:=droit(L,n-k-2); 
     retourne La,Lfin,S,S-r;
   fsi;
 fpour;
 retourne L,[],S,S;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L1:=[1,15,2,7,5,1.2,3,5.5]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L2:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketdimanche1(L1,50,5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketdimanche1(L2,60,10)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>En syntaxe Python :

</p><pre class="verbatim">def Ticketdimanche1(L,a,r):
    # local S,n,k,Lfin,La
    n=dim(L)
    S=0
    for k in range(0,n,2):
        S=S+L[k]*L[k+1]
        if S&gt;=a :
            La=gauche(L,k+2)
            Lfin=droit(L,n-k-2)
            return La,Lfin,S,S-r
    return L,[],S,S

</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L1:=[1,15,2,7,5,1.2,3,5.5]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L2:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketdimanche1(L1,50,5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketdimanche1(L2,60,10)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec64" Encore un exemple de boucle <span style="font-family:monospace">tantque</span> : le ticket de caisse-->
<h2 id="sec64" class="section">3.16  Encore un exemple de boucle <span style="font-family:monospace">tantque</span> : le ticket de caisse</h2><!--SEC END --><p>
Maintenant le magasin de Paul favorise aussi les achats en gros :
10% de réduction lorsque on achète 3 fois le même produit.
En plus il offre selon les dimanches une réduction immédiate <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi></mrow><annotation encoding='application/x-tex'>r</annotation></semantics></math> qui varie 
selon le montant <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> des achats, par exemple une réduction de 10 euros dès 
60 euros d’achats.<br>
Modifier les programmes précédents pour tenir compte des achats en 
gros. On utilise ici la fonction <span style="font-family:monospace">Prix</span> écrite précédemment 
(cf <a href="#sec%3APrix">3.9</a>).<br>
<span style="font-weight:bold">Attention</span> comme précédemment on suppose ici que la liste de courses 
est constituée par une suite des nombres <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math>,<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi></mrow><annotation encoding='application/x-tex'>P</annotation></semantics></math> où <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> est le nombre 
d’achats du même article de prix <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>P</mi></mrow><annotation encoding='application/x-tex'>P</annotation></semantics></math>.<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Ticketdimgros(L,a,r) 
 local S,n,k,Lfin,La; 
 n:=dim(L);
 S:=0;
 k:=0;
 tantque k &lt; n et S&lt;a faire 
   S:=S+Prix(L[k],L[k+1]);
   k:=k+2;
 ftantque;
 La:=gauche(L,k);
 Lfin:=droit(L,n-k);
 si S &lt; a alors r:=0 ;fsi;
 retourne La,Lfin,S,S-r;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketdimgros(L,60,10)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">1*15+2*7.8+5*2.2*0.9+4*5.5*0.9
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
En syntaxe Python :

</p><pre class="verbatim">def Ticketdimgros(L,a,r) :
    # local S,n,k,Lfin,La 
    n=dim(L)
    S=0
    k=0
    while k &lt; n and S&lt;a :
        S=S+Prix(L[k],L[k+1])
        k=k+2
    La=gauche(L,k)
    Lfin=droit(L,n-k)
    if S &lt; a :
        r=0 
    return La,Lfin,S,S-r
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketdimgros(L,60,10)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">1*15+2*7.8+5*2.2*0.9+4*5.5*0.9
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Transformation en boucle </span><span style="font-weight:bold"><span style="font-family:monospace">pour</span></span>
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Ticketdimgros1(L,a,r) 
 local S,n,k,Lfin,La; 
 n:=dim(L);
 S:=0;
 pour k de 0 jusque n-1 pas 2 faire
   S:=S+Prix(L[k],L[k+1]);
   si S&gt;=a alors 
     La:=gauche(L,k+2);
     Lfin:=droit(L,n-k-2);
     retourne La,Lfin,S,S-r;
   fsi;
 fpour;
 retourne La,[],S,S;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketdimgros1(L,60,10)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">1*15+2*7.8+5*2.2*0.9+4*5.5*0.9
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>En syntaxe Python :

</p><pre class="verbatim">def Ticketdimgros1(L,a,r):
    # local S,n,k,Lfin,La
    n=dim(L)
    S=0
    for k in range(0,n,2):
        S=S+Prix(L[k],L[k+1])
        if S&gt;=a :
            La=gauche(L,k+2)
            Lfin=droit(L,n-k-2)
            return La,Lfin,S,S-r
    return La,[],S,S
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[1,15,2,7.8,5,2.2,4,5.5,2,2.7,1,2.1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Ticketdimgros1(L,60,10)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">1*15+2*7.8+5*2.2*0.9+4*5.5*0.9
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec65" Exercice : Algorithme de tracé de courbe-->
<h2 id="sec65" class="section">3.17  Exercice : Algorithme de tracé de courbe</h2><!--SEC END --><p><a id="hevea_default104"></a><a id="hevea_default105"></a>
Soit la fonction <span style="font-family:monospace">f</span> définie sur <span style="font-family:monospace">[a,b]</span>.<br>
 On veut tracer le graphe de cette fonction sur l’intervalle <span style="font-family:monospace">[a,b]</span>.<br>
 En partageant <span style="font-family:monospace">[a,b]</span> en <span style="font-family:monospace">n</span> parties égales on obtient : <br>
<span style="font-family:monospace">a=a0,a1=a+h,a2=a+2h, ...b=a+n*h</span> avec <span style="font-family:monospace">h=(b-a)/n</span>.
Le graphe sera obtenu en reliant les points de coordonnées <span style="font-family:monospace">[a f(a)]</span>
<span style="font-family:monospace">[a1 f(a1)]</span> etc ... par des segments.<br>
En syntaxe <span style="font-family:monospace">Xcas</span> :

</p><pre class="verbatim">fonction Graphe(f,a,b,n)
 local L,h,k;
 L:=NULL;
 h:=(b-a)/n;
 pour k de 0 jusque n-1 faire
   L:=L,segment(point(a,f(a)),point(a+h,f(a+h)));
   a:=a+h;
 fpour;
 retourne L;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f(x):=x^2+1
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">g(x):=(x+1)/(x-1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Graphe(f,-2,2,100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Graphe(g,-12,12,100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Graphe(Abs1,-10,12,100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>En syntaxe Python :

</p><pre class="verbatim">def Graphe(f,a,b,n):
    # local L,h,k
    L=NULL
    h=(b-a)/n
    for k in range(n):
        L=L,segment(point(a,f(a)),point(a+h,f(a+h)))
        a=a+h
    return L
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f(x):=x^2+1
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">g(x):=(x+1)/(x-1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Graphe(f,-2,2,100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Graphe(g,-12,12,100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Graphe(Abs1,-10,12,100)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec66" Mettre au point un programme-->
<h2 id="sec66" class="section">3.18  Mettre au point un programme</h2><!--SEC END --><p>
Lorsqu’on écrit un programme, il y a deux étapes
à franchir :
</p><ul class="itemize"><li class="li-itemize">
Écrire un programme syntaxiquement correct. Quand on
tape sur le bouton ok, on <span style="font-family:monospace">compile</span> le programme 
(plus préciśement il est interprété). 
Les erreurs à ce stade sont appelées
<span style="font-weight:bold">erreurs de syntaxe</span><a id="hevea_default106"></a><a id="hevea_default107"></a>.<br>
Certaines interfaces de <span style="font-family:monospace">Xcas</span> essaient de placer
le curseur à l’endroit de l’erreur, d’autres affichent le numéro
de ligne et colonne de l’erreur. Il faut garder en tête que
l’erreur peut être située avant l’endroit indiqué par le curseur
ou dans le message d’erreur, l’endroit indiqué est le premier endroit
où l’interpréteur ne comprend plus la syntaxe.
</li><li class="li-itemize">S’assurer que le programme fait bien ce qu’on attend de lui.
Si ce n’est pas le cas on parle d’<span style="font-weight:bold">erreur 
d’exécution</span><a id="hevea_default108"></a><a id="hevea_default109"></a> 
(en anglais runtime error). <br>
Pour corriger ce type d’erreur, <span style="font-family:monospace">Xcas</span>
propose une commande appelée <code>debug</code><a id="hevea_default110"></a>. Au lieu d’appeler
directement le programme, on le place dans <code>debug()</code>,
par exemple au lieu de taper <code>Graphe(f,-2,2,100)</code>
on tape <code>debug(Graphe(f,-2,2,100))</code>
Le debogueur affiche alors la liste des variables locales et leur valeur
ainsi que la prochaine ligne du programme qui sera exécutée. On
peut alors exécuter ligne par ligne le programme avec des arguments
pour lequel on connait la réponse, regarder l’évolution
des valeurs des variables et comprendre plus facilement pourquoi
le programme ne fait pas ce qui est attendu.
</li></ul>
<!--TOC chapter id="sec67" Résolution d’équations-->
<h1 id="sec67" class="chapter">Chapitre 4  Résolution d’équations</h1><!--SEC END -->
<!--TOC section id="sec68" Encadrer une racine d’une équation par dichotomie-->
<h2 id="sec68" class="section">4.1  Encadrer une racine d’une équation par dichotomie</h2><!--SEC END --><p> <a id="sec:dichotomie"></a>
<span style="font-weight:bold">Algorithme de dichotomie</span><br>
On suppose que la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi></mrow><annotation encoding='application/x-tex'>f</annotation></semantics></math> est continue sur 
l’intervalle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[a,b]</annotation></semantics></math> et que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mi>&lt;</mi><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(a)&amp;lt;0</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>b</mi><mo stretchy="false">)</mo><mi>&gt;</mi><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(b)&amp;gt;0</annotation></semantics></math>
(si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mi>&gt;</mi><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(a)&amp;gt;0</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>b</mi><mo stretchy="false">)</mo><mi>&lt;</mi><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(b)&amp;lt;0</annotation></semantics></math> on peut se ramener au cas précédent
en échangeant <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math>).
On en déduit que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi></mrow><annotation encoding='application/x-tex'>f</annotation></semantics></math> s’annule pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>=</mo><msub><mi>x</mi> <mn>0</mn></msub></mrow><annotation encoding='application/x-tex'>x=x_0</annotation></semantics></math> avec <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mi>&lt;</mi><msub><mi>x</mi> <mn>0</mn></msub><mi>&lt;</mi><mi>b</mi></mrow><annotation encoding='application/x-tex'>a&amp;lt;x_0&amp;lt;b</annotation></semantics></math>, 
on cherche une valeur approchée de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>x</mi> <mn>0</mn></msub></mrow><annotation encoding='application/x-tex'>x_0</annotation></semantics></math>.</p><p>Pour avoir une meilleur approximation de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>x</mi> <mn>0</mn></msub></mrow><annotation encoding='application/x-tex'>x_0</annotation></semantics></math>, on cherche le signe de 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>f(c)</annotation></semantics></math> où <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi><mo>=</mo><mfrac><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow><mn>2</mn></mfrac></mrow><annotation encoding='application/x-tex'>c=\frac{a+b}{2}</annotation></semantics></math> est le milieu de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[a,b]</annotation></semantics></math>.
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(c)=0</annotation></semantics></math> alors <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>x</mi> <mn>0</mn></msub><mo>=</mo><mi>c</mi></mrow><annotation encoding='application/x-tex'>x_0=c</annotation></semantics></math> et on est content !
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo><mi>&lt;</mi><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(c)&amp;lt; 0</annotation></semantics></math>, il est de même signe que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>f(a)</annotation></semantics></math>,
on peut donc remplacer <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi></mrow><annotation encoding='application/x-tex'>c</annotation></semantics></math>, sinon <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo><mi>&gt;</mi><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(c)&amp;gt;0</annotation></semantics></math> est de 
même signe que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>b</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>f(b)</annotation></semantics></math>, on peut remplacer <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi></mrow><annotation encoding='application/x-tex'>c</annotation></semantics></math>.
On recommence le processus jusquà ce que
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(c)=0</annotation></semantics></math> ou <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">&vert;</mo><mi>b</mi><mo>&minus;</mo><mi>a</mi><mo stretchy="false">&vert;</mo><mi>&lt;</mi><msup><mn>10</mn> <mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mi>n</mi></mrow></msup></mrow><annotation encoding='application/x-tex'>|b&#x2d;a|&amp;lt;10^{&#x2d;n}</annotation></semantics></math> (avec par exemple <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi><mo>=</mo><mn>3</mn></mrow><annotation encoding='application/x-tex'>n=3</annotation></semantics></math>).

</p><pre class="verbatim">fonction Dichotomie0(f,a,b,n)
 local c;
 si f(a)*f(b)&gt;0 alors retourne [] fsi; 
 si f(a)==0 alors retourne [a] fsi;
 si f(b)==0 alors retourne [b] fsi;
 si f(a)&gt;0 alors a,b:=b,a; fsi; // echange a et b pour avoir f(a)&lt;=0
 tantque abs(b-a)&gt;10^(-n) faire
   c:=evalf(a+b)/2;
   si f(c)=0 alors retourne [c] fsi;
   si f(c)&lt;0 alors a:=c; sinon b:=c; fsi; // on a f(a)&lt;=0
 ftantque
 retourne [c];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


Notez le test d’arrêt qui utilise <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">&vert;</mo><mi>b</mi><mo>&minus;</mo><mi>a</mi><mo stretchy="false">&vert;</mo></mrow><annotation encoding='application/x-tex'>|b&#x2d;a|</annotation></semantics></math> car <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> ont peut-être
été échangés.
Exemple :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">f(x):=x^2-2
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Dichotomie0(f,1,2,12)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">g(x):=cos(x)-x
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Dichotomie0(g,0.,1.,12)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>On peut rajouter en début de programme
un test sur <span style="font-family:monospace">n</span> pour que le nombre d’itérations 
ne soit pas trop grand, par exemple<br>
<span style="font-family:monospace">si n&gt;12 alors n:=12; fsi;</span><br>
On peut aussi utiliser une variable locale pour ne faire qu’une seule fois
le calcul de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mn>10</mn> <mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mi>n</mi></mrow></msup></mrow><annotation encoding='application/x-tex'>10^{&#x2d;n}</annotation></semantics></math> et de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>f(c)</annotation></semantics></math>. Ce qui donne le programme suivant :

</p><pre class="verbatim">fonction Dichotomie1(f,a,b,n)
 local c,fc,eps;
 si f(a)*f(b)&gt;0 alors retourne [] fsi; 
 si f(a)==0 alors retourne [a] fsi;
 si f(b)==0 alors retourne [b] fsi;
 si f(a)&gt;0 alors a,b:=b,a; fsi; // echange a et b pour avoir f(a)&lt;=0
 si n&gt;12 alors n:=12; fsi;
 eps:=10^(-n);
 tantque abs(b-a)&gt;eps faire
   c:=evalf(a+b)/2;
   fc:=f(c);
   si fc=0 alors retourne [c] fsi;
   si fc&lt;0 alors a:=c; sinon b:=c; fsi; // on a f(a)&lt;0
 ftantque
 retourne [c];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">g(x):=cos(x)-x
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Dichotomie1(g,0.,1.,12)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>Il n’est pas indispensable de tester que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(a)=0</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>b</mi><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(b)=0</annotation></semantics></math> 
et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(c)=0</annotation></semantics></math> (comme cela n’arrive
pratiquement jamais, c’est donc inefficace de le faire), 
on peut supprimer ces lignes. Il faut alors utiliser <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo><mo>&leq;</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(c)\leq 0</annotation></semantics></math>
comme test (au lieu de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo><mi>&lt;</mi><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(c)&amp;lt;0</annotation></semantics></math>)
pour conserver comme invariant de boucle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>&leq;</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(a)\leq 0</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>b</mi><mo stretchy="false">)</mo><mi>&gt;</mi><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(b)&amp;gt;0</annotation></semantics></math>.

</p><pre class="verbatim">fonction Dichotomie(f,a,b,n)
 local c,eps;
 si f(a)*f(b)&gt;0 alors retourne [] fsi; 
 si f(a)&gt;0 alors a,b:=b,a; fsi; // echange a et b pour avoir f(a)&lt;=0
 si n&gt;12 alors n:=12; fsi;
 eps:=10^(-n);
 tantque abs(b-a)&gt;eps faire
   c:=evalf(a+b)/2; // invariant f(a)&lt;=0 et f(b)&gt;0
   si f(c)&lt;=0 alors a:=c; sinon b:=c; fsi; 
 ftantque
 retourne [c];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Dichotomie(g,0.,1.,12)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<span style="font-weight:bold">Traduction du “tantque” en “pour”</span><br>
On observe qu’à chaque itération de la boucle 
on divise la longueur de l’intervalle par 2, le nombre
d’itérations ne peut pas être très grand.
On peut donc transformer la boucle “tantque” en boucle “pour”
en se fixant à priori un nombre maximal d’itérations ce qui
évitera d’ailleurs d’avoir une boucle qui ne se termine jamais. On
montrera plus bas que 2100 itérations
suffisent en calcul approché.

</p><pre class="verbatim">fonction Dichotomie2(f,a,b,n)
 local c,k,eps;
 eps:=10^-n;
 si f(a)*f(b)&gt;0 alors retourne []; fsi; 
 pour k de 1 jusque 2100 faire
   c:=(a+b)/2.0; // invariant f(a)*f(b)&lt;=0
   si b-a&lt;eps alors retourne [c]; fsi;
   si f(a)*f(c)&lt;=0 alors b:=c; sinon a:=c; fsi;
 fpour;
 retourne [c];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">g(x):=cos(x)-x
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Dichotomie2(g,0.,1.,12)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Exercice :</span> modifier le programme pour ne pas faire le calcul de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>f(a)</annotation></semantics></math>
dans la boucle.</p><p>Remarque avancée : 
si on connaît les logarithmes, on peut calculer 
le nombre d’itérations <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi></mrow><annotation encoding='application/x-tex'>N</annotation></semantics></math> 
pour que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">&vert;</mo><mi>b</mi><mo>&minus;</mo><mi>a</mi><mo stretchy="false">&vert;</mo><mo stretchy="false">/</mo><msup><mn>2</mn> <mi>N</mi></msup><mi>&lt;</mi><msup><mn>10</mn> <mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mi>n</mi></mrow></msup></mrow><annotation encoding='application/x-tex'>|b&#x2d;a|/2^N&amp;lt;10^{&#x2d;n}</annotation></semantics></math> en résolvant cette équation.
On peut aussi observer que les calculs se font en approché, dans <span style="font-family:monospace">Xcas</span> 
le plus grand nombre représentable par défaut 
est <code>evalf(2^(1024-1)</code>, donc la taille
du plus grand intervalle est (légèrement inférieure à)
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mn>2</mn> <mn>1025</mn></msup></mrow><annotation encoding='application/x-tex'>2^{1025}</annotation></semantics></math>. Le plus petit réel strictement positif représentable
est <code>evalf(2^(-1069))</code>. Comme on divise par 2 la taille
de l’intervalle à chaque itération, le nombre maximal d’itérations
est au plus 1025+1069=2094<sup><a id="text3" href="#note3">1</a></sup>. 
Au-delà, soit <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> sont représentés
par le même nombre flottant (et le test <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">&vert;</mo><mi>b</mi><mo>&minus;</mo><mi>a</mi><mo stretchy="false">&vert;</mo><mi>&lt;</mi><msup><mn>10</mn> <mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mi>n</mi></mrow></msup></mrow><annotation encoding='application/x-tex'>|b&#x2d;a|&amp;lt;10^{&#x2d;n}</annotation></semantics></math> sera
donc vrai) soit ils ne différeront que par leur dernier bit de mantisse,
et dans ce cas <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi><mo>=</mo><mo stretchy="false">(</mo><mi>a</mi><mo>+</mo><mi>b</mi><mo stretchy="false">)</mo><mo stretchy="false">/</mo><mn>2</mn></mrow><annotation encoding='application/x-tex'>c=(a+b)/2</annotation></semantics></math> sera arrondi vers <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> ou vers <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> et la boucle
<span style="font-family:monospace">tanque</span> continuera indéfiniment.<br>
La majoration est le plus souvent très pessimiste, par exemple 
si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>a=1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi><mo>=</mo><mn>2</mn></mrow><annotation encoding='application/x-tex'>b=2</annotation></semantics></math> ils sont déjà représentés avec le même
exposant et le nombre d’itérations sera limité par 48.

</p><pre class="verbatim">fonction Dichotomie3(f,a,b,n)
 local c,k,N;
 si f(a)*f(b)&gt;0 alors retourne []; fsi; 
 N:=ceil(log((b-a)/10^(-n))/log(2)); 
 si N&gt;2100 alors N:=2100 fsi;
 pour k de 1 jusque N faire
   c:=(a+b)/2.0; // f(a)*f(b)&lt;=0
   si f(a)*f(c)&lt;=0 alors b:=c; sinon a:=c; fsi;
 fpour;
 retourne [c];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">g(x):=cos(x)-x
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Dichotomie3(g,0.,1.,12)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-weight:bold">Exercice :</span> Modifier la fonction ci-dessus pour calculer <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi></mrow><annotation encoding='application/x-tex'>f</annotation></semantics></math> une
seule fois par itération, c’est-à-dire qu’on calcule <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi></mrow><annotation encoding='application/x-tex'>c</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>f(c)</annotation></semantics></math> 
mais qu’on ne recalcule pas <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>f(a)</annotation></semantics></math>.<br>
<span style="font-weight:bold">Première méthode :</span><br>
On introduit 3 variables locales <span style="font-family:monospace">fa, fb, fc</span> contenant les valeurs
de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>f(a)</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>b</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>f(b)</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>f(c)</annotation></semantics></math>. On en profite pour tester au passage si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(c)=0</annotation></semantics></math>.

</p><pre class="verbatim">fonction Dichotomie4(f,a,b,n)
 local c,k,N,fa,fb,fc;
 fa:=f(a);
 fb:=f(b);
 si fa*fb&gt;0 alors retourne []; fsi; 
 si fa==0 alors retourne [a] fsi;
 si fb==0 alors retourne [b] fsi;
 N:=ceil(log((b-a)/10^(-n))/log(2)); 
 si N&gt;2100 alors N:=2100 fsi;
 pour k de 1 jusque N faire
   c:=(a+b)/2.0;
   fc:=f(c);
   si fc==0 alors retourne [c] fsi;
   si fa*fc&lt;0 alors b:=c; sinon a:=c; fa:=fc; fsi;
 fpour;
 retourne [c];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">g(x):=cos(x)-x
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Dichotomie4(g,0.,1.,12)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<span style="font-weight:bold">Deuxième méthode :</span><br>
On échange le rôle de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mi>&gt;</mi><mn>0</mn></mrow><annotation encoding='application/x-tex'>f(a)&amp;gt;0</annotation></semantics></math>.

</p><pre class="verbatim">fonction Dichotomie5(f,a,b,n)
 local c,k,N;
 si f(a)*f(b)&gt;0 alors retourne []; fsi; 
 N:=ceil(log(abs(b-a)/10^(-n))/log(2)); 
 si N&gt;2100 alors N:=2100 fsi;
 si f(a)&gt;0 alors a,b:=b,a; fsi;
 pour k de 1 jusque N faire
   c:=(a+b)/2.0; // invariant f(a)&lt;=0 et f(b)&gt;0
   si f(c)&lt;=0 alors a:=c; sinon b:=c; fsi;
 fpour;
 retourne [c];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">g(x):=cos(x)-x
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Dichotomie5(g,0.,1.,12)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Ce programme est optimal.</p><p>On peut vérifier ces résultats en utilisant la commande <span style="font-family:monospace">fsolve</span> de 
<span style="font-family:monospace">Xcas</span> qui effectue la résolution numérique d’une équation :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">fsolve(cos(x)=x,x,0..1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec69" Résoudre dans <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Ropf;</mi></mrow><annotation encoding='application/x-tex'>\mathbb{R}</annotation></semantics></math> une équation se ramenant au premier degré ou au degré 2-->
<h2 id="sec69" class="section">4.2  Résoudre dans <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Ropf;</mi></mrow><annotation encoding='application/x-tex'>\mathbb{R}</annotation></semantics></math> une équation se ramenant au premier degré ou au degré 2</h2><!--SEC END --><p><a id="sec:Solution12"></a>
On considère une équation qui se ramène au premier ou au deuxième
degré.<br>
Si cette équation se ramène au premier degré, elle est de la forme :
</p><div class="center"><span style="font-family:monospace">a*x+b=0</span> avec <span style="font-family:monospace">a!=0</span></div><p>
donc cette équation a une solution qui est:<br>
 <span style="font-family:monospace">x0:=-b/a</span>.<br>
Si cette équation se ramène au deuxième degré, elle est de la forme :
</p><div class="center"><span style="font-family:monospace">a*x</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+b*x+c=0</span> avec <span style="font-family:monospace">a!=0</span></div><p> 
donc :
</p><ul class="itemize"><li class="li-itemize">
si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Delta;</mi></mrow><annotation encoding='application/x-tex'>\Delta</annotation></semantics></math>=<span style="font-family:monospace">b</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2-4*a*c&gt;0</span> il y a 2 solutions qui sont :<br>
 <span style="font-family:monospace">x1:=(-b</span>+<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msqrt><mi>&Delta;</mi></msqrt><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>\sqrt\Delta)</annotation></semantics></math><span style="font-family:monospace">)/(2*a)</span> et
<span style="font-family:monospace">x2:=(-b</span>-<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msqrt><mi>&Delta;</mi></msqrt><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>\sqrt\Delta)</annotation></semantics></math><span style="font-family:monospace">)/(2*a)</span>.
</li><li class="li-itemize">si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Delta;</mi></mrow><annotation encoding='application/x-tex'>\Delta</annotation></semantics></math>=<span style="font-family:monospace">b</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2-4*a*c=0</span> il y a 1 solution qui est :<br>
 <span style="font-family:monospace">x1</span> et <span style="font-family:monospace">x1:=-b/(2*a)</span>
</li><li class="li-itemize">si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Delta;</mi></mrow><annotation encoding='application/x-tex'>\Delta</annotation></semantics></math>=<span style="font-family:monospace">b</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2-4*a*c&lt;0</span> il n’y a pas de solution réelle.
</li></ul><p>
On tape :

</p><pre class="verbatim">fonction Solution12(Eq,Var)
 local a,b,c,d;
 Eq:=normal(gauche(Eq)-droit(Eq));
 si degree(Eq,Var)==0 alors 
   si (Eq==0) alors retourne "infinite de solution" ;
   sinon retourne "pas de solution" ;
   fsi;
 fsi; 
 si degree(Eq,Var)==1 alors 
   //a:=coeff(Eq,Var,1);b:=coeff(Eq,Var,0);
   b:=subst(Eq,Var=0);
   a:=subst(Eq,Var=1)-b;
   retourne normal([-b/a]);
 fsi;
 si degree(Eq,Var)==2 alors 
   //a:=coeff(Eq,Var,2);b:=coeff(Eq,Var,1);c:=coeff(Eq,Var,0);
   c:=subst(Eq,Var=0);
   d:=subst(Eq,Var=1);
   b:=(d-subst(Eq,Var=-1))/2;
   a:=d-b-c;
   d:=b^2-4*a*c;
   si d&gt;0 alors retourne simplify([(-b+sqrt(d))/(2*a),(-b-sqrt(d))/(2*a)]);fsi;
   si d==0 alors retourne simplify([-b/(2*a)]); fsi;
   retourne [];
 fsi;
 retourne "degree &gt;2";
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">purge(x)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Solution12(2*x^2+2*x+2=x^2+2*x+4,x)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Solution12(2*x^2+2*x+2=2x^2+x+4,x)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Solution12(2*x^2+2*x+1=-2*x+31,x)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Solution12(2*x^2+2*x+1=-2*x-2,x)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec70" Résoudre un système de deux équations du premier degré à deux inconnues.-->
<h2 id="sec70" class="section">4.3  Résoudre un système de deux équations du premier degré à deux inconnues.</h2><!--SEC END --><p>
On veut résoudre le système de deux équations du premier degré <br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>a</mi> <mn>1</mn></msub><mi>x</mi><mo>+</mo><msub><mi>b</mi> <mn>1</mn></msub><mi>y</mi><mo>+</mo><msub><mi>c</mi> <mn>1</mn></msub><mo>=</mo><mn>0</mn><mo>,</mo><mspace width="1em"/><msub><mi>a</mi> <mn>2</mn></msub><mi>x</mi><mo>+</mo><msub><mi>b</mi> <mn>2</mn></msub><mi>y</mi><mo>+</mo><msub><mi>c</mi> <mn>2</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>a_1 x+b_1 y+c_1=0, \quad a_2x+b_2y+c_2=0 </annotation></semantics></math>
à deux inconnues <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>,</mo><mi>y</mi></mrow><annotation encoding='application/x-tex'>x,y</annotation></semantics></math>. On notera <span style="font-family:monospace">a1, b1, c1, a2, b2, c2</span> les
coefficients des équations dans les programmes.<br>
Pour éviter d’étudier des cas particuliers inintéressants, on va 
supposer que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><msub><mi>a</mi> <mn>1</mn></msub><mo>,</mo><msub><mi>b</mi> <mn>1</mn></msub><mo stretchy="false">)</mo><mo>&ne;</mo><mo stretchy="false">(</mo><mn>0</mn><mo>,</mo><mn>0</mn><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>(a_1,b_1)\neq (0,0)</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><msub><mi>a</mi> <mn>2</mn></msub><mo>,</mo><msub><mi>b</mi> <mn>2</mn></msub><mo stretchy="false">)</mo><mo>&ne;</mo><mo stretchy="false">(</mo><mn>0</mn><mo>,</mo><mn>0</mn><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>(a_2,b_2) \neq (0,0)</annotation></semantics></math>. 
Dans ce cas <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>1</mn></msub><mi>x</mi><mo>+</mo><msub><mi>b</mi> <mn>1</mn></msub><mi>y</mi><mo>+</mo><msub><mi>c</mi> <mn>1</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>a_1 x+b_1 y+c_1=0</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>2</mn></msub><mi>x</mi><mo>+</mo><msub><mi>b</mi> <mn>2</mn></msub><mi>y</mi><mo>+</mo><msub><mi>c</mi> <mn>2</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> a_2x+b_2y+c_2=0</annotation></semantics></math>
sont les équations de 2 droites <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math>.</p><p><span style="font-weight:bold">Solution géométrique</span>
</p><ul class="itemize"><li class="li-itemize">
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math> sont concourantes, il y a une seule solution.
Pour la déterminer, on peut utiliser la commande 
<span style="font-family:monospace">solve</span> de <span style="font-family:monospace">Xcas</span><br>
<br><textarea onkeypress="UI.ckenter(event,this,2)" 
style="width:400px;font-size:large">solve([a1*x+b1*y+c1=0,a2*x+b2*y+c2=0],[x,y]) 
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value); tmp=UI.latexeval(tmp);nextSibling.innerHTML='&nbsp;'+tmp; if (UI.usemathjax) MathJax.Hub.Queue(['Typeset',MathJax.Hub,nextSibling])">ok</button><span></span><br>
<br>
On justifiera ce résultat plus bas.
</li><li class="li-itemize">Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math> sont parallèles il n’y a pas de solution, sauf si
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math> sont confondues, il y a une infinité de solutions. On
va montrer que cela se produit si et seulement si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>1</mn></msub><msub><mi>b</mi> <mn>2</mn></msub><mo>&minus;</mo><msub><mi>a</mi> <mn>2</mn></msub><msub><mi>b</mi> <mn>1</mn></msub><mo>&ne;</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>a_1 b_2&#x2d;a_2b_1 \neq 0</annotation></semantics></math>.<br>
En effet, 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math> sont parallèles lorsque les coefficients <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>a</mi> <mn>1</mn></msub><mo>,</mo><msub><mi>b</mi> <mn>1</mn></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> [a_1,b_1]</annotation></semantics></math> 
et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>a</mi> <mn>2</mn></msub><mo>,</mo><msub><mi>b</mi> <mn>2</mn></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> [a_2,b_2]</annotation></semantics></math> sont proportionnels i.e si il existe <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>k</mi><mo>&ne;</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> k\neq0</annotation></semantics></math> tel que :<br>
 <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>a</mi> <mn>1</mn></msub><mo>,</mo><msub><mi>b</mi> <mn>1</mn></msub><mo stretchy="false">]</mo><mo>=</mo><mi>k</mi><mo stretchy="false">[</mo><msub><mi>a</mi> <mn>2</mn></msub><mo>,</mo><msub><mi>b</mi> <mn>2</mn></msub><mo stretchy="false">]</mo><mo>=</mo><mo stretchy="false">[</mo><mi>k</mi><msub><mi>a</mi> <mn>2</mn></msub><mo>,</mo><mi>k</mi><msub><mi>b</mi> <mn>2</mn></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> [a_1,b_1]=k[a_2,b_2]=[ka_2,kb_2]</annotation></semantics></math> ce qui entraine :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mo stretchy="false">(</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>1</mn></msub><mo stretchy="false">)</mo><mo>=</mo><mi>k</mi><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>2</mn></msub><mo>&minus;</mo><mi>k</mi><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>2</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>(b_1a_2&#x2d;b_2a_1)=kb_2a_2&#x2d;kb_2a_2=0 </annotation></semantics></math>
Réciproquement, si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub><mo>=</mo><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>1</mn></msub><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'> (b_1a_2=b_2a_1)</annotation></semantics></math> alors <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math> sont 
parallèles ou confondues.<br>
En effet :
<ul class="itemize"><li class="li-itemize">
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>b</mi> <mn>1</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> b_1=0</annotation></semantics></math> (resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>1</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> a_1=0</annotation></semantics></math>) alors <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>b</mi> <mn>2</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> b_2=0</annotation></semantics></math> (resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>2</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> a_2=0</annotation></semantics></math>) puisque 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>a</mi> <mn>1</mn></msub><mo>,</mo><msub><mi>b</mi> <mn>1</mn></msub><mo stretchy="false">]</mo><mo>&ne;</mo><mo stretchy="false">[</mo><mn>0</mn><mo>,</mo><mn>0</mn><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> [a_1,b_1]\neq[0,0]</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub><mo>=</mo><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>1</mn></msub><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'> (b_1a_2=b_2a_1)</annotation></semantics></math>, donc 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math> sont parallèles à l’axe des <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'> x</annotation></semantics></math> (resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi></mrow><annotation encoding='application/x-tex'> y</annotation></semantics></math>).
</li><li class="li-itemize">Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>b</mi> <mn>1</mn></msub><mo>&ne;</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> b_1\neq0</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>1</mn></msub><mo>&ne;</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> a_1\neq0</annotation></semantics></math> alors <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>b</mi> <mn>2</mn></msub><mo stretchy="false">/</mo><msub><mi>b</mi> <mn>1</mn></msub><mo>=</mo><mo>=</mo><msub><mi>a</mi> <mn>2</mn></msub><mo stretchy="false">/</mo><msub><mi>a</mi> <mn>1</mn></msub><mo>=</mo><mi>k</mi></mrow><annotation encoding='application/x-tex'> b_2/b_1==a_2/a_1=k</annotation></semantics></math> ce qui signifie que
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math> sont parallèles ou confondues 
(<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math> sont confondues lorsque les coefficients <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>a</mi> <mn>1</mn></msub><mo>,</mo><msub><mi>b</mi> <mn>1</mn></msub><mo>,</mo><msub><mi>c</mi> <mn>1</mn></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> [a_1,b_1,c_1]</annotation></semantics></math> 
et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>a</mi> <mn>2</mn></msub><mo>,</mo><msub><mi>b</mi> <mn>2</mn></msub><mo>,</mo><msub><mi>c</mi> <mn>2</mn></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> [a_2,b_2,c_2]</annotation></semantics></math> sont proportionnels i.e si il existe <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>k</mi><mo>&ne;</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> k\neq0</annotation></semantics></math> tel que :<br>
 <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>a</mi> <mn>1</mn></msub><mo>,</mo><msub><mi>b</mi> <mn>1</mn></msub><mo>,</mo><msub><mi>c</mi> <mn>1</mn></msub><mo stretchy="false">]</mo><mo>=</mo><mi>k</mi><mo stretchy="false">[</mo><msub><mi>a</mi> <mn>2</mn></msub><mo>,</mo><msub><mi>b</mi> <mn>2</mn></msub><mo>,</mo><msub><mi>c</mi> <mn>2</mn></msub><mo stretchy="false">]</mo><mo>=</mo><mo stretchy="false">[</mo><mi>k</mi><msub><mi>a</mi> <mn>2</mn></msub><mo>,</mo><mi>k</mi><msub><mi>b</mi> <mn>2</mn></msub><mo>,</mo><mi>k</mi><msub><mi>c</mi> <mn>2</mn></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> [a_1,b_1,c_1]=k[a_2,b_2,c_2]=[ka_2,kb_2,kc_2]</annotation></semantics></math>).
</li></ul>
</li></ul><p>On commence par écrire un programme dans le cas où les droites
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math> sont concourrantes.

</p><pre class="verbatim">fonction Intersection1(Eq1,Eq2,Var1,Var2)
 local a1,b1,c1,a2,b2,c2;
 Eq1:=normal(gauche(Eq1)-droit(Eq1));
 Eq2:=normal(gauche(Eq2)-droit(Eq2));
 a1:=coeff(Eq1,Var1,1);
 a2:=coeff(Eq2,Var1,1);
 b1:=coeff(Eq1,Var2,1);
 b2:=coeff(Eq2,Var2,1);
 si normal(a1*b2-a2*b1)==0 alors
   retourne "Cas non traite : Eq1 ou Eq2 n'est pas une  "+
          "equation de droite ou droites paralleles"; 
 fsi;
 c1:=subst(Eq1,[Var1,Var2],[0,0]);
 c2:=subst(Eq2,[Var1,Var2],[0,0]);
 print("droites concourantes");
 retourne [normal((-b2*c1+b1*c2)/(a1*b2-a2*b1)),
           normal((a2*c1-a1*c2)/(a1*b2-a2*b1))];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">purge(x,y)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">d1:=droite(x+y=3);d2:=droite(2x-y=9);d3:=droite(-4x+2y=3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Intersection1(x+y=3,2x-y=9,x,y)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Intersection1(4x-2y+9=0,2x-y=3,x,y)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<span style="font-weight:bold">Exercice :</span> modifiez le programme ci-dessus pour éviter de calculer
plusieurs fois <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>1</mn></msub><msub><mi>b</mi> <mn>2</mn></msub><mo>&minus;</mo><msub><mi>a</mi> <mn>2</mn></msub><msub><mi>b</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>a_1b_2&#x2d;a_2b_1</annotation></semantics></math>, en stockant sa valeur dans une variable 
locale.<br>

<span style="font-weight:bold">Correction de l’exercice :</span>

</p><pre class="verbatim">fonction Intersection2(Eq1,Eq2,Var1,Var2)
 local a1,b1,c1,a2,b2,c2,d;
 Eq1:=normal(gauche(Eq1)-droit(Eq1));
 Eq2:=normal(gauche(Eq2)-droit(Eq2));
 a1:=coeff(Eq1,Var1,1);
 a2:=coeff(Eq2,Var1,1);
 b1:=coeff(Eq1,Var2,1);
 b2:=coeff(Eq2,Var2,1);
 d:=normal(a1*b2-a2*b1);
 si d==0 alors
   retourne "Cas non traite : Eq1 ou Eq2 n'est pas une"+
    " equation de droite ou droites paralleles ou confondues"; 
 fsi;
 c1:=subst(Eq1,[Var1,Var2],[0,0]);
 c2:=subst(Eq2,[Var1,Var2],[0,0]);
 print("droites concourantes");
 retourne [normal((-b2*c1+b1*c2)/d),
           normal((a2*c1-a1*c2)/d)];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">d1:=droite(x+y=3);d2:=droite(2x-y=9);d3:=droite(-4x+2y=3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Intersection2(x+y=3,2x-y=9,x,y)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Intersection2(4x-2y+9=0,2x-y=3,x,y)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

Voici maintenant un programme qui teste que les équations
entrées sont bien des équations de droite et traite aussi 
le cas des droites parallèles ou confondues :

</p><pre class="verbatim">fonction Intersection(Eq1,Eq2,Var1,Var2)
 local a1,b1,c1,a2,b2,c2,d;
 Eq1:=normal(gauche(Eq1)-droit(Eq1));
 si degree(Eq1,Var1)&gt;1 et degree(Eq1,Var2)&gt;1  alors 
   retourne "pas de degre 1"; 
 fsi;
 Eq2:=normal(gauche(Eq2)-droit(Eq2));
 si degree(Eq2,Var1)&gt;1 et degree(Eq2,Var2)&gt;1 alors 
   retourne "pas de degre 1"; 
 fsi;
 a1:=coeff(Eq1,Var1,1);
 a2:=coeff(Eq2,Var1,1);
 b1:=coeff(Eq1,Var2,1);
 b2:=coeff(Eq2,Var2,1);
 si [a1,b1]==[0,0] ou [a2,b2]==[0,0] alors 
   retourne "Eq1 ou Eq2 est nulle"; 
 fsi;
 c1:=subst(Eq1,[Var1,Var2],[0,0]);
 c2:=subst(Eq2,[Var1,Var2],[0,0]);
 d:=normal(a1*b2-a2*b1);
 si d!=0 alors 
   print("droites concourantes");
   retourne [normal((-b2*c1+b1*c2)/d),
             normal((a2*c1-a1*c2)/d)];
 fsi;
 si a1!=0 et a2!=0 alors 
   si c1*a2-c2*a1==0 alors 
     print("droites confondues");
     retourne [normal(-c1/a1),Var2]; 
   sinon 
     print("droites paralleles");
     retourne [] ;
   fsi;
 fsi;    
 si b1!=0 et b2!=0 alors 
   si c1*b2==c2*b1 alors 
     print("droites confondues");
     retourne [Var1,normal(-c1/b1)]; 
   sinon 
     print("droites paralleles");
     retourne [];
   fsi;
 fsi;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Intersection(x+y=3,2x-y=9,x,y)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Intersection(4x-2y+3=0,2x-y=9,x,y)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On vérifie avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">coordonnees(inter_unique(d1,d2))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">est_parallele(d2,d3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Justification de la solution lorsque </span><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math><span style="font-weight:bold"> et </span><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math><span style="font-weight:bold"> sont concourantes</span><br>
On a vu que c’était le cas si et seulement si
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>1</mn></msub><mo>&ne;</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> b_1a_2&#x2d;b_2a_1\neq0</annotation></semantics></math>.
</p><ul class="itemize"><li class="li-itemize">
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>b</mi> <mn>1</mn></msub><mo>&ne;</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> b_1\neq0</annotation></semantics></math> on a <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi><mo>=</mo><mo stretchy="false">(</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>a</mi> <mn>1</mn></msub><mi>x</mi><mo>&minus;</mo><msub><mi>c</mi> <mn>1</mn></msub><mo stretchy="false">)</mo><mo stretchy="false">/</mo><msub><mi>b</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'> y=(&#x2d;a_1x&#x2d;c_1)/b_1</annotation></semantics></math> donc l’abscisse du point 
d’intersection de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math> vérifie :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub><mi>x</mi><mo>+</mo><msub><mi>b</mi> <mn>2</mn></msub><mo stretchy="false">(</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>a</mi> <mn>1</mn></msub><mi>x</mi><mo>&minus;</mo><msub><mi>c</mi> <mn>1</mn></msub><mo stretchy="false">)</mo><mo>+</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>c</mi> <mn>2</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> b_1a_2x+b_2(&#x2d;a_1x&#x2d;c_1)+b_1c_2=0</annotation></semantics></math><br>
donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>1</mn></msub><mo stretchy="false">)</mo><mi>x</mi><mo>+</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>c</mi> <mn>2</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>c</mi> <mn>1</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> (b_1a_2&#x2d;b_2a_1)x+b_1c_2&#x2d;b_2c_1=0</annotation></semantics></math> et finalement :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>x</mi><mo>=</mo><mfrac><mrow><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>c</mi> <mn>2</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>c</mi> <mn>1</mn></msub></mrow><mrow><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>1</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub></mrow></mfrac></mrow><annotation encoding='application/x-tex'>x=\frac{b_1c_2&#x2d;b_2c_1}{b_2a_1&#x2d;b_1a_2}  </annotation></semantics></math>
On remplace dans l’expression de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi></mrow><annotation encoding='application/x-tex'>y</annotation></semantics></math> en fonction de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>y</mi><mo>=</mo><mfrac><mn>1</mn><mrow><msub><mi>b</mi> <mn>1</mn></msub></mrow></mfrac><mo stretchy="false">(</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>a</mi> <mn>1</mn></msub><mfrac><mrow><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>c</mi> <mn>2</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>c</mi> <mn>1</mn></msub></mrow><mrow><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>1</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub></mrow></mfrac><mo>&minus;</mo><msub><mi>c</mi> <mn>1</mn></msub><mo stretchy="false">)</mo><mo>=</mo><mfrac><mn>1</mn><mrow><msub><mi>b</mi> <mn>1</mn></msub></mrow></mfrac><mo stretchy="false">(</mo><mfrac><mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>a</mi> <mn>1</mn></msub><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>c</mi> <mn>2</mn></msub><mo>+</mo><msub><mi>a</mi> <mn>1</mn></msub><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>c</mi> <mn>1</mn></msub><mo>&minus;</mo><msub><mi>c</mi> <mn>1</mn></msub><mo stretchy="false">(</mo><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>1</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub><mo stretchy="false">)</mo></mrow><mrow><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>1</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub></mrow></mfrac><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>y=\frac{1}{b_1}(&#x2d;a_1\frac{b_1c_2&#x2d;b_2c_1}{b_2a_1&#x2d;b_1a_2}&#x2d;c_1)=\frac{1}{b_1}(\frac{&#x2d;a_1b_1c_2+a_1b_2c_1&#x2d;c_1(b_2a_1&#x2d;b_1a_2)}{b_2a_1&#x2d;b_1a_2}) </annotation></semantics></math>
Donc
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>y</mi><mo>=</mo><mfrac><mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>a</mi> <mn>1</mn></msub><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>c</mi> <mn>2</mn></msub><mo>+</mo><msub><mi>c</mi> <mn>1</mn></msub><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub></mrow><mrow><msub><mi>b</mi> <mn>1</mn></msub><mo stretchy="false">(</mo><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>1</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub><mo stretchy="false">)</mo></mrow></mfrac><mo>=</mo><mfrac><mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>a</mi> <mn>1</mn></msub><msub><mi>c</mi> <mn>2</mn></msub><mo>+</mo><msub><mi>c</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub></mrow><mrow><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>1</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub></mrow></mfrac></mrow><annotation encoding='application/x-tex'>y=\frac{&#x2d;a_1b_1c_2+c_1b_1a_2}{b_1(b_2a_1&#x2d;b_1a_2)}=\frac{&#x2d;a_1c_2+c_1a_2}{b_2a_1&#x2d;b_1a_2} </annotation></semantics></math>
</li><li class="li-itemize">Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>b</mi> <mn>1</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'> b_1=0</annotation></semantics></math>, on va voir que les mêmes formules s’appliquent.
En effet l’abscisse du point d’intersection de 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math> vérifie <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>1</mn></msub><mi>x</mi><mo>+</mo><msub><mi>c</mi> <mn>1</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>a_1x+c_1=0</annotation></semantics></math> donc 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>x</mi><mo>=</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mfrac><mrow><msub><mi>c</mi> <mn>1</mn></msub></mrow><mrow><msub><mi>a</mi> <mn>1</mn></msub></mrow></mfrac><mo>=</mo><mfrac><mrow><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>c</mi> <mn>2</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>c</mi> <mn>1</mn></msub></mrow><mrow><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>1</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub></mrow></mfrac></mrow><annotation encoding='application/x-tex'>x=&#x2d;\frac{c_1}{a_1}=\frac{b_1c_2&#x2d;b_2c_1}{b_2a_1&#x2d;b_1a_2} </annotation></semantics></math>
Comme <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>b</mi> <mn>2</mn></msub><mo>&ne;</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>b_2\neq0</annotation></semantics></math>, on a 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>y</mi><mo>=</mo><mfrac><mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>a</mi> <mn>2</mn></msub><mi>x</mi><mo>&minus;</mo><msub><mi>c</mi> <mn>2</mn></msub></mrow><mrow><msub><mi>b</mi> <mn>2</mn></msub></mrow></mfrac><mo>=</mo><mfrac><mrow><msub><mi>a</mi> <mn>2</mn></msub><mfrac><mrow><msub><mi>c</mi> <mn>1</mn></msub></mrow><mrow><msub><mi>a</mi> <mn>1</mn></msub></mrow></mfrac><mo>&minus;</mo><msub><mi>c</mi> <mn>2</mn></msub></mrow><mrow><msub><mi>b</mi> <mn>2</mn></msub></mrow></mfrac><mo>=</mo><mfrac><mrow><msub><mi>a</mi> <mn>2</mn></msub><msub><mi>c</mi> <mn>1</mn></msub><mo>&minus;</mo><msub><mi>a</mi> <mn>1</mn></msub><msub><mi>c</mi> <mn>2</mn></msub></mrow><mrow><msub><mi>a</mi> <mn>1</mn></msub><msub><mi>b</mi> <mn>2</mn></msub></mrow></mfrac><mo>=</mo><mfrac><mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>a</mi> <mn>1</mn></msub><msub><mi>c</mi> <mn>2</mn></msub><mo>+</mo><msub><mi>c</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub></mrow><mrow><msub><mi>b</mi> <mn>2</mn></msub><msub><mi>a</mi> <mn>1</mn></msub><mo>&minus;</mo><msub><mi>b</mi> <mn>1</mn></msub><msub><mi>a</mi> <mn>2</mn></msub></mrow></mfrac></mrow><annotation encoding='application/x-tex'>y=\frac{&#x2d;a_2x&#x2d;c_2}{b_2}=\frac{a_2\frac{c_1}{a_1}&#x2d;c_2}{b_2}=\frac{a_2 c_1&#x2d;a_1 c_2}{a_1b_2}=\frac{&#x2d;a_1c_2+c_1a_2}{b_2a_1&#x2d;b_1a_2} </annotation></semantics></math>
</li></ul>
<!--BEGIN NOTES chapter-->
<hr class="footnoterule"><dl class="thefootnotes"><dt class="dt-thefootnotes">
<a id="note3" href="#text3">1</a></dt><dd class="dd-thefootnotes"><div class="footnotetext">Il faut ajouter 5 pour un langage 
traditionnel
où la mantisse a 53 chiffres significatifs. Attention, ceci n’est
plus valable dans <span style="font-family:monospace">Xcas</span> si on modifie la valeur de <span style="font-family:monospace">Digits</span></div></dd></dl>
<!--END NOTES-->
<!--TOC chapter id="sec71" Les figures en géométrie plane avec <span style="font-family:monospace">Xcas</span>-->
<h1 id="sec71" class="chapter">Chapitre 5  Les figures en géométrie plane avec <span style="font-family:monospace">Xcas</span></h1><!--SEC END -->
<!--TOC section id="sec72" Le point : <span style="font-family:monospace">point</span> et le segment : <span style="font-family:monospace">segment</span>-->
<h2 id="sec72" class="section">5.1  Le point : <span style="font-family:monospace">point</span> et le segment : <span style="font-family:monospace">segment</span></h2><!--SEC END --><p><a id="hevea_default111"></a><a id="hevea_default112"></a>
<span style="font-family:monospace">point</span> a comme arguments l’abscisse et l’ordonnée du point.<br>
<span style="font-family:monospace">point</span> trace le point à l’aide d’une croix sur l’écran de 
géométrie <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>2</mn><mi>d</mi></mrow><annotation encoding='application/x-tex'>2d</annotation></semantics></math>.<br>
Si on a donné un nom au point (par ex <span style="font-family:monospace">A:=point(1,1);</span> ou 
<span style="font-family:monospace">A:=point([1,1]);</span>) ce nom sera affiché à côté de la croix.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">A:=point(1,1);B:=point(2,3);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

<span style="font-family:monospace">segment</span> a comme argument 2 points.<br>
<span style="font-family:monospace">segment</span> trace le segment reliant ces 2 points sur l’écran de 
géométrie <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>2</mn><mi>d</mi></mrow><annotation encoding='application/x-tex'>2d</annotation></semantics></math>.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">A:=A;B:=B;segment(A,B);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC section id="sec73" Les coordonnées d’un point : <span style="font-family:monospace">coordonnees</span>-->
<h2 id="sec73" class="section">5.2  Les coordonnées d’un point : <span style="font-family:monospace">coordonnees</span></h2><!--SEC END --><p><a id="hevea_default113"></a>
<span style="font-family:monospace">coordonnees</span> a comme argument 1 point.<br>
<span style="font-family:monospace">coordonnees</span> renvoie la liste constitué de l’abscisse et de l’ordonnée
du point.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">coordonnees(A)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">coordonnees(B)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC section id="sec74" La droite et son équation : <span style="font-family:monospace">droite</span> et <span style="font-family:monospace">equation</span>-->
<h2 id="sec74" class="section">5.3  La droite et son équation : <span style="font-family:monospace">droite</span> et <span style="font-family:monospace">equation</span></h2><!--SEC END --><p><a id="hevea_default114"></a><a id="hevea_default115"></a>
<span style="font-family:monospace">droite</span> a comme argument 2 points.<br>
<span style="font-family:monospace">droite</span> trace la droite passant par ces 2 points sur l’écran de 
géométrie <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>2</mn><mi>d</mi></mrow><annotation encoding='application/x-tex'>2d</annotation></semantics></math>.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">A:=A;B:=B;d:=droite(A,B);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

<span style="font-family:monospace">equation</span> a comme argument une droite.<br>
<span style="font-family:monospace">equation</span> renvoie l’équation de cette droite<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">equation(d)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC section id="sec75" Ligne brisée : <span style="font-family:monospace">polygone_ouvert</span>-->
<h2 id="sec75" class="section">5.4  Ligne brisée : <span style="font-family:monospace">polygone_ouvert</span></h2><!--SEC END --><p><a id="hevea_default116"></a>
<span style="font-family:monospace">polygone_ouvert</span> a comme argument une liste <span style="font-family:monospace">L</span> de points.<br>
<span style="font-family:monospace">polygone_ouvert</span> trace la ligne brisée joignant les points 
<span style="font-family:monospace">L[k]</span> et <span style="font-family:monospace">L[k+1]</span> pour <span style="font-family:monospace">k=0..dim(L)-2</span>.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">A:=point(1,1);B:=point(2,3);C:=point(3,2);D:=point(2,0);polygone_ouvert(A,B,C,D)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC section id="sec76" Les polygones : <span style="font-family:monospace">triangle, carre, polygone</span>-->
<h2 id="sec76" class="section">5.5  Les polygones : <span style="font-family:monospace">triangle, carre, polygone</span></h2><!--SEC END --><p><a id="hevea_default117"></a><a id="hevea_default118"></a><a id="hevea_default119"></a>
<span style="font-family:monospace">triangle</span> a comme argument 3 points.<br>
<span style="font-family:monospace">triangle</span> trace le triangle défini par ces 3 points sur l’écran de 
géométrie <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>2</mn><mi>d</mi></mrow><annotation encoding='application/x-tex'>2d</annotation></semantics></math>.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">A:=A;B:=B;C:=C;triangle(A,B,C)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

<span style="font-family:monospace">carre</span> a comme argument 2 points.<br>
<span style="font-family:monospace">carre</span> trace le carré direct défini par ces 2 points sur l’écran de 
géométrie <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>2</mn><mi>d</mi></mrow><annotation encoding='application/x-tex'>2d</annotation></semantics></math>.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">A:=A;D:=D;carre(A,D)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">A:=A;D:=D;carre(D,A)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

<span style="font-family:monospace">polygone</span> a comme argument une liste de points.<br>
<span style="font-family:monospace">polygone</span> trace le polygone fermé défini par cette liste de points sur 
l’écran de géométrie <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>2</mn><mi>d</mi></mrow><annotation encoding='application/x-tex'>2d</annotation></semantics></math>.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">A:=A;B:=B;C:=C;D:=D;polygone(A,B,C,D)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

<span style="font-weight:bold">Exercice</span><br>
Faire un programme qui trace les polygones réguliers connaissant son centre 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math>, un de ses sommets <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> et le nombre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> de côtés.<br>

</p><pre class="verbatim">fonction Isopolygonec(C,A,n)
 local L,k;
 L:=NULL;
 L:=A;
 pour k de 0 jusque n-1 faire
   L:=L,C+(A-C)*exp(2*i*k*pi/n);
 fpour;
 retourne polygone(L);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


<span style="font-family:monospace">Xcas</span>, la fonction <span style="font-family:monospace">isopolygone</span> a 3 arguments : 2 sommets 
et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> le nombre de côtés ou bien le centre du polygone, un sommet 
et un nombre négatif <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mi>n</mi></mrow><annotation encoding='application/x-tex'>&#x2d;n</annotation></semantics></math> qui a comme valeur absolue le nombre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> de 
côtés.<br>
Avec <span style="font-family:monospace">Xcas</span>, on tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">isopolygone(point(1),point(i),-6)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
 
qui est identique à :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Isopolygonec(point(1),point(i),6)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec77" Le cercle et son équation : <span style="font-family:monospace">cercle</span> et <span style="font-family:monospace">equation</span>-->
<h2 id="sec77" class="section">5.6  Le cercle et son équation : <span style="font-family:monospace">cercle</span> et <span style="font-family:monospace">equation</span></h2><!--SEC END --><p><a id="hevea_default120"></a><a id="hevea_default121"></a>
Si le cercle est défini par son centre et son rayon alors
<span style="font-family:monospace">cercle</span> a pour argument un point et un réel <span style="font-family:monospace">r</span>.<br>
<span style="font-family:monospace">cercle</span> trace le cercle de centre ce point et de rayon <span style="font-family:monospace">abs(r)</span>
sur l’écran de géométrie <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>2</mn><mi>d</mi></mrow><annotation encoding='application/x-tex'>2d</annotation></semantics></math>.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">A:=point(1,1);C1:=cercle(A,-2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">equation(C1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>Si le cercle est défini par son diamètre alors
<span style="font-family:monospace">cercle</span> a pour argument 2 points.<br>
 <span style="font-family:monospace">cercle</span> trace le cercle de diamètre ces 2 points.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">A1:=point(1,1);A2:=point(2,3);C2:=cercle(A1,A2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">equation(C2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec78" Les tangentes à un cercle passant par un point et leurs équations-->
<h2 id="sec78" class="section">5.7  Les tangentes à un cercle passant par un point et leurs équations</h2><!--SEC END --><p>
Si <span style="font-family:monospace">C</span> est un cercle et <span style="font-family:monospace">B</span> un point situé à l’extérieur de
(resp sur) <span style="font-family:monospace">C</span> alors <span style="font-family:monospace">tangent(C,B)</span> trace les (resp la) tangente(s) à 
<span style="font-family:monospace">C</span> passant par <span style="font-family:monospace">B</span>.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">B:=point(3,1);C1:=cercle(point(1,1),1);T1:=tangent(C1,B);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">equation(T1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">B:=point(3,1);C2:=cercle(A1,A2);T2:=tangent(C2,B);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">equation(T2);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec79" Exercice : les lunules d’Hippocrate-->
<h2 id="sec79" class="section">5.8  Exercice : les lunules d’Hippocrate</h2><!--SEC END --><p>
Ce théorème, très ancien, a été démontré par Hippocrate de Chios 
(-500) (Ne pas le confondre avec Hippocrate de Cos, le médecin), qui étudia 
aussi la duplication du cube, c’est-à-dire le calcul de la racine cubique de 2.<br>
Hippocrate recherchait alors la quadrature du cercle et pensait que la 
quadrature de ses lunules allait le rapprocher du but.<br>
Une lunule est une portion de surface délimitée par deux arcs de cercles 
non concentriques de rayons différents. Ces arcs ont mêmes extrémités et
forment un croissant de lune en forme de ménisque : convexe d’un côté et 
concave de l’autre.<br>
</p>
<!--TOC subsection id="sec80" Exercice 1-->
<h3 id="sec80" class="subsection">5.8.1  Exercice 1</h3><!--SEC END --><p>
Soit le triangle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math> rectangle en <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Cscr;</mi></mrow><annotation encoding='application/x-tex'>\mathcal{C}</annotation></semantics></math> le cercle circonscrit 
à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math> (de diamètre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>BC</annotation></semantics></math>).<br>
La lunule <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>L</mi> <mrow><mi>A</mi><mi>C</mi></mrow></msub></mrow><annotation encoding='application/x-tex'>L_{AC}</annotation></semantics></math> est la figure formée par le demi-disque de diamètre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>AC</annotation></semantics></math> 
extérieur au triangle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math>, auquel on enlève son intersection avec le disque 
délimité par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Cscr;</mi></mrow><annotation encoding='application/x-tex'>\mathcal{C}</annotation></semantics></math>.<br>
La lunule <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>L</mi> <mrow><mi>A</mi><mi>B</mi></mrow></msub></mrow><annotation encoding='application/x-tex'>L_{AB}</annotation></semantics></math> est la figure formée par le demi-disque de diamètre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>AB</annotation></semantics></math> 
extérieur au triangle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math>, auquel on enlève son intersection avec le 
disque délimité par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&Cscr;</mi></mrow><annotation encoding='application/x-tex'>\mathcal{C}</annotation></semantics></math>.<br>
Ces deux lunules (en jaune sur la figure ci-dessous) sont appelées 
<span style="font-weight:bold">lunules d’Hippocrate</span>.<br>
Montrer que la somme des aires de ces deux lunules <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>L</mi> <mrow><mi>B</mi><mi>C</mi></mrow></msub></mrow><annotation encoding='application/x-tex'>L_{BC}</annotation></semantics></math> et de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>L</mi> <mrow><mi>B</mi><mi>A</mi></mrow></msub></mrow><annotation encoding='application/x-tex'>L_{BA}</annotation></semantics></math> (en 
jaune) est égale à l’aire du triangle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math> (en rouge).<br>
On tape pour faire la figure :

</p><pre class="verbatim">fonction Lunule1()
local A,B,C,L;
L:=NULL;
A:=point(0);
B:=point(2,affichage=quadrant1);
C:=point(3*i,affichage=quadrant1);
L:=L,cercle((A+C)/2,3/2,pi/2,3*pi/2,affichage=3+rempli);
L:=L,cercle(A,B,-pi,0,affichage=3+rempli);
L:=L,cercle(B,C,0,pi,affichage=4+rempli);
L:=L,triangle(A,B,C,affichage=1+rempli);
retourne L;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">Lunule1();A:=point(0);B:=point(2,affichage=quadrant1);C:=point(3*i,affichage=quadrant1);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-weight:bold">Solution</span><br>
On calcule <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mn>1</mn></mrow><annotation encoding='application/x-tex'>S1</annotation></semantics></math> l’aire du triangle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math> :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mn>1</mn><mo>=</mo><mi>A</mi><mi>B</mi><mo>*</mo><mi>A</mi><mi>C</mi><mo stretchy="false">/</mo><mn>2</mn></mrow><annotation encoding='application/x-tex'>S1=AB*AC/2</annotation></semantics></math>
On calcule <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mn>2</mn></mrow><annotation encoding='application/x-tex'>S2</annotation></semantics></math> la somme des aires de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>L</mi> <mrow><mi>B</mi><mi>C</mi></mrow></msub></mrow><annotation encoding='application/x-tex'>L_{BC}</annotation></semantics></math> et de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>L</mi> <mrow><mi>B</mi><mi>A</mi></mrow></msub></mrow><annotation encoding='application/x-tex'>L_{BA}</annotation></semantics></math> :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mn>2</mn></mrow><annotation encoding='application/x-tex'>S2</annotation></semantics></math> est obtenue par différence : <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mn>2</mn></mrow><annotation encoding='application/x-tex'>S2</annotation></semantics></math> est égale à la somme des aires des
demi-cercles de diamètres <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>AB</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>AC</annotation></semantics></math> à laquelle on enlève l’aire en 
bleu.<br>
L’aire en bleu est égale à l’aire du demi-cercle de 
diamètre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>BC</annotation></semantics></math> à laquelle on enlève l’aire <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mn>1</mn></mrow><annotation encoding='application/x-tex'>S1</annotation></semantics></math> du triangle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math> :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mn>2</mn><mo>=</mo><mi>&pi;</mi><mo>*</mo><mi>A</mi><msup><mi>B</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><mn>2</mn><mo>+</mo><mi>&pi;</mi><mo>*</mo><mi>A</mi><msup><mi>C</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><mn>2</mn><mo>&minus;</mo><mo stretchy="false">(</mo><mi>&pi;</mi><mo>*</mo><mi>B</mi><msup><mi>C</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><mn>2</mn><mo>&minus;</mo><mi>S</mi><mn>1</mn><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>S2=\pi*AB^2/2+\pi*AC^2/2&#x2d;(\pi*BC^2/2&#x2d;S1)</annotation></semantics></math><br>
D’après le théorème de Pythagore on a : <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><msup><mi>B</mi> <mn>2</mn></msup><mo>+</mo><mi>A</mi><msup><mi>C</mi> <mn>2</mn></msup><mo>=</mo><mi>B</mi><msup><mi>C</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>AB^2+AC^2=BC^2</annotation></semantics></math> donc :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>S</mi><mn>2</mn><mo>=</mo><mi>S</mi><mn>1</mn></mrow><annotation encoding='application/x-tex'>S2=S1</annotation></semantics></math>.
</p>
<!--TOC subsection id="sec81" Exercice 2-->
<h3 id="sec81" class="subsection">5.8.2  Exercice 2</h3><!--SEC END --><p>
Soient un carré de côtés <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>l</mi></mrow><annotation encoding='application/x-tex'>l</annotation></semantics></math> et les cercles ayant comme 
diamètre les côtés du carré.<br>
À l’extérieur du carré, ces cercles déterminent avec le cercle 
circonscrit au carré 4 lunules.<br>
Trouver l’aire des 4 lunules ainsi déterminées.<br>
À l’intérieur du carré, ces cercles en se coupant déterminent 4 
"pétales".<br>
 Trouver l’aire des 4 "pétales" ainsi déterminées.<br>
On tape pour faire la figure :

</p><pre class="verbatim">fonction Lunule2()
local A,B,C,L;
L:=NULL;
L:=L,cercle(point(2),2,-pi/2,pi/2,affichage=1+rempli);
L:=L,cercle(point(2*i),2,0,pi,affichage=2+rempli);
L:=L,cercle(point(-2),2,pi/2,3*pi/2,affichage=3+rempli);
L:=L,cercle(point(0,-2),2,pi,2*pi,affichage=4+rempli);
L:=L,cercle(0,2*sqrt(2),affichage=5+rempli);
L:=L,cercle(point(0,-2),2);
L:=L,cercle(point(0,2),2);
L:=L,cercle(point(2,0),2);
L:=L,cercle(point(-2,0),2);
L:=L,carre(-2-2*i,2-2*i);
retourne L;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">Lunule2();
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

<span style="font-weight:bold">Solution</span>
Un carré est formé de 2 triangles rectangles donc l’aire des 4 lunules est 
égale à l’aire du carré (cl le résultat précédent).<br>
La somme de l’aire du carré et de l’aire des "pétales" est égale à 
l’aire des 4 demi-cercles de rayon <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>l</mi><mo stretchy="false">/</mo><mn>2</mn></mrow><annotation encoding='application/x-tex'>l/2</annotation></semantics></math> (car les 4 demi-cercles qui sont à 
l’intérieur du carré remplissent le carré et se superposent selon les 
"pétales") donc l’aire des "pétales"=<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&pi;</mi><mo>*</mo><msup><mi>l</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><mn>2</mn><mo>&minus;</mo><msup><mi>l</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>\pi*l^2/2&#x2d;l^2</annotation></semantics></math>.</p>
<!--TOC subsection id="sec82" Exercice 3-->
<h3 id="sec82" class="subsection">5.8.3  Exercice 3</h3><!--SEC END --><p>
Si la tentative de la quadrature du cercle est un échec, Hippocrate a trouvé
la quadrature de plusieurs lunules en partant de la remarque suivante :<br>
deux secteurs circulaires <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>OAB</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>O</mi> <mn>1</mn></msub><msub><mi>A</mi> <mn>1</mn></msub><msub><mi>B</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>O_1A_1B_1</annotation></semantics></math> de rayon <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi></mrow><annotation encoding='application/x-tex'>r</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>r</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>r_1</annotation></semantics></math> semblables 
i.e. dont les angles au centre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> ont la même valeur ont des aires 
proportionnelles aux carrés des longueurs de leurs cordes.<br>
On tape pour faire la figure :

</p><pre class="verbatim">fonction Secteurcirc(O,r,t,a)
local A,B,L,xO,yO;
L:=NULL;
[xO,yO]:=coordonnees(O);
A:=point(xO+r*cos(t),yO+r*sin(t));
B:=point(xO+r*cos(t+a),yO+r*sin(t+a));
L:=L,cercle(O,r,t,t+a,affichage=4+rempli);
L:=L,triangle(O,A,B,affichage=1+rempli);
retourne L;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


Voici 2 secteurs circulaires identiques :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">Secteurcirc(-1,1,pi/6,2*pi/5),Secteurcirc(0,1,0,2*pi/5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Voici 2 secteurs circulaires semblables :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">Secteurcirc(-1,1,pi/6,2*pi/5),Secteurcirc(0,2,0,2*pi/5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Chaque secteur circulaire est composé ici d’un triangle (en rouge) et d’une 
calotte circulaire (en bleu). Les aires des triangles ainsi que les aires des 
calottes circulaires,sont aussi proportionnelles aux carrés des longueurs des 
cordes.<br>
Montrer ces résultats.<br>
<span style="font-weight:bold">Solution</span><br>
Si deux secteurs circulaires <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>OAB</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>O</mi> <mn>1</mn></msub><msub><mi>A</mi> <mn>1</mn></msub><msub><mi>B</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>O_1A_1B_1</annotation></semantics></math> de rayon <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi></mrow><annotation encoding='application/x-tex'>r</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>r</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>r_1</annotation></semantics></math> ont pour
angle au centre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> on a :<br>
La longueur <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>AB</annotation></semantics></math> vaut <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>2</mn><mi>R</mi><mi>sin</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">/</mo><mn>2</mn></mrow><annotation encoding='application/x-tex'>2R\sin(a/2</annotation></semantics></math> donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi><mo>=</mo><mi>A</mi><mi>B</mi><mo stretchy="false">/</mo><mo stretchy="false">(</mo><mn>2</mn><mi>sin</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">/</mo><mn>2</mn><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>r=AB/(2\sin(a/2)</annotation></semantics></math><br>
L’aire du secteur circulaire vaut <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><msup><mi>R</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><mn>2</mn><mo>=</mo><mi>A</mi><msup><mi>B</mi> <mn>2</mn></msup><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">/</mo><mo stretchy="false">(</mo><mn>8</mn><mi>sin</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">/</mo><mn>2</mn><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>aR^2/2=AB^2(a/(8\sin(a/2)^2)</annotation></semantics></math><br>
L’aire du secteur circulaire est donc proportionnelle à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><msup><mi>B</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>AB^2</annotation></semantics></math>.<br>
L’aire du triangle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>OAB</annotation></semantics></math> vaut <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>R</mi> <mn>2</mn></msup><mi>cos</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">/</mo><mn>2</mn><mo stretchy="false">)</mo><mi>sin</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">/</mo><mn>2</mn><mo stretchy="false">)</mo><mo>=</mo><mi>A</mi><msup><mi>B</mi> <mn>2</mn></msup><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">/</mo><mo stretchy="false">(</mo><mn>4</mn><mi>tan</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">/</mo><mn>2</mn><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>R^2\cos(a/2)\sin(a/2)=AB^2(1/(4\tan(a/2))</annotation></semantics></math><br>
L’aire du triangle est donc proportionnelle à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><msup><mi>B</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>AB^2</annotation></semantics></math>.<br>
L’aire de la calotte circulaire vaut <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><msup><mi>B</mi> <mn>2</mn></msup><mo stretchy="false">(</mo><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">/</mo><mo stretchy="false">(</mo><mn>8</mn><mi>sin</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">/</mo><mn>2</mn><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo stretchy="false">)</mo><mo>&minus;</mo><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">/</mo><mo stretchy="false">(</mo><mn>4</mn><mi>tan</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">/</mo><mn>2</mn><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>AB^2((a/(8\sin(a/2)^2)&#x2d;(1/(4\tan(a/2))</annotation></semantics></math>.<br>
L’aire du calotte circulaire est donc proportionnelle à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><msup><mi>B</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>AB^2</annotation></semantics></math>.<br>
<span style="font-weight:bold">Application</span><br>
Soit un triangle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math> isocèle et rectangle en <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math>.<br>
Soit <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>D</mi></mrow><annotation encoding='application/x-tex'>D</annotation></semantics></math> le symétrique de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> par rapport à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>AB</annotation></semantics></math>.<br>
Le demi-cercle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math> de diamètre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>AB</annotation></semantics></math> et le quart de cercle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>M</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>AMB</annotation></semantics></math> de centre
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>D</mi></mrow><annotation encoding='application/x-tex'>D</annotation></semantics></math> définissent la lunule <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>M</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>AMBC</annotation></semantics></math> en rouge sur la figure.<br>
On tape pour faire la figure :

</p><pre class="verbatim">fonction Lunule3()
local A,B,C,D,L,xO,yO;
L:=NULL;
A:=point(-2);
B:=point(2,affichage=quadrant1);
C:=point([0,2],affichage=quadrant1);
D:=point(0,-2);
L:=L,affichage(cercle(0,2,0,pi),1+rempli);
L:=L,triangle(A,B,C,affichage=4+rempli);
L:=L,affichage(cercle(D,2*sqrt(2),pi/4,3*pi/4),6+rempli);
L:=L,triangle(A,B,D,affichage=3+rempli);
retourne L;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">Lunule3();A:=point(-2);B:=point(2,affichage=quadrant1);C:=point(0,2,affichage=quadrant1);M:=point(0,-2+2*sqrt(2))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

<span style="font-weight:bold">Solution</span>
L’aire des 2 calottes circulaires rouges est égale à l’aire de la calotte
circulaire cyan puisque <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><msup><mi>B</mi> <mn>2</mn></msup><mo>=</mo><mi>A</mi><msup><mi>C</mi> <mn>2</mn></msup><mo>+</mo><mi>B</mi><msup><mi>C</mi> <mn>2</mn></msup><mo>=</mo><mn>2</mn><mi>A</mi><msup><mi>C</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>AB^2=AC^2+BC^2=2AC^2</annotation></semantics></math> (car le triangle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math> est 
rectangle isocèle de sommet <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math>.<br>
L’aire du triangle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math> (aire bleue+aire de la calotte circulaire cyan) est 
donc égale à l’aire de la lunule <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>M</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>AMBC</annotation></semantics></math> (aires des calottes circulaires 
rouges +aire bleue)
</p>
<!--TOC subsection id="sec83" Exercice 4-->
<h3 id="sec83" class="subsection">5.8.4  Exercice 4</h3><!--SEC END --><p>
Soit un trapèze isocèle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'>ABCD</annotation></semantics></math> vérifiant <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi><mi>C</mi><mo>=</mo><mi>C</mi><mi>D</mi><mo>=</mo><mi>A</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'>BC=CD=AD</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><msup><mi>B</mi> <mn>2</mn></msup><mo>=</mo><mn>3</mn><mi>D</mi><msup><mi>C</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>AB^2=3DC^2</annotation></semantics></math>.<br>
Soit l’arc de cercle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi><mi>C</mi><mi>M</mi><mi>D</mi><mi>A</mi></mrow><annotation encoding='application/x-tex'>BCMDA</annotation></semantics></math> de centre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi></mrow><annotation encoding='application/x-tex'>I</annotation></semantics></math> intersection des médiatrices de
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>AC</annotation></semantics></math> et de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>D</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>DC</annotation></semantics></math> (où <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'>M</annotation></semantics></math> est un point de l’arc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'>CD</annotation></semantics></math>).<br>
Soit l’arc de cercle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi><mi>N</mi><mi>A</mi></mrow><annotation encoding='application/x-tex'>BNA</annotation></semantics></math> tangent à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>AC</annotation></semantics></math> de centre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>J</mi></mrow><annotation encoding='application/x-tex'>J</annotation></semantics></math> intersection de la
médiatrice de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>D</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>DC</annotation></semantics></math> et de la perpendiculaire en <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>AC</annotation></semantics></math>.<br>
On tape pour faire la figure :

</p><pre class="verbatim">fonction Lunule4()
local A,B,C,D,I,J,L;
L:=NULL;
A:=point(-sqrt(3.));
B:=point(sqrt(3.));
C:=point(1,sqrt(2*sqrt(3.)));
D:=point(-1,sqrt(2*sqrt(3.)));
//I:=inter_unique(droite(x=0),mediatrice(A,D));
I:=point(0,sqrt(-3+2*sqrt(3.))*sqrt(3.))/3);
//J:=inter_unique(droite(x=0),perpendiculaire(A,droite(A,C)));
J:=point(0,-sqrt(3+2*sqrt(3.)));
L:=L,affichage(cercle(I,evalf(longueur(A,I)),angle(I,I+2,B),2*pi+angle(I,I+2,A)),1+rempli);
L:=L,triangle(A,B,C,affichage=2+rempli);
L:=L,triangle(A,C,D,affichage=2+rempli);
L:=L,affichage(cercle(J,sqrt(6+2*sqrt(3.)),angle(J,J+2,B),angle(J,J+2,A)),4+rempli);
L:=L,affichage(triangle(J,A,B),3+rempli);
L:=L,segment(D,I),segment(C,I),segment(A,C),segment(A,J),segment(J,B),segment(I,J);
retourne L;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>

</p><p>
<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">Lunule4();A:=point(-sqrt(3.),affichage=quadrant2);B:=point(sqrt(3.),affichage=quadrant1);C:=point(1,sqrt(2*sqrt(3.)),affichage=quadrant1);D:=point(-1,sqrt(2*sqrt(3.)),affichage=quadrant2);I:=point(0,sqrt(-3+2*sqrt(3.))/sqrt(3.));J:=point(0,-sqrt(3+2*sqrt(3.)))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-weight:bold">Solution</span>
L’aire de la lunule (rouge + vert) <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'>ABCD</annotation></semantics></math> est égale à l’aire du trapèze 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'>ABCD</annotation></semantics></math> (vert+bleu).<br>
En effet, l’aire de la calotte bleue est égale à 3 fois l’aire d’une calotte
rouge car les secteurs circulaires <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>J</mi><mi>B</mi><mi>A</mi></mrow><annotation encoding='application/x-tex'>JBA</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'>ICD</annotation></semantics></math> sont homothétiques et que 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><msup><mi>B</mi> <mn>2</mn></msup><mo>=</mo><mn>3</mn><mi>D</mi><msup><mi>C</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>AB^2=3DC^2</annotation></semantics></math>.<br>
On a donc puisque <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>D</mi><mo>=</mo><mi>D</mi><mi>C</mi><mo>=</mo><mi>C</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>AD=DC=CB</annotation></semantics></math>, l’aire des calottes rouges sont égales.<br>
Donc l’aire des 3 calottes rouges est égale à l’aire bleue et :<br>
aire lunule(<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'>ABCD</annotation></semantics></math>)=aire trapeze(<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'>ABCD</annotation></semantics></math>)-aire calotte bleue+3*aire lunule(<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'>CD</annotation></semantics></math>)<br>
Donc <br>
aire lunule(<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'>ABCD</annotation></semantics></math>)=aire trapeze(<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'>ABCD</annotation></semantics></math>).</p>
<!--TOC chapter id="sec84" La géométrie analytique-->
<h1 id="sec84" class="chapter">Chapitre 6  La géométrie analytique</h1><!--SEC END --><p>
Dans ce chapitre, les programmes que l’on va faire ne feront pas de tracés 
mais renverront des valeurs (coordonnées, coefficients, équations).<br>
On pourra alors faire les figures avec <span style="font-family:monospace">Xcas</span> et vérifier les résultats
obtenus par ces programmes.
</p>
<!--TOC section id="sec85" Les segments-->
<h2 id="sec85" class="section">6.1  Les segments</h2><!--SEC END -->
<!--TOC subsection id="sec86" Calculer la distance de deux points connaissant leurs coordonnées-->
<h3 id="sec86" class="subsection">6.1.1  Calculer la distance de deux points connaissant leurs coordonnées</h3><!--SEC END --><p>
<a id="sec:Longueur"></a>
Si les points <span style="font-family:monospace">A</span> et <span style="font-family:monospace">B</span> ont pour coordonnées <span style="font-family:monospace">cA:=[xA,yA]</span> et
<span style="font-family:monospace">cB:=[xB,yB]</span> le segment <span style="font-family:monospace">AB</span> a pour longueur :<br>
<span style="font-family:monospace">sqrt((xA-xB)</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+(yA-yB)</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2)</span><br>
On tape :

</p><pre class="verbatim">fonction Longueur(cA,cB)
 local xA,xB,yA,yB;
 xA:=cA[0];
 yA:=cA[1];
 xB:=cB[0];
 yB:=cB[1];
 retourne simplify(sqrt((xA-xB)^2+(yA-yB)^2));
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[1,2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cB:=[-1,-3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Longueur(cA,cB)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Vérifions avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">longueur(cA,cB)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC subsection id="sec87" Calculer les coordonnées du milieu d’un segment-->
<h3 id="sec87" class="subsection">6.1.2  Calculer les coordonnées du milieu d’un segment</h3><!--SEC END --><p><a id="sec:Milieu"></a>
Si les points <span style="font-family:monospace">A</span> et <span style="font-family:monospace">B</span> ont pour coordonnées <span style="font-family:monospace">cA:=[xA,yA]</span> et 
<span style="font-family:monospace">cB:=[xB,yB]</span>, le milieu de <span style="font-family:monospace">AB</span> a pour coordonnées 
<span style="font-family:monospace">[(xA+xB)/2,(yA+yB)/2]</span> :<br>
On tape :

</p><pre class="verbatim">fonction Milieu(cA,cB)
 local xA,xB,yA,yB;
 xA:=cA[0];
 yA:=cA[1];
 xB:=cB[0];
 yB:=cB[1];
 retourne [(xA+xB)/2,(yA+yB)/2];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[1,2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cB:=[-1,-3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Milieu(cA,cB)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Vérifions avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">coordonnees(milieu(cA,cB))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC section id="sec88" Les droites-->
<h2 id="sec88" class="section">6.2  Les droites</h2><!--SEC END -->
<!--TOC subsection id="sec89" Équation d’une droite définie par 2 points ou par sa pente et un point-->
<h3 id="sec89" class="subsection">6.2.1  Équation d’une droite définie par 2 points ou par sa pente et un point</h3><!--SEC END --><p><a id="sec:Droite"></a>
<span style="font-weight:bold">Équation d’une droite définie par 2 points</span><br>
Si les points <span style="font-family:monospace">A</span> et <span style="font-family:monospace">B</span> ont pour coordonnées <span style="font-family:monospace">cA:=[xA,yA]</span> et 
<span style="font-family:monospace">cB:=[xB,yB]</span>, la droite <span style="font-family:monospace">d</span> passant par <span style="font-family:monospace">A</span> et <span style="font-family:monospace">B</span> a pour 
équation :<br>
<span style="font-family:monospace">(xA-xB)*y-(yA-yB)*x-yB*xA+yA*xB=0</span> ou encore<br>
si <span style="font-family:monospace">(xA==xB)</span> alors l’équation de <span style="font-family:monospace">d</span> est <span style="font-family:monospace">x=xA</span> <br>
si <span style="font-family:monospace">(xA!=xB)</span> alors l’équation de <span style="font-family:monospace">d</span> est 
<span style="font-family:monospace">y=(yA-yB)*(x-xB)/(xA-xB)+yB</span> <br>

<span style="font-weight:bold">Équation d’une droite définie par sa pente et un point</span><br>
La droite passant par le point <span style="font-family:monospace">A</span> de coordonnées 
<span style="font-family:monospace">cA:=[xA,yA]</span> et de pente <span style="font-family:monospace">m</span> a pour équation :<br>
<span style="font-family:monospace">y=m*(x-xA)+yA</span>.<br>
On tape :

</p><pre class="verbatim">fonction Droite1(cA,cB)
 local xA,xB,yA,yB;
 xA:=cA[0];
 yA:=cA[1];
 xB:=cB[0];
 yB:=cB[1];
 retourne normal((xA-xB)*y-(yA-yB)*x-yB*xA+yA*xB)=0;
ffonction:;

fonction Droite2(cA,m)
 local xA,yA;
 xA:=cA[0];
 yA:=cA[1];
 retourne y-m*(x-xA)-yA=0;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


On peut réunir les 2 programmes en un seul en testant la dimension du 
deuxième paramètre de <span style="font-family:monospace">Droite</span> qui est soit une liste de dimension 2,
soit un réél.<br>
On peut aussi faire en sorte que <span style="font-family:monospace">Droite</span> accepte 1 seul argument qui soit 
son équation : pour cela, on donne au deuxième argument une valeur par 
défaut (ici cette valeur sera arbitraire par exemple 0) (cf <a href="#sec%3Avaldef">2.2.4</a>).<br>
On tape :

</p><pre class="verbatim">fonction Droite(cA,L=0)
 local xA,xB,yA,yB,m;
 si type(cA)==expression alors retourne cA;fsi;
 xA:=cA[0];
 yA:=cA[1];
 si type(L)==vecteur alors 
   xB:=L[0];
   yB:=L[1];
   retourne normal((xA-xB)*y-(yA-yB)*x-yB*xA+yA*xB)=0;
 sinon
   m:=L;
   retourne y-m*(x-xA)-yA=0;
 fsi;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


Observez qu’on a donné une valeur par défaut 0 
au deuxième paramètre <code>L</code>, si <code>Droite</code> est appelée
avec deux arguments tout se passe comme si on avait écrit
<code>L</code> et non <code>L=0</code>, par contre si <code>Droite</code> est
appelée avec un seul argument, alors <code>L</code> prend la valeur
0 au début de la fonction.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">purge(x,y)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[1,2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cB:=[-1,-3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">m:=2
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Droite(cA,cB)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Droite(cA,m)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Droite(x+y=1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Vérifions avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">equation(droite(point(cA),point(cB)))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">equation(droite(point(cA),pente=m))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC subsection id="sec90" Coefficients (a,b,c) de la droite d’équation ax+by+c=0-->
<h3 id="sec90" class="subsection">6.2.2  Coefficients (a,b,c) de la droite d’équation ax+by+c=0</h3><!--SEC END --><p><a id="hevea_default122"></a><a id="hevea_default123"></a><a id="hevea_default124"></a><a id="sec:Coeffsdroite"></a>
Étant donnée l’équation d’une droite <span style="font-family:monospace">a*x+b*y+c=0</span>, on va écrire une
fonction qui renvoie les coefficients <span style="font-family:monospace">a</span>, <span style="font-family:monospace">b</span> et <span style="font-family:monospace">c</span>.<br>
On utilise tout d’abord <span style="font-family:monospace">gauche</span> et <span style="font-family:monospace">droit</span> qui renvoie le côté 
gauche et le côté droit d’une équation.<br>
Par exemple si <span style="font-family:monospace">Eq:=eq1=eq2</span> alors
<span style="font-family:monospace">gauche(Eq)</span> renvoie <span style="font-family:monospace">eq1</span> et
<span style="font-family:monospace">droit(Eq)</span> renvoie <span style="font-family:monospace">eq2</span> donc <br>
<span style="font-family:monospace">gauche(Eq)-droit(Eq)</span> renvoie <span style="font-family:monospace">eq</span> 
qui est égal à <span style="font-family:monospace">eq1-eq2</span>.<br>
On peut alors trouver <span style="font-family:monospace">a</span>, <span style="font-family:monospace">b</span> et <span style="font-family:monospace">c</span> en donnant des valeurs à
<span style="font-family:monospace">x</span> et <span style="font-family:monospace">y</span>.<br>
Posons :<br>
<span style="font-family:monospace">c:=subst(eq,[x,y],[0,0])</span><br>
<span style="font-family:monospace">d1:=subst(eq,[x,y],[1,0])</span><br>
<span style="font-family:monospace">d2:=subst(eq,[x,y],[0,1])</span><br>
Alors on a <span style="font-family:monospace">a:=d1-c</span> et <span style="font-family:monospace">b:=d2-c</span><br>
On tape :

</p><pre class="verbatim">fonction Coeffsdroite(Eq)
 local a,b,c,d1,d2,eq;
 eq:=gauche(Eq)-droit(Eq);
 c:=subst(eq,[x,y],[0,0]);
 d1:=subst(eq,[x,y],[1,0]);
 d2:=subst(eq,[x,y],[0,1]);
 retourne normal(d1-c,d2-c,c);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Coeffsdroite(y-3*(x-1)-1=0)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Coeffsdroite((1+sqrt(2))^2*x-y+3=0)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Remarque</span><br>
On peut aussi utiliser :<br>
<span style="font-family:monospace">coeff(P(x,y),x)</span> (resp <span style="font-family:monospace">coeff(P(x,y),y)</span>) qui renvoie la liste 
des coefficients selon les puissances décroissantes du polynôme <span style="font-family:monospace">P</span> par 
rapport à la variable <span style="font-family:monospace">x</span> (resp <span style="font-family:monospace">y</span>) et<br>
<span style="font-family:monospace">coeff(P(x,y),x,n)</span> (resp <span style="font-family:monospace">coeff(P(x,y),y,n)</span>) qui renvoie le 
coefficient de <span style="font-family:monospace">x</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">n</span> (resp de <span style="font-family:monospace">y</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">n</span>) du
polynôme <span style="font-family:monospace">P</span>.<br>
On tape :

</p><pre class="verbatim">fonction Coeffdroite(Eq)
 local a,b,c;
 Eq:=gauche(Eq)-droit(Eq);
 a:=coeff(Eq,x,1);
 b:=coeff(Eq,y,1);
 c:=subst(Eq,[x,y]=[0,0]);
 retourne normal(a,b,c);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Coeffdroite(y-3*(x-1)-1=0)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Coeffdroite(Droite(y-3*(x-1)-1=0))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Vérifions avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">Eq:=y-3*(x-1)-1;[coeff(Eq,x,1),coeff(Eq,y,1),subst(Eq,[x,y]=[0,0])]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec91" Point d’intersection de 2 droites sécantes-->
<h3 id="sec91" class="subsection">6.2.3  Point d’intersection de 2 droites sécantes</h3><!--SEC END --><p>
Cette section reprend la section sur la résolution de système
de 2 équations à 2 inconnues.
Soient deux droites <span style="font-family:monospace">d1</span> et <span style="font-family:monospace">d2</span> d’équation :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>1</mn></msub><mi>x</mi><mo>+</mo><msub><mi>b</mi> <mn>1</mn></msub><mi>y</mi><mo>+</mo><msub><mi>c</mi> <mn>1</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>a_1x+b_1y+c_1=0</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>2</mn></msub><mi>x</mi><mo>+</mo><msub><mi>b</mi> <mn>2</mn></msub><mi>y</mi><mo>+</mo><msub><mi>c</mi> <mn>2</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>a_2x+b_2y+c_2=0</annotation></semantics></math><br>
Ces 2 droites sont parallèles si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>1</mn></msub><msub><mi>b</mi> <mn>2</mn></msub><mo>=</mo><msub><mi>a</mi> <mn>2</mn></msub><msub><mi>b</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>a_1b_2=a_2b_1</annotation></semantics></math>.<br>
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>1</mn></msub><msub><mi>b</mi> <mn>2</mn></msub><mo>&ne;</mo><msub><mi>a</mi> <mn>2</mn></msub><msub><mi>b</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>a_1b_2\neq a_2b_1</annotation></semantics></math> <span style="font-family:monospace">d1</span> et <span style="font-family:monospace">d2</span> sont sécantes.<br>
Les coordonnées de leur point d’intersection sont <br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>c</mi> <mn>2</mn></msub><mo>*</mo><msub><mi>b</mi> <mn>1</mn></msub><mo>+</mo><msub><mi>b</mi> <mn>2</mn></msub><mo>*</mo><msub><mi>c</mi> <mn>1</mn></msub><mo stretchy="false">)</mo><mo stretchy="false">/</mo><mo stretchy="false">(</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>b</mi> <mn>2</mn></msub><mo>*</mo><msub><mi>a</mi> <mn>1</mn></msub><mo>+</mo><msub><mi>a</mi> <mn>2</mn></msub><mo>*</mo><msub><mi>b</mi> <mn>1</mn></msub><mo stretchy="false">)</mo><mo>,</mo><mo stretchy="false">(</mo><msub><mi>c</mi> <mn>2</mn></msub><mo>*</mo><msub><mi>a</mi> <mn>1</mn></msub><mo>&minus;</mo><msub><mi>a</mi> <mn>2</mn></msub><mo>*</mo><msub><mi>c</mi> <mn>1</mn></msub><mo stretchy="false">)</mo><mo stretchy="false">/</mo><mo stretchy="false">(</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>b</mi> <mn>2</mn></msub><mo>*</mo><msub><mi>a</mi> <mn>1</mn></msub><mo>+</mo><msub><mi>a</mi> <mn>2</mn></msub><mo>*</mo><msub><mi>b</mi> <mn>1</mn></msub><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>(&#x2d;c_2*b_1+b_2*c_1)/(&#x2d;b_2*a_1+a_2*b_1),(c_2*a_1&#x2d;a_2*c_1)/(&#x2d;b_2*a_1+a_2*b_1)</annotation></semantics></math>
<span style="font-family:monospace">Interdroite(d1,d2)</span> renvoie <span style="font-family:monospace">[]</span> si <span style="font-family:monospace">d1</span> et <span style="font-family:monospace">d2</span> sont 
paralléles et sinon renvoie les coordonées de leur point d’intersection.<br>
On utilise les programmes <span style="font-family:monospace">Droite</span> et <span style="font-family:monospace">Coeffsdroite</span> précédents 
(cf <a href="#sec%3ACoeffsdroite">6.2.2</a> pour avoir les coefficients
des équations <span style="font-family:monospace">Eq1</span> et <span style="font-family:monospace">Eq2</span> de <span style="font-family:monospace">d1</span> et de <span style="font-family:monospace">d2</span>
On tape :

</p><pre class="verbatim">fonction Interdroite(d1,d2)
 local a1,a2,b1,b2,c1,c2,gd1,gd2,d;
 (a1,b1,c1):=Coeffsdroite(d1);
 (a2,b2,c2):=Coeffsdroite(d2);
 d:=normal(a2*b1-b2*a1);
 si d==0 alors retourne [];fsi;
 retourne [(b2*c1-b1*c2)/d,(c2*a1-a2*c1)/d];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">d1:=Droite(2x+3y-1=0)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">d2:=Droite(-x+y+1=0)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">d3:=Droite([1,1],[2,3])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">d4:=Droite([1,0],[0,1])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">d5:=Droite([1,2],2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Interdroite(d1,d2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Interdroite(d3,d4)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Interdroite(d5,d3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On fait la figure avec <span style="font-family:monospace">Xcas</span>:<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">droite(d1),droite(d2),droite(d3),droite(d4),droite(d5)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Vérifions avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">coordonnees(inter_unique(droite(d1),droite(d2)))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">coordonnees(inter_unique(droite(d3),droite(d4)))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC section id="sec92" Triangles et quadrilatères définis par les coordonnées des sommets-->
<h2 id="sec92" class="section">6.3  Triangles et quadrilatères définis par les coordonnées des sommets</h2><!--SEC END --><p>
On définit des versions de la commande <code>polygone</code> de <span style="font-family:monospace">Xcas</span> donc ces 2 programmes vont faire des figures.

</p><pre class="verbatim">fonction Triangle(cA,cB,cC)
 retourne polygone(cA,cB,cC);
ffonction:;
fonction Quadrilatere(cA,cB,cC,cD)
 retourne polygone(cA,cB,cC,cD);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[1,-1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cB:=[1/2,2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cC:=[0,3/2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cD:=[-1/2,0]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Triangle(cA,cB,cC)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Quadrilatere(cA,cB,cC,cD)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC section id="sec93" Les vecteurs-->
<h2 id="sec93" class="section">6.4  Les vecteurs</h2><!--SEC END -->
<!--TOC subsection id="sec94" Les coordonnées d’un vecteur défini par 2 points-->
<h3 id="sec94" class="subsection">6.4.1  Les coordonnées d’un vecteur défini par 2 points</h3><!--SEC END --><p>
Si les coordonnées du point A (resp B) sont <span style="font-family:monospace">cA:=[xA,yA]</span> 
(resp <span style="font-family:monospace">cB:=[xB,yB]</span>), les coordonnées du vecteur <span style="font-family:monospace">AB</span> 
sont <span style="font-family:monospace">[xB-xA,yB-yA]</span>.<br>
On tape :

</p><pre class="verbatim">fonction Vecteur(cA,cB)
 local xA,xB,yA,yB;
 xA:=cA[0];
 yA:=cA[1];
 xB:=cB[0];
 yB:=cB[1];
 retourne normal([xB-xA,yB-yA]);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


ou plus simplement :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Vecteur(cA,cB):=normal(cB-cA);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[1,2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cB:=[-1,-3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Vecteur(cA,cB)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On fait la figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">A:=point(cA);B:=point(cB);vecteur(A,B);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Vérifions avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">coordonnees(vecteur(A,B))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec95" Calculer les coordonnées de la somme de deux vecteurs dans un repère-->
<h3 id="sec95" class="subsection">6.4.2  Calculer les coordonnées de la somme de deux vecteurs dans un repère</h3><!--SEC END --><p>
Si les vecteurs <span style="font-family:monospace">V1</span> et <span style="font-family:monospace">V2</span> ont pour coordonnées <span style="font-family:monospace">cV1:=[x1,y1]</span> 
et <span style="font-family:monospace">cV2:=[x2,y2]</span>, les coordonnées du vecteur <span style="font-family:monospace">V1+V2</span> sont 
<span style="font-family:monospace">[x1+x2,y1+y2]</span>.<br>
On tape :

</p><pre class="verbatim">fonction SumVect(cV1,cV2)
 local x1,x2,y1,y2;
 x1:=cV1[0];
 y1:=cV1[1];
 x2:=cV2[0];
 y2:=cV2[1];
 retourne normal([x1+x2,y1+y2]);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


ou plus simplement :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">SumVect(cV1,cV2):=normal(cV1+cV2);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cV1:=[1,2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cV2:=[-2,3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cV3:=SumVect(cV1,cV2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On fait la figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">V1:=vecteur(0,cV1);V2:=vecteur(0,cV2);V3:=vecteur(0,cV3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Vérifions avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cV1+cV2
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC subsection id="sec96" Coordonnées de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>D</mi></mrow><annotation encoding='application/x-tex'>D</annotation></semantics></math> extrémité du vecteur 
d’origine <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> équipollent au vecteur <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>AB</annotation></semantics></math>-->
<h3 id="sec96" class="subsection">6.4.3  Coordonnées de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>D</mi></mrow><annotation encoding='application/x-tex'>D</annotation></semantics></math> extrémité du vecteur 
d’origine <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> équipollent au vecteur <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>AB</annotation></semantics></math></h3><!--SEC END --><p>
On a <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>D</mi><mo>:</mo><mo>=</mo><mi>C</mi><mo>+</mo><mo stretchy="false">(</mo><mi>B</mi><mo>&minus;</mo><mi>A</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>D:=C+(B&#x2d;A)</annotation></semantics></math>.<br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Translation(cA,cB,cC):=cC+(cB-cA);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[1,2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cB:=[2,3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cC:=[-1,1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cD:=Translation(cA,cB,cC)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On fait la figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">A:=point(cA);B:=point(cB);C:=point(cC);D:=point(cD);polygone(cA,cB,cD,cC)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Vérifions avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">coordonnees(translation(cB-cA,point(cC)))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec97" Norme d’un vecteur-->
<h3 id="sec97" class="subsection">6.4.4  Norme d’un vecteur</h3><!--SEC END --><p>
Soit le vecteur <span style="font-family:monospace">V:=[xV,yV]</span>, on pose <span style="font-family:monospace">cV:=[xV,yV]</span> la liste des 
coordonnées de V.<br>
La norme de <span style="font-family:monospace">V</span> est égale à <span style="font-family:monospace">sqrt(xV</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+yV</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2)</span>.<br>
On tape :

</p><pre class="verbatim">fonction Norme(cV)
 local xV,yV;
 xV:=cV[0];
 yV:=cV[1];
 retourne sqrt(xV^2+yV^2);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[1,2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cB:=[2,3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Norme(cB-cA)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
Vérifions avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">norm(vecteur(point(cA),point(cB)))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC section id="sec98" Changement de repères-->
<h2 id="sec98" class="section">6.5  Changement de repères</h2><!--SEC END -->
<!--TOC subsection id="sec99" Le problème-->
<h3 id="sec99" class="subsection">6.5.1  Le problème</h3><!--SEC END --><p>
Soient 2 repères orthonormés <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mo>,</mo><mi>O</mi><mi>x</mi><mo>,</mo><mi>O</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'> O,Ox,Oy</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mo>,</mo><mi>I</mi><mi>X</mi><mo>,</mo><mi>I</mi><mi>Y</mi></mrow><annotation encoding='application/x-tex'> I,IX,IY</annotation></semantics></math>. <br>
<span style="font-weight:bold">Notations :</span>
</p><ul class="itemize"><li class="li-itemize">
Soit <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'> M</annotation></semantics></math> un point ou un vecteur.<br>
On note <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>M</mi></msub></mrow><annotation encoding='application/x-tex'> c_M</annotation></semantics></math> les coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>M</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>M</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> [x_M,y_M]</annotation></semantics></math> de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'> M</annotation></semantics></math> dans le repère 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>x</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'> Oxy</annotation></semantics></math>.<br>
On note <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>C</mi> <mi>M</mi></msub></mrow><annotation encoding='application/x-tex'> C_M</annotation></semantics></math> les coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>X</mi> <mi>M</mi></msub><mo>,</mo><msub><mi>Y</mi> <mi>M</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> [X_M,Y_M]</annotation></semantics></math> de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'> M</annotation></semantics></math> dans le repère 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>X</mi><mi>Y</mi></mrow><annotation encoding='application/x-tex'> IXY</annotation></semantics></math>.
</li><li class="li-itemize">On note <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>u</mi></mrow><annotation encoding='application/x-tex'> u</annotation></semantics></math> (resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>v</mi></mrow><annotation encoding='application/x-tex'> v</annotation></semantics></math>) le vecteur unitaire porté par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>x</mi></mrow><annotation encoding='application/x-tex'> Ox</annotation></semantics></math> 
(resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'> Oy</annotation></semantics></math>)
</li><li class="li-itemize">On note <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>U</mi></mrow><annotation encoding='application/x-tex'> U</annotation></semantics></math> (resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>V</mi></mrow><annotation encoding='application/x-tex'> V</annotation></semantics></math>) le vecteur unitaire porté par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>X</mi></mrow><annotation encoding='application/x-tex'> OX</annotation></semantics></math> 
(resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>Y</mi></mrow><annotation encoding='application/x-tex'> OY</annotation></semantics></math>)
</li></ul><p>
Avec ces notations, on a :
</p><ul class="itemize"><li class="li-itemize">
le point <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi></mrow><annotation encoding='application/x-tex'> I</annotation></semantics></math> a pour coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>I</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>I</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> c_I:=[x_I,y_I]</annotation></semantics></math> dans le repère 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mo>,</mo><mi>O</mi><mi>x</mi><mo>,</mo><mi>O</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'> O,Ox,Oy</annotation></semantics></math> donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>I</mi><mo>=</mo><msub><mi>x</mi> <mi>I</mi></msub><mi>u</mi><mo>+</mo><msub><mi>y</mi> <mi>I</mi></msub><mi>v</mi></mrow><annotation encoding='application/x-tex'> OI=x_Iu+y_Iv</annotation></semantics></math>
</li><li class="li-itemize">le vecteur <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>U</mi></mrow><annotation encoding='application/x-tex'> U</annotation></semantics></math> a pour coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>U</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>U</mi></msub><mo>,</mo><mi>y</mi><mi>U</mi><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> c_U:=[x_U,yU]</annotation></semantics></math> dans le repère 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mo>,</mo><mi>O</mi><mi>x</mi><mo>,</mo><mi>O</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'> O,Ox,Oy</annotation></semantics></math> (<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msubsup><mi>x</mi> <mi>U</mi> <mn>2</mn></msubsup><mo>+</mo><msubsup><mi>y</mi> <mi>U</mi> <mn>2</mn></msubsup><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'> x_U^2+y_U^2=1</annotation></semantics></math>) donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>U</mi><mo>=</mo><msub><mi>x</mi> <mi>U</mi></msub><mi>u</mi><mo>+</mo><msub><mi>y</mi> <mi>U</mi></msub><mi>v</mi></mrow><annotation encoding='application/x-tex'> U=x_Uu+y_Uv</annotation></semantics></math> 
</li><li class="li-itemize">le vecteur <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>V</mi></mrow><annotation encoding='application/x-tex'> V</annotation></semantics></math> a pour coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>V</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>V</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>V</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> c_V:=[x_V,y_V]</annotation></semantics></math> dans le repère 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mo>,</mo><mi>O</mi><mi>x</mi><mo>,</mo><mi>O</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'> O,Ox,Oy</annotation></semantics></math> (<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msubsup><mi>x</mi> <mi>V</mi> <mn>2</mn></msubsup><mo>+</mo><msubsup><mi>y</mi> <mi>V</mi> <mn>2</mn></msubsup><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'> x_V^2+y_V^2=1</annotation></semantics></math>) donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>V</mi><mo>=</mo><msub><mi>x</mi> <mi>V</mi></msub><mi>u</mi><mo>+</mo><msub><mi>y</mi> <mi>V</mi></msub><mi>v</mi></mrow><annotation encoding='application/x-tex'> V=x_Vu+y_Vv</annotation></semantics></math>.
L’angle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>U</mi><mo>,</mo><mi>V</mi><mo stretchy="false">)</mo><mo>=</mo><mi>&pi;</mi><mo stretchy="false">/</mo><mn>2</mn></mrow><annotation encoding='application/x-tex'> (U,V)=\pi/2</annotation></semantics></math> donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>x</mi> <mi>V</mi></msub><mo>:</mo><mo>=</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>y</mi> <mi>U</mi></msub></mrow><annotation encoding='application/x-tex'> x_V:=&#x2d;y_U</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>y</mi> <mi>V</mi></msub><mo>:</mo><mo>=</mo><msub><mi>x</mi> <mi>U</mi></msub></mrow><annotation encoding='application/x-tex'> y_V:=x_U</annotation></semantics></math>
</li></ul>
<!--TOC subsection id="sec100" Le programme <span style="font-family:monospace">Changexy2XY(cM,cI,cU)</span>-->
<h3 id="sec100" class="subsection">6.5.2  Le programme <span style="font-family:monospace">Changexy2XY(cM,cI,cU)</span></h3><!--SEC END --><p><a id="sec:Changexy2XY"></a>
On connaît les coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi><mi>M</mi><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>M</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>M</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> cM:=[x_M,y_M]</annotation></semantics></math> d’un point <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'> M</annotation></semantics></math> dans le 
repère <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>O</mi><mo>,</mo><mi>O</mi><mi>x</mi><mo>,</mo><mi>O</mi><mi>y</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'> (O,Ox,Oy)</annotation></semantics></math> ainsi que les coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>I</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>I</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> c_I:=[x_I,y_I]</annotation></semantics></math> et
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>U</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>U</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>U</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> c_U:=[x_U,y_U]</annotation></semantics></math> de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi></mrow><annotation encoding='application/x-tex'> I</annotation></semantics></math> et de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>U</mi></mrow><annotation encoding='application/x-tex'> U</annotation></semantics></math> dans le repère <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>O</mi><mo>,</mo><mi>O</mi><mi>x</mi><mo>,</mo><mi>O</mi><mi>y</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'> (O,Ox,Oy)</annotation></semantics></math>.<br>
On cherche les coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>C</mi> <mi>M</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>X</mi> <mi>M</mi></msub><mo>,</mo><msub><mi>Y</mi> <mi>M</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> C_M:=[X_M,Y_M]</annotation></semantics></math> de 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'> M</annotation></semantics></math> dans le repère <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>I</mi><mo>,</mo><mi>I</mi><mi>X</mi><mo>,</mo><mi>I</mi><mi>Y</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'> (I,IX,IY)</annotation></semantics></math>.<br>
On a donc :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mrow><mtable displaystyle="false" rowspacing="0.5ex"><mtr><mtd><mi>O</mi><mi>M</mi><mo>=</mo><msub><mi>x</mi> <mi>M</mi></msub><mi>u</mi><mo>+</mo><msub><mi>y</mi> <mi>M</mi></msub><mi>v</mi></mtd> <mtd><mo>=</mo></mtd> <mtd><mi>O</mi><mi>I</mi><mo>+</mo><mi>I</mi><mi>M</mi></mtd></mtr> <mtr><mtd/> <mtd><mo>=</mo></mtd> <mtd><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>I</mi></msub><mi>u</mi><mo>+</mo><msub><mi>y</mi> <mi>I</mi></msub><mi>v</mi><mo stretchy="false">)</mo><mo>+</mo><mo stretchy="false">(</mo><msub><mi>X</mi> <mi>M</mi></msub><mi>U</mi><mo>+</mo><msub><mi>Y</mi> <mi>M</mi></msub><mi>V</mi><mo stretchy="false">)</mo></mtd></mtr> <mtr><mtd/> <mtd><mo>=</mo></mtd> <mtd><msub><mi>x</mi> <mi>I</mi></msub><mi>u</mi><mo>+</mo><msub><mi>y</mi> <mi>I</mi></msub><mi>v</mi><mo>+</mo><msub><mi>X</mi> <mi>M</mi></msub><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>U</mi></msub><mi>u</mi><mo>+</mo><msub><mi>y</mi> <mi>U</mi></msub><mi>v</mi><mo stretchy="false">)</mo><mo>+</mo><msub><mi>Y</mi> <mi>M</mi></msub><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>V</mi></msub><mi>u</mi><mo>+</mo><msub><mi>y</mi> <mi>V</mi></msub><mi>v</mi><mo stretchy="false">)</mo></mtd></mtr> <mtr><mtd/> <mtd><mo>=</mo></mtd> <mtd><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>I</mi></msub><mo>+</mo><msub><mi>X</mi> <mi>M</mi></msub><msub><mi>x</mi> <mi>U</mi></msub><mo>+</mo><msub><mi>Y</mi> <mi>M</mi></msub><msub><mi>x</mi> <mi>V</mi></msub><mo stretchy="false">)</mo><mi>u</mi><mo>+</mo><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>I</mi></msub><mo>+</mo><msub><mi>X</mi> <mi>M</mi></msub><msub><mi>y</mi> <mi>U</mi></msub><mo>+</mo><msub><mi>Y</mi> <mi>M</mi></msub><msub><mi>y</mi> <mi>V</mi></msub><mo stretchy="false">)</mo><mi>v</mi></mtd></mtr></mtable></mrow></mrow><annotation encoding='application/x-tex'> \begin{matrix}
OM=x_Mu+y_Mv&amp;=&amp;OI+IM\\
 &amp;=&amp;(x_Iu+y_Iv)+(X_MU+Y_MV) \\
 &amp;=&amp;x_Iu+y_Iv+X_M(x_Uu+y_Uv)+Y_M(x_Vu+y_Vv)\\
 &amp;=&amp;(x_I+X_Mx_U+Y_Mx_V)u+(y_I+X_My_U+Y_My_V)v
 \end{matrix} </annotation></semantics></math>
Donc :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>x</mi> <mi>M</mi></msub><mo>=</mo><msub><mi>x</mi> <mi>I</mi></msub><mo>+</mo><msub><mi>X</mi> <mi>M</mi></msub><msub><mi>x</mi> <mi>U</mi></msub><mo>+</mo><msub><mi>Y</mi> <mi>M</mi></msub><msub><mi>x</mi> <mi>V</mi></msub><mo>,</mo><mspace width="1em"/><msub><mi>y</mi> <mi>M</mi></msub><mo>=</mo><msub><mi>y</mi> <mi>I</mi></msub><mo>+</mo><msub><mi>X</mi> <mi>M</mi></msub><msub><mi>y</mi> <mi>U</mi></msub><mo>+</mo><msub><mi>Y</mi> <mi>M</mi></msub><msub><mi>y</mi> <mi>V</mi></msub></mrow><annotation encoding='application/x-tex'>x_M=x_I+X_Mx_U+Y_Mx_V, \quad
 y_M=y_I+X_My_U+Y_My_V </annotation></semantics></math>
on en déduit <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>X</mi> <mi>M</mi></msub><mo>,</mo><msub><mi>Y</mi> <mi>M</mi></msub></mrow><annotation encoding='application/x-tex'>X_M, Y_M</annotation></semantics></math>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>X</mi> <mi>M</mi></msub><mo>=</mo><mfrac><mrow><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>M</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><msub><mi>y</mi> <mi>V</mi></msub><mo>&minus;</mo><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>M</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><msub><mi>x</mi> <mi>V</mi></msub></mrow><mrow><msub><mi>x</mi> <mi>U</mi></msub><msub><mi>y</mi> <mi>V</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>U</mi></msub><msub><mi>x</mi> <mi>V</mi></msub></mrow></mfrac><mo>,</mo><mspace width="1em"/><msub><mi>Y</mi> <mi>M</mi></msub><mo>=</mo><mfrac><mrow><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>M</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><msub><mi>y</mi> <mi>U</mi></msub><mo>&minus;</mo><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>M</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><msub><mi>x</mi> <mi>U</mi></msub></mrow><mrow><msub><mi>x</mi> <mi>V</mi></msub><msub><mi>y</mi> <mi>U</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>V</mi></msub><msub><mi>x</mi> <mi>U</mi></msub></mrow></mfrac></mrow><annotation encoding='application/x-tex'>X_M= \frac{(x_M&#x2d;x_I)y_V&#x2d;(y_M&#x2d;y_I)x_V}{x_Uy_V&#x2d;y_Ux_V},
\quad
Y_M= \frac{(x_M&#x2d;x_I)y_U&#x2d;(y_M&#x2d;y_I)x_U}{x_Vy_U&#x2d;y_Vx_U}
 </annotation></semantics></math>
Or <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>x</mi> <mi>V</mi></msub><mo>=</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>y</mi> <mi>U</mi></msub></mrow><annotation encoding='application/x-tex'> x_V=&#x2d;y_U</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>y</mi> <mi>V</mi></msub><mo>=</mo><msub><mi>x</mi> <mi>U</mi></msub></mrow><annotation encoding='application/x-tex'> y_V=x_U</annotation></semantics></math> donc
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>x</mi> <mi>U</mi></msub><msub><mi>y</mi> <mi>V</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>U</mi></msub><msub><mi>x</mi> <mi>V</mi></msub><mo>=</mo><msubsup><mi>x</mi> <mi>U</mi> <mn>2</mn></msubsup><mo>+</mo><msubsup><mi>y</mi> <mi>U</mi> <mn>2</mn></msubsup><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>x_Uy_V&#x2d;y_Ux_V=x_U^2+y_U^2=1  </annotation></semantics></math>
Finalement :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>X</mi> <mi>M</mi></msub><mo>=</mo><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>M</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><msub><mi>x</mi> <mi>U</mi></msub><mo>+</mo><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>M</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><msub><mi>y</mi> <mi>U</mi></msub><mo>,</mo><mspace width="1em"/><msub><mi>Y</mi> <mi>M</mi></msub><mo>=</mo><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>M</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><msub><mi>y</mi> <mi>U</mi></msub><mo>&minus;</mo><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>M</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><msub><mi>x</mi> <mi>U</mi></msub></mrow><annotation encoding='application/x-tex'>X_M= (x_M&#x2d;x_I)x_U+(y_M&#x2d;y_I)y_U, \quad
 Y_M= (x_M&#x2d;x_I)y_U&#x2d;(y_M&#x2d;y_I)x_U </annotation></semantics></math>
On tape :

</p><pre class="verbatim">fonction Changexy2XY(cM,cI,cU)
local xM,xI,xU,xV,yM,yI,yU,yV,l;
xM:=cM[0];
yM:=cM[1];
xI:=cI[0];
yI:=cI[1];
xU:=cU[0];
yU:=cU[1];
l:=xU^2+yU^2;
si l!=1 alors l:=sqrt(l);xU:=xU/l;yU:=yU/l;fsi;
xV:=-yU;
yV:=xU;
retourne normal([((xM-xI)*xU+(yM-yI)*yU),(-(xM-xI)*yU+(yM-yI)*xU)]);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


<span style="font-weight:bold">Remarque</span> <br>
Dans le programme ci-dessus, on teste si le vecteur <span style="font-family:monospace">U</span> est unitaire, si ce 
n’est pas le cas, on le rend unitaire avec :<br>
<span style="font-family:monospace">l:=xU</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+yU</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2;si l!=1 alors l:=sqrt(l);xU:=xU/l;yU:=yU/l;fsi;</span><br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cM:=[5/2,9/2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cI:=[2,3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cU:=[sqrt(2)/2,sqrt(2)/2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cV:=[-sqrt(2)/2,sqrt(2)/2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Changexy2XY(cM,cI,cU)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
La figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">O:=point(0);M:=point(cM);I:=point(cI);U:=point(cI+cU);V:=point(cI+cV);vecteur(I,U);vecteur(I,V);vecteur(I,M)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec101" Le programme <span style="font-family:monospace">ChangeXY2xy(CM,cI,cU)</span>-->
<h3 id="sec101" class="subsection">6.5.3  Le programme <span style="font-family:monospace">ChangeXY2xy(CM,cI,cU)</span></h3><!--SEC END --><p><a id="sec:ChangeXY2xy"></a>
Il s’agit du programme inverse du précédent :
on connaît les coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>C</mi> <mi>M</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>X</mi> <mi>M</mi></msub><mo>,</mo><msub><mi>Y</mi> <mi>M</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>C_M:=[X_M,Y_M]</annotation></semantics></math> d’un point <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'>M</annotation></semantics></math> dans le 
repère <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>I</mi><mo>,</mo><mi>I</mi><mi>X</mi><mo>,</mo><mi>I</mi><mi>Y</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>(I,IX,IY)</annotation></semantics></math> ainsi que les coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>I</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>I</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>c_I:=[x_I,y_I]</annotation></semantics></math> et
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>U</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>U</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>U</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>c_U:=[x_U,y_U]</annotation></semantics></math> de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi></mrow><annotation encoding='application/x-tex'>I</annotation></semantics></math> et de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>U</mi></mrow><annotation encoding='application/x-tex'>U</annotation></semantics></math> dans le repère <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>O</mi><mo>,</mo><mi>O</mi><mi>x</mi><mo>,</mo><mi>O</mi><mi>y</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>(O,Ox,Oy)</annotation></semantics></math>.
On cherche les coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>M</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>M</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>M</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>c_M:=[x_M,y_M]</annotation></semantics></math> de 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'>M</annotation></semantics></math> dans le repère <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>O</mi><mo>,</mo><mi>O</mi><mi>x</mi><mo>,</mo><mi>O</mi><mi>y</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>(O,Ox,Oy)</annotation></semantics></math>.</p><p>On a vu précédemment que :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>x</mi> <mi>M</mi></msub><mo>=</mo><msub><mi>x</mi> <mi>I</mi></msub><mo>+</mo><msub><mi>X</mi> <mi>M</mi></msub><msub><mi>x</mi> <mi>U</mi></msub><mo>+</mo><msub><mi>Y</mi> <mi>M</mi></msub><msub><mi>x</mi> <mi>V</mi></msub><mo>,</mo><mspace width="1em"/><msub><mi>y</mi> <mi>M</mi></msub><mo>=</mo><msub><mi>y</mi> <mi>I</mi></msub><mo>+</mo><msub><mi>X</mi> <mi>M</mi></msub><msub><mi>y</mi> <mi>U</mi></msub><mo>+</mo><msub><mi>Y</mi> <mi>M</mi></msub><msub><mi>y</mi> <mi>V</mi></msub></mrow><annotation encoding='application/x-tex'>x_M=x_I+X_Mx_U+Y_Mx_V, \quad
 y_M=y_I+X_My_U+Y_My_V </annotation></semantics></math>
On tape :

</p><pre class="verbatim">fonction ChangeXY2xy(CM,cI,cU)
 local XM,xI,xU,xV,YM,yI,yU,yV,l;
 XM:=CM[0];
 YM:=CM[1];
 xI:=cI[0];
 yI:=cI[1];
 xU:=cU[0];
 yU:=cU[1];
 l:=xU^2+yU^2;
 si l!=1 alors l:=sqrt(l);xU:=xU/l;yU:=yU/l;fsi;
 xV:=-yU;
 yV:=xU;
 retourne normal([xI+XM*xU+YM*xV,yI+XM*yU+YM*yV]);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


<span style="font-weight:bold">Remarque</span><br>
 Dans le programme ci-dessus, si le vecteur <span style="font-family:monospace">U</span> n’est pas 
unitaire, on le rend unitaire :<br>
<span style="font-family:monospace">l:=xU</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+yU</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2;si l!=1 alors l:=sqrt(l);xU:=xU/l;yU:=yU/l;fsi;</span><br>
On tape :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">CM:=[sqrt(2),sqrt(2)/2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cI:=[2,3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cU:=[sqrt(2)/2,sqrt(2)/2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cV:=[-sqrt(2)/52,sqrt(2)/2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">ChangeXY2xy(CM,cI,cU)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
La figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">O:=point(0);M:=point(cI+CM[0]*cU+CM[1]*cV);I:=point(cI);U:=point(cI+cU);V:=point(cI+cV);vecteur(I,U);vecteur(I,V);vecteur(I,M)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC subsection id="sec102" Exercices-->
<h3 id="sec102" class="subsection">6.5.4  Exercices</h3><!--SEC END --><p>
En se servant des programmes précédents, faire les programmes :
</p><ol class="enumerate" type=1><li class="li-enumerate">
calculant les coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>C</mi></msub></mrow><annotation encoding='application/x-tex'>c_C</annotation></semantics></math> du sommet <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> d’un triangle 
équilatéral direct <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math> connaissant les coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>A</mi></msub></mrow><annotation encoding='application/x-tex'>c_A</annotation></semantics></math> de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> 
et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>B</mi></msub></mrow><annotation encoding='application/x-tex'>c_B</annotation></semantics></math> de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi></mrow><annotation encoding='application/x-tex'>B</annotation></semantics></math>, 
</li><li class="li-enumerate">calculant les coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>C</mi></msub></mrow><annotation encoding='application/x-tex'>c_C</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>D</mi></msub></mrow><annotation encoding='application/x-tex'>c_D</annotation></semantics></math> 
des sommets <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>D</mi></mrow><annotation encoding='application/x-tex'>D</annotation></semantics></math> d’un 
carré direct <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'>ABCD</annotation></semantics></math> connaissant les coordonnées 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>A</mi></msub></mrow><annotation encoding='application/x-tex'>c_A</annotation></semantics></math> de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>B</mi></msub></mrow><annotation encoding='application/x-tex'>c_B</annotation></semantics></math> de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi></mrow><annotation encoding='application/x-tex'>B</annotation></semantics></math>.
</li></ol><p>
<span style="font-weight:bold">Solution</span><br>
1/
Soit un triangle équilatéral direct <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math>. Dans le repère 
orthonormé <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>x</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'>Oxy</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> a pour coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>A</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>A</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> c_A:=[x_A,y_A]</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi></mrow><annotation encoding='application/x-tex'>B</annotation></semantics></math> a pour
coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>B</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>B</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>B</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> c_B:=[x_B,y_B]</annotation></semantics></math>.<br>
Cherchons les coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>C</mi> <mi>C</mi></msub><mo>=</mo><mo stretchy="false">[</mo><msub><mi>X</mi> <mi>C</mi></msub><mo>,</mo><msub><mi>Y</mi> <mi>C</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> C_C=[X_C,Y_C]</annotation></semantics></math> du point <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> dans le
repère d’origine <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> et d’axe des <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>X</mi></mrow><annotation encoding='application/x-tex'>X</annotation></semantics></math> dirigé selon le vecteur <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>AB</annotation></semantics></math>.
On pose :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>l</mi><mo>:</mo><mo>=</mo><msqrt><mrow><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>B</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>A</mi></msub><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>+</mo><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>B</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>A</mi></msub><msup><mo stretchy="false">)</mo> <mn>2</mn></msup></mrow></msqrt></mrow><annotation encoding='application/x-tex'>l:=\sqrt{(x_B&#x2d;x_A)^2+(y_B&#x2d;y_A)^2}  </annotation></semantics></math>
On a :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>c</mi> <mi>U</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><mfrac><mrow><msub><mi>x</mi> <mi>B</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>A</mi></msub></mrow><mi>l</mi></mfrac><mo>,</mo><mfrac><mrow><msub><mi>y</mi> <mi>B</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>A</mi></msub></mrow><mi>l</mi></mfrac><mo stretchy="false">]</mo><mo>,</mo><mspace width="1em"/><msub><mi>C</mi> <mi>C</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><mfrac><mi>l</mi><mn>2</mn></mfrac><mo>,</mo><mfrac><mrow><mi>l</mi><msqrt><mn>3</mn></msqrt></mrow><mn>2</mn></mfrac><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>c_U:=[\frac{x_B&#x2d;x_A}{l},\frac{y_B&#x2d;y_A}{l}], \quad
 C_C:=[\frac{l}{2},\frac{l\sqrt{3}}{2}]  </annotation></semantics></math>
Et les coordonnées de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> dans le repère orthonormé <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>x</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'>Oxy</annotation></semantics></math> sont :<br>
<span style="font-family:monospace">ChangeXY2xy(CC,cA,cU)</span> (fonction écrite précédemment cf
<a href="#sec%3AChangeXY2xy">6.5.3</a>).<br>
On tape :

</p><pre class="verbatim">fonction Coordequi(cA,cB)
 local xA,yA,xB,yB,cU,l,CC;
 xA:=cA[0];
 yA:=cA[1];
 xB:=cB[0];
 yB:=cB[1];
 l:=sqrt((xB-xA)^2+(yB-yA)^2);
 cU:=[(xB-xA)/l,(yB-yA)/l];
 CC:=[l/2,l*sqrt(3)/2];
 retourne ChangeXY2xy(CC,cA,cU);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[1,2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cB:=[-1,-3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cC:=Coordequi(cA,cB)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On fait la figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">A:=point(cA);B:=point(cB);T:=triangle_equilateral(A,B);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Vérifions avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">normal(coordonnees(sommets(T)[2]))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
2/ 
Soit un carré direct <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'>ABCD</annotation></semantics></math>, avec <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> de coordonnées
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>A</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>A</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>c_A:=[x_A,y_A]</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi></mrow><annotation encoding='application/x-tex'>B</annotation></semantics></math> de coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>B</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>B</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>B</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>c_B:=[x_B,y_B]</annotation></semantics></math>
dans le repère 
orthonormé <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>x</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'>Oxy</annotation></semantics></math>.<br>
Cherchons les coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>C</mi> <mi>C</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>X</mi> <mi>C</mi></msub><mo>,</mo><msub><mi>Y</mi> <mi>C</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>C_C:=[X_C,Y_C]</annotation></semantics></math> 
du point <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>C</mi> <mi>D</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>X</mi> <mi>D</mi></msub><mo>,</mo><msub><mi>Y</mi> <mi>D</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>C_D:=[X_D,Y_D]</annotation></semantics></math>
des points <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>D</mi></mrow><annotation encoding='application/x-tex'>D</annotation></semantics></math> dans le repère d’origine <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> et d’axe des <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>X</mi></mrow><annotation encoding='application/x-tex'>X</annotation></semantics></math> dirigé 
selon le vecteur <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>AB</annotation></semantics></math>. On pose :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>l</mi><mo>:</mo><mo>=</mo><msqrt><mrow><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>B</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>A</mi></msub><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>+</mo><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>B</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>A</mi></msub><msup><mo stretchy="false">)</mo> <mn>2</mn></msup></mrow></msqrt></mrow><annotation encoding='application/x-tex'>l:=\sqrt{(x_B&#x2d;x_A)^2+(y_B&#x2d;y_A)^2}  </annotation></semantics></math>
On a :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>c</mi> <mi>U</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><mfrac><mrow><msub><mi>x</mi> <mi>B</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>A</mi></msub></mrow><mi>l</mi></mfrac><mo>,</mo><mfrac><mrow><msub><mi>y</mi> <mi>B</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>A</mi></msub></mrow><mi>l</mi></mfrac><mo stretchy="false">]</mo><mo>,</mo><mspace width="1em"/><msub><mi>c</mi> <mi>C</mi></msub><mo>=</mo><mo stretchy="false">[</mo><mi>l</mi><mo>,</mo><mi>l</mi><mo stretchy="false">]</mo><mo>,</mo><mspace width="1em"/><msub><mi>c</mi> <mi>D</mi></msub><mo>=</mo><mo stretchy="false">[</mo><mn>0</mn><mo>,</mo><mi>l</mi><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>c_U:=[\frac{x_B&#x2d;x_A}{l},\frac{y_B&#x2d;y_A}{l}], \quad
c_C=[l,l], \quad c_D=[0,l]  </annotation></semantics></math>
Donc les coordonnées de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> dans le repère orthonormé <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>x</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'>Oxy</annotation></semantics></math> sont :<br>
<span style="font-family:monospace">ChangeXY2xy(CC,cA,cU)</span><br>
les coordonnées de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>D</mi></mrow><annotation encoding='application/x-tex'>D</annotation></semantics></math> dans le repère orthonormé <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>x</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'>Oxy</annotation></semantics></math> sont :<br>
<span style="font-family:monospace">ChangeXY2xy(CD,cA,cU)</span> (fonction écrite précédemment cf 
<a href="#sec%3AChangeXY2xy">6.5.3</a>).

</p><pre class="verbatim">fonction Coordcarre(cA,cB)
 local xA,yA,xB,yB,CC,CD,cU,l;
 xA:=cA[0];
 yA:=cA[1];
 xB:=cB[0];
 yB:=cB[1];
 l:=sqrt((xB-xA)^2+(yB-yA)^2);
 cU:=[(xB-xA)/l,(yB-yA)/l];
 CC:=[l,l];
 CD:=[0,l];
 retourne ChangeXY2xy(CC,cA,cU),ChangeXY2xy(CD,cA,cU);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[1,2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cB:=[-1,-3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cC:=Coordcarre(cA,cB)[0]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cD:=Coordcarre(cA,cB)[1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On fait la figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">A:=point(cA);B:=point(cB);K:=carre(A,B)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On vérifie avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">normal(coordonnees(sommets(K)[2],sommets(K)[3]))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec103" Cercles, Tangentes à un cercle-->
<h2 id="sec103" class="section">6.6  Cercles, Tangentes à un cercle</h2><!--SEC END -->
<!--TOC subsection id="sec104" Équation d’un cercle défini par son centre et son rayon-->
<h3 id="sec104" class="subsection">6.6.1  Équation d’un cercle défini par son centre et son rayon</h3><!--SEC END --><p>
Le cercle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> défini par son centre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> de coordonnées 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>A</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[x_A,y_A]</annotation></semantics></math> et de rayon <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi></mrow><annotation encoding='application/x-tex'>r</annotation></semantics></math> a pour équation :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mo>&minus;</mo><msub><mi>x</mi> <mi>A</mi></msub><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>+</mo><mo stretchy="false">(</mo><mi>y</mi><mo>&minus;</mo><msub><mi>y</mi> <mi>A</mi></msub><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>=</mo><msup><mi>r</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>(x&#x2d;x_A)^2+(y&#x2d;y_A)^2=r^2 </annotation></semantics></math> 
ou encore
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>y</mi> <mn>2</mn></msup><mo>&minus;</mo><mn>2</mn><msub><mi>x</mi> <mi>A</mi></msub><mi>x</mi><mo>&minus;</mo><mn>2</mn><msub><mi>y</mi> <mi>A</mi></msub><mi>y</mi><mo>+</mo><msubsup><mi>x</mi> <mi>A</mi> <mn>2</mn></msubsup><mo>+</mo><msubsup><mi>y</mi> <mi>A</mi> <mn>2</mn></msubsup><mo>&minus;</mo><msup><mi>r</mi> <mn>2</mn></msup><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>x^2+y^2&#x2d;2x_Ax&#x2d;2y_Ay+x_A^2+y_A^2&#x2d;r^2=0 </annotation></semantics></math>
On va écrire une procédure Cercle qui renvoie une liste constituée des
coordonnées de son centre, de son rayon et de son équation.<br>
On tape :

</p><pre class="verbatim">fonction Cercle1(cA,r)
 //cercle defini par son centre et son rayon
 local xA,yA;
 xA:=cA[0];
 yA:=cA[1];
 retourne [cA,r,x^2+y^2-2*xA*x-2*yA*y+xA^2+yA^2-r^2=0];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


</p>
<!--TOC subsection id="sec105" Équation d’un cercle défini par son diamètre-->
<h3 id="sec105" class="subsection">6.6.2  Équation d’un cercle défini par son diamètre</h3><!--SEC END --><p>
Si les points <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi></mrow><annotation encoding='application/x-tex'>B</annotation></semantics></math> ont pour coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>A</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[x_A,y_A]</annotation></semantics></math> et 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mi>x</mi><mi>B</mi><mo>,</mo><mi>y</mi><mi>B</mi><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[xB,yB]</annotation></semantics></math>, le cercle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> de diamètre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>AB</annotation></semantics></math> a pour équation :<br>
si <span style="font-family:monospace">M:= Milieu(A,B)</span>, si <span style="font-family:monospace">xM:=M[0]</span>, si <span style="font-family:monospace">yM:=M[1]</span> et si 
<span style="font-family:monospace">r:=Longueur(A,B)/2</span> :<br>
<span style="font-family:monospace">(x-xM)</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+(y-yM)</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2=r</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2</span> ou encore<br>
<span style="font-family:monospace">x</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+y</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2-2*xM*x-2*yM*y+xM</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2+yM</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2-r</span><code><span style="font-family:monospace">^</span></code><span style="font-family:monospace">2=0</span><br>
On va écrire une procédure Cercle qui renvoie une liste constituée des
coordonnées de son centre, de son rayon et de son équation.<br>
On tape :

</p><pre class="verbatim">fonction Cercle2(cA,cB)
 //cercle d\'efini par son diam\`etre
 local xA,xB,xM,yA,yB,yM,M,r;
 xA:=cA[0];
 yA:=cA[1];
 xB:=cB[0];
 yB:=cB[1];
 cM:=Milieu(cA,cB):
 xM:=cM[0];
 yM:=cM[1];
 r:=Longueur(cA,cB):
 retourne [cM,r,x^2+y^2-2*xM*x-2*yM*y+xM^2+yM^2-r^2=0];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


</p>
<!--TOC subsection id="sec106" Équation d’un cercle défini par son centre et son rayon ou par son diamètre-->
<h3 id="sec106" class="subsection">6.6.3  Équation d’un cercle défini par son centre et son rayon ou par son diamètre</h3><!--SEC END --><p><a id="sec:Cercle"></a>
On peut reunir les 2 programmes en un seul en testant la dimension du 
deuxième paramètre de <span style="font-family:monospace">Cercle</span> qui est soit 
une liste de dimension 2 (cercle défini par son diamètre),
soit un réel (cercle défini par centre et rayon).<br>
On tape :

</p><pre class="verbatim">fonction Cercle(cA,L)
 local cB,xA,xB,xM,yA,yB,yM,cM,r;
 xA:=cA[0];
 yA:=cA[1];
 si type(L)==vecteur alors 
   xB:=L[0];
   yB:=L[1];
   cB:=[xB,yB]
   cM:=Milieu(cA,cB);
   xM:=cM[0];
   yM:=cM[1];
   r:=Longueur(cA,cB)/2;
   retourne  [cM,r,x^2+y^2-2*xM*x-2*yM*y+xM^2+yM^2-r^2=0];
 sinon
   r:=L;
   retourne [cA,r,x^2+y^2-2*xA*x-2*yA*y+xA^2+yA^2-r^2=0];
 fsi;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[1,2]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cB:=[-1,-3]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">r:=2
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Cercle(cA,cB)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Cercle(cA,r)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On fait la figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">A:=point(cA);B:=point(cB);C1:=cercle(A,B);C2:=cercle(A,r)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On vérifie avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">normal(equation(C1));normal(equation(C2))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC subsection id="sec107" Centre et rayon d’un cercle donné par son équation-->
<h3 id="sec107" class="subsection">6.6.4  Centre et rayon d’un cercle donné par son équation</h3><!--SEC END --><p>
On utilise ici les commandes <span style="font-family:monospace">Xcas</span>
<span style="font-family:monospace">gauche, droit ,coeff, subst</span><br>
On tape :

</p><pre class="verbatim">fonction Centrerayon(Eq)
 local k,a,b,c;
 Eq:=gauche(Eq)-droit(Eq);
 k:=coeff(Eq,x,2);
 si k!=coeff(Eq,y,2) alors retourne "ce n'est pas un cercle";fsi;
 Eq:=Eq/k;
 a:=-coeff(Eq,x,1)/2;
 b:=-coeff(Eq,y,1)/2;
 c:=subst(Eq,[x,y],[0,0]);
 retourne [a,b], normal(sqrt(a^2+b^2-c));
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Centrerayon(2x^2+2y^2-4x+2y=0)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On vérifie avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">coordonnees(centre(2x^2+2y^2-4x+2y=0)),rayon(2x^2+2y^2-4x+2y=0)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec108" Construire la tangente à un cercle en l’un de ses points-->
<h3 id="sec108" class="subsection">6.6.5  Construire la tangente à un cercle en l’un de ses points</h3><!--SEC END --><p>
Soit <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math> un cercle de centre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi></mrow><annotation encoding='application/x-tex'> I</annotation></semantics></math> de coordonnées 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>I</mi></msub><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>I</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> c_I=[x_I,y_I]</annotation></semantics></math> et de rayon <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi></mrow><annotation encoding='application/x-tex'> r</annotation></semantics></math>.<br>
Soit <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math> un point de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math> de coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>A</mi></msub><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>A</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>c_A=[x_A,y_A]</annotation></semantics></math>.
la tangente au cercle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math> en <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math> est perpendiculaire à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>A</mi></mrow><annotation encoding='application/x-tex'> IA</annotation></semantics></math>, donc
a pour pente <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>m</mi><mo>=</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><mo stretchy="false">/</mo><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'> m=&#x2d;(x_A&#x2d;x_I)/(y_A&#x2d;y_I)</annotation></semantics></math><br>
L’équation de cette tangente est donc : <span style="font-family:monospace">Droite(cA,m)</span> (fonction 
<span style="font-family:monospace">Droite</span> a été écrite précédemment cf <a href="#sec%3ADroite">6.2.1</a>).<br>
On utilise aussi, ici, les fonctions <span style="font-family:monospace">Longueur</span> (cf <a href="#sec%3ALongueur">6.1.1</a>) et 
<span style="font-family:monospace">Cercle</span> (cf <a href="#sec%3ACercle">6.6.3</a>).<br>
On tape :

</p><pre class="verbatim">fonction Tangent1(C,cA)
 local I,r,m,xI,yI,xA,yA,cI;
 cI:=C[0];
 r:=C[1];
 si Longueur(cA,cI)!=r alors retourne "A n'est pas sur C"; fsi;
 xI:=cI[0];
 yI:=cI[1];
 xA:=cA[0];
 yA:=cA[1];
 si yA!=yI alors 
   m:=-(xA-xI)/(yA-yI);
   retourne Droite(cA,m);
 fsi
 retourne x=xA; 
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cI:=[0,1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[1,0]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">r:=sqrt(2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">C:=Cercle(cI,r)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
 <br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">T1:=Tangent1(C,cA);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On fait la figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">I:=point(cI);c:=cercle(I,r);A:=point(cA);droite(T1);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On vérifie avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">t:=tangent(c,A):;equation(t)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec109" Construire les tangentes à un cercle passant par un point-->
<h3 id="sec109" class="subsection">6.6.6  Construire les tangentes à un cercle passant par un point</h3><!--SEC END --><p>
Soit <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math> un cercle de centre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi></mrow><annotation encoding='application/x-tex'> I</annotation></semantics></math> de coordonnées 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>I</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>I</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> c_I:=[x_I,y_I]</annotation></semantics></math> et de rayon <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi></mrow><annotation encoding='application/x-tex'> r</annotation></semantics></math>.<br>
Soit <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math> un point du plan de coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>A</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>A</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> c_A:=[x_A,y_A]</annotation></semantics></math>.<br>
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math> est à l’intérieur de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math> il n’y a pas de tangente à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math>
passant par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math>.</p>
<!--TOC subsubsection id="sec110" Le cas simple-->
<h4 id="sec110" class="subsubsection">Le cas simple</h4><!--SEC END --><p>
On suppose qu’on a choisi comme repère, le repère <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>X</mi><mi>Y</mi></mrow><annotation encoding='application/x-tex'>IXY</annotation></semantics></math>
d’origine le centre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi></mrow><annotation encoding='application/x-tex'> I</annotation></semantics></math> du cercle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> et
tel que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> est sur l’axe des <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>X</mi></mrow><annotation encoding='application/x-tex'>X</annotation></semantics></math> (i.e. de coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>X</mi> <mi>A</mi></msub><mo>,</mo><mn>0</mn><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[X_A,0]</annotation></semantics></math>) et 
à l’extérieur de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math>.<br>
On peut mener par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math>, 2 tangentes <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>T</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'> T_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>T</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'> T_2</annotation></semantics></math> à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math>.<br>
Soient <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'> M_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'> M_2</annotation></semantics></math> les 2 points de tangeance de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>T</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'> T_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>T</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'> T_2</annotation></semantics></math>.<br>
Les triangles <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>A</mi><msub><mi>M</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'> IAM_1</annotation></semantics></math> (resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>A</mi><msub><mi>M</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'> IAM_2</annotation></semantics></math>) sont rectangles en <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'> M_1</annotation></semantics></math> 
(resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'> M_2</annotation></semantics></math>) et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>1</mn></msub><msub><mi>M</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'> M_1M_2</annotation></semantics></math> est perpendiculaire à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>I</mi></mrow><annotation encoding='application/x-tex'> AI</annotation></semantics></math>.<br>
Soit <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>H</mi></mrow><annotation encoding='application/x-tex'> H</annotation></semantics></math> l’intersection de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>1</mn></msub><msub><mi>M</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'> M_1M_2</annotation></semantics></math> avec <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>I</mi></mrow><annotation encoding='application/x-tex'> AI</annotation></semantics></math>.<br>
On fait la figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">I:=point(0);C:=cercle(I,1);A:=point(2,0);T:=tangent(C,A);M1:=inter_unique(C,T[0]);M2:=inter_unique(C,T[1]);droite(M1,M2);M12:=droite(M1,M2):;H:=inter_unique(M12,droite(A,I))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On a :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msup><mi>r</mi> <mn>2</mn></msup><mo>=</mo><mi>I</mi><msubsup><mi>M</mi> <mn>1</mn> <mn>2</mn></msubsup><mo>=</mo><mi>I</mi><msubsup><mi>M</mi> <mn>2</mn> <mn>2</mn></msubsup><mo>=</mo><mi>I</mi><mi>A</mi><mo>&times;</mo><mi>I</mi><mi>H</mi></mrow><annotation encoding='application/x-tex'>r^2=IM_1^2=IM_2^2=IA \times IH </annotation></semantics></math>
Donc dans le repère <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>X</mi><mi>Y</mi></mrow><annotation encoding='application/x-tex'>IXY</annotation></semantics></math>, 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> a pour abscisse <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>X</mi> <mi>A</mi></msub><mo>=</mo><mtext>Longueur(cI,cA)</mtext></mrow><annotation encoding='application/x-tex'>X_A=\mbox{Longueur(cI,cA)}</annotation></semantics></math> et pour ordonnée 0.<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>H</mi></mrow><annotation encoding='application/x-tex'>H</annotation></semantics></math> a pour abscisse <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mfrac><mrow><msup><mi>r</mi> <mn>2</mn></msup></mrow><mrow><msub><mi>X</mi> <mi>A</mi></msub></mrow></mfrac></mrow><annotation encoding='application/x-tex'>\frac{r^2}{X_A}</annotation></semantics></math> et pour ordonnée 0.<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'> M_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'> M_2</annotation></semantics></math> ont la même abscisse :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>X</mi> <mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow></msub><mo>=</mo><msub><mi>X</mi> <mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow></msub><mo>=</mo><mfrac><mrow><msup><mi>r</mi> <mn>2</mn></msup></mrow><mrow><msub><mi>X</mi> <mi>A</mi></msub></mrow></mfrac></mrow><annotation encoding='application/x-tex'>X_{M_1}=X_{M_2}=\frac{r^2}{X_A} </annotation></semantics></math>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'> M_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'> M_2</annotation></semantics></math> ont des ordonnées opposées :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>Y</mi> <mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow></msub><mi>&gt;</mi><mn>0</mn><mo>,</mo><mspace width="1em"/><msubsup><mi>Y</mi> <mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow> <mn>2</mn></msubsup><mo>=</mo><msup><mi>r</mi> <mn>2</mn></msup><mo>&minus;</mo><mfrac><mrow><msup><mi>r</mi> <mn>4</mn></msup></mrow><mrow><msubsup><mi>X</mi> <mi>A</mi> <mn>2</mn></msubsup></mrow></mfrac><mo>=</mo><msup><mi>r</mi> <mn>2</mn></msup><mo stretchy="false">(</mo><mn>1</mn><mo>&minus;</mo><mfrac><mrow><msup><mi>r</mi> <mn>2</mn></msup></mrow><mrow><msubsup><mi>X</mi> <mi>A</mi> <mn>2</mn></msubsup></mrow></mfrac><mo stretchy="false">)</mo><mo>,</mo><mspace width="1em"/><msub><mi>Y</mi> <mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow></msub><mo>=</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>Y</mi> <mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow></msub></mrow><annotation encoding='application/x-tex'>Y_{M_1}&amp;gt;0,\quad Y_{M_1}^2=r^2&#x2d;\frac{r^4}{X_A^2}=r^2(1&#x2d;\frac{r^2}{X_A^2}), \quad Y_{M_2}=&#x2d;Y_{M_1} </annotation></semantics></math>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>Y</mi> <mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow></msub><mo>=</mo><mi>r</mi><mfrac><msqrt><mrow><msubsup><mi>X</mi> <mi>A</mi> <mn>2</mn></msubsup><mo>&minus;</mo><msup><mi>r</mi> <mn>2</mn></msup></mrow></msqrt><mrow><msub><mi>X</mi> <mi>A</mi></msub></mrow></mfrac><mo>,</mo><mspace width="1em"/><msub><mi>Y</mi> <mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow></msub><mo>=</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>Y</mi> <mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow></msub></mrow><annotation encoding='application/x-tex'>Y_{M_1}=r\frac{\sqrt{X_A^2&#x2d;r^2}}{X_A}, \quad Y_{M_2}=&#x2d;Y_{M_1}  </annotation></semantics></math>
Les tangentes sont donc :
</p><div class="center">
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mtext>Droite</mtext><mo stretchy="false">(</mo><mo stretchy="false">[</mo><msub><mi>X</mi> <mi>A</mi></msub><mo>,</mo><mn>0</mn><mo stretchy="false">]</mo><mo>,</mo><mo stretchy="false">[</mo><msub><mi>X</mi> <mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow></msub><mo>,</mo><msub><mi>Y</mi> <mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow></msub><mo stretchy="false">]</mo><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'> \mbox{Droite}([X_A,0], [X_{M_1},Y_{M_1}])</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mtext>Droite</mtext><mo stretchy="false">(</mo><mo stretchy="false">[</mo><msub><mi>X</mi> <mi>A</mi></msub><mo>,</mo><mn>0</mn><mo stretchy="false">]</mo><mo>,</mo><mo stretchy="false">[</mo><msub><mi>X</mi> <mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow></msub><mo>,</mo><msub><mi>Y</mi> <mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow></msub><mo stretchy="false">]</mo><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'> \mbox{Droite}([X_A,0], [X_{M_2},Y_{M_2}])</annotation></semantics></math>
</div><p>
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math> est sur <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math> (i.e. <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>X</mi> <mi>A</mi></msub><mo>=</mo><mo>=</mo><mi>r</mi></mrow><annotation encoding='application/x-tex'> X_A==r</annotation></semantics></math>) alors on peut mener par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A </annotation></semantics></math>,
une tangente <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>T</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'> T_1</annotation></semantics></math> à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math> qui est <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mtext>Droite</mtext><mo stretchy="false">(</mo><mi>x</mi><mo>=</mo><msub><mi>X</mi> <mi>A</mi></msub><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'> \mbox{Droite}(x=X_A)</annotation></semantics></math>.</p>
<!--TOC subsubsection id="sec111" Le cas général-->
<h4 id="sec111" class="subsubsection">Le cas général</h4><!--SEC END --><p>
On se ramène au cas précédent par changement de repère.<br>
Soit <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>x</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'>Oxy</annotation></semantics></math> le repère.
Dans le repère <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>x</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'>Oxy</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi></mrow><annotation encoding='application/x-tex'>I</annotation></semantics></math> (resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math>) a pour coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>I</mi></msub></mrow><annotation encoding='application/x-tex'>c_I</annotation></semantics></math> (resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>c</mi> <mi>A</mi></msub></mrow><annotation encoding='application/x-tex'>c_A</annotation></semantics></math>).<br>
On fait un changement de repère en prenant le centre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi></mrow><annotation encoding='application/x-tex'>I</annotation></semantics></math> du cercle
comme origine et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>A</mi></mrow><annotation encoding='application/x-tex'> IA</annotation></semantics></math> comme axe des <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>X</mi></mrow><annotation encoding='application/x-tex'> X</annotation></semantics></math>.<br>
On note <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>X</mi> <mi>M</mi></msub></mrow><annotation encoding='application/x-tex'> X_M</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>Y</mi> <mi>M</mi></msub></mrow><annotation encoding='application/x-tex'> Y_M</annotation></semantics></math> les coordonnées d’un point <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'> M</annotation></semantics></math> ou d’un 
vecteur <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'> M</annotation></semantics></math> dans le nouveau repère <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>X</mi><mi>Y</mi></mrow><annotation encoding='application/x-tex'>IXY</annotation></semantics></math> et 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>x</mi> <mi>M</mi></msub></mrow><annotation encoding='application/x-tex'> x_M</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>y</mi> <mi>M</mi></msub></mrow><annotation encoding='application/x-tex'> y_M</annotation></semantics></math> les coordonnées de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'>M</annotation></semantics></math> dans le repère <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>O</mi><mi>x</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'>Oxy</annotation></semantics></math>.<br>
Dans le repère <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>X</mi><mi>Y</mi></mrow><annotation encoding='application/x-tex'>IXY</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> a pour abscisse <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>X</mi> <mi>A</mi></msub><mo>=</mo><mtext>Longueur</mtext><mo stretchy="false">(</mo><msub><mi>c</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>c</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>X_A=\mbox{Longueur}(c_A,c_I)</annotation></semantics></math> et 
pour ordonnée 0.<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>H</mi></mrow><annotation encoding='application/x-tex'>H</annotation></semantics></math> a pour abscisse <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mfrac><mrow><msup><mi>r</mi> <mn>2</mn></msup></mrow><mrow><msub><mi>X</mi> <mi>A</mi></msub></mrow></mfrac></mrow><annotation encoding='application/x-tex'>\frac{r^2}{X_A}</annotation></semantics></math> et pour ordonnée 0.<br>
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>U</mi></mrow><annotation encoding='application/x-tex'> U</annotation></semantics></math> est le vecteur unitaire de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>X</mi></mrow><annotation encoding='application/x-tex'> IX</annotation></semantics></math> on a :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>x</mi> <mi>U</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><mo stretchy="false">/</mo><msub><mi>X</mi> <mi>A</mi></msub></mrow><annotation encoding='application/x-tex'> x_U:=(x_A&#x2d;x_I)/X_A</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>y</mi> <mi>U</mi></msub><mo>:</mo><mo>=</mo><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><mo stretchy="false">/</mo><msub><mi>X</mi> <mi>A</mi></msub></mrow><annotation encoding='application/x-tex'> y_U:=(y_A&#x2d;y_I)/X_A</annotation></semantics></math> avec <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>X</mi> <mi>A</mi></msub><mo>:</mo><mo>=</mo><mtext>Longueur</mtext><mo stretchy="false">(</mo><msub><mi>c</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>c</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'> X_A:=\mbox{Longueur}(c_A,c_I)</annotation></semantics></math>.<br>
On a vu que (cf <a href="#sec%3AChangexy2XY">6.5.2</a>) :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>x</mi> <mi>M</mi></msub><mo>=</mo><msub><mi>x</mi> <mi>I</mi></msub><mo>+</mo><msub><mi>X</mi> <mi>M</mi></msub><msub><mi>x</mi> <mi>U</mi></msub><mo>+</mo><msub><mi>Y</mi> <mi>M</mi></msub><msub><mi>x</mi> <mi>V</mi></msub><mo>,</mo><mspace width="1em"/><msub><mi>y</mi> <mi>M</mi></msub><mo>=</mo><msub><mi>y</mi> <mi>I</mi></msub><mo>+</mo><msub><mi>X</mi> <mi>M</mi></msub><msub><mi>y</mi> <mi>U</mi></msub><mo>+</mo><msub><mi>Y</mi> <mi>M</mi></msub><msub><mi>y</mi> <mi>V</mi></msub></mrow><annotation encoding='application/x-tex'>x_M=x_I+X_Mx_U+Y_Mx_V, \quad  y_M=y_I+X_My_U+Y_My_V  </annotation></semantics></math>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>x</mi> <mi>V</mi></msub><mo>:</mo><mo>=</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>y</mi> <mi>U</mi></msub><mo>,</mo><mspace width="1em"/><msub><mi>y</mi> <mi>V</mi></msub><mo>:</mo><mo>=</mo><msub><mi>x</mi> <mi>U</mi></msub></mrow><annotation encoding='application/x-tex'>x_V:=&#x2d;y_U, \quad y_V:= x_U </annotation></semantics></math>
Donc :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>x</mi> <mi>M</mi></msub><mo>=</mo><msub><mi>x</mi> <mi>I</mi></msub><mo>+</mo><msub><mi>X</mi> <mi>M</mi></msub><msub><mi>x</mi> <mi>U</mi></msub><mo>&minus;</mo><msub><mi>Y</mi> <mi>M</mi></msub><msub><mi>y</mi> <mi>U</mi></msub><mo>,</mo><mspace width="1em"/><msub><mi>y</mi> <mi>M</mi></msub><mo>=</mo><msub><mi>y</mi> <mi>I</mi></msub><mo>+</mo><msub><mi>X</mi> <mi>M</mi></msub><msub><mi>y</mi> <mi>U</mi></msub><mo>+</mo><msub><mi>Y</mi> <mi>M</mi></msub><msub><mi>x</mi> <mi>U</mi></msub></mrow><annotation encoding='application/x-tex'>x_M=x_I+X_Mx_U&#x2d;Y_My_U, \quad y_M=y_I+X_My_U+Y_Mx_U </annotation></semantics></math>
En remplaçant <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>x</mi> <mi>U</mi></msub></mrow><annotation encoding='application/x-tex'> x_U</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>y</mi> <mi>U</mi></msub></mrow><annotation encoding='application/x-tex'> y_U</annotation></semantics></math> par leur valeur, on a :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>x</mi> <mi>M</mi></msub><mo>=</mo><msub><mi>x</mi> <mi>I</mi></msub><mo>+</mo><mfrac><mrow><msub><mi>X</mi> <mi>M</mi></msub><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><mo>&minus;</mo><msub><mi>Y</mi> <mi>M</mi></msub><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow><mrow><mtext>Longueur</mtext><mo stretchy="false">(</mo><msub><mi>c</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>c</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow></mfrac><mspace width="1em"/><msub><mi>y</mi> <mi>M</mi></msub><mo>=</mo><msub><mi>y</mi> <mi>I</mi></msub><mo>+</mo><mfrac><mrow><msub><mi>X</mi> <mi>M</mi></msub><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><mo>+</mo><msub><mi>Y</mi> <mi>M</mi></msub><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow><mrow><mtext>Longueur</mtext><mo stretchy="false">(</mo><msub><mi>c</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>c</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow></mfrac></mrow><annotation encoding='application/x-tex'>x_M=x_I+\frac{X_M(x_A&#x2d;x_I)&#x2d;Y_M(y_A&#x2d;y_I)}{\mbox{Longueur}(c_A,c_I)}
\quad
y_M=y_I+\frac{X_M(y_A&#x2d;y_I)+Y_M(x_A&#x2d;x_I)}{\mbox{Longueur}(c_A,c_I)} </annotation></semantics></math>
Dans le repère <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>X</mi><mi>Y</mi></mrow><annotation encoding='application/x-tex'>IXY</annotation></semantics></math> les coordonnées de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'> M_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'> M_2</annotation></semantics></math> sont :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>X</mi> <mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow></msub><mo>=</mo><msub><mi>X</mi> <mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow></msub><mo>=</mo><msup><mi>r</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><msub><mi>x</mi> <mi>A</mi></msub></mrow><annotation encoding='application/x-tex'>X_{M_1}=X_{M_2}=r^2/x_A </annotation></semantics></math>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msub><mi>Y</mi> <mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow></msub><mo>=</mo><mi>r</mi><mfrac><msqrt><mrow><msubsup><mi>X</mi> <mi>A</mi> <mn>2</mn></msubsup><mo>&minus;</mo><msup><mi>r</mi> <mn>2</mn></msup></mrow></msqrt><mrow><msub><mi>X</mi> <mi>A</mi></msub></mrow></mfrac><mo>,</mo><mspace width="1em"/><msub><mi>Y</mi> <mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow></msub><mo>=</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><msub><mi>Y</mi> <mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow></msub></mrow><annotation encoding='application/x-tex'>Y_{M_1}=r\frac{\sqrt{X_A^2&#x2d;r^2}}{X_A}, \quad Y_{M_2}=&#x2d;Y_{M_1}  </annotation></semantics></math>
Donc :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mrow><mtable displaystyle="false" rowspacing="0.5ex"><mtr><mtd><msub><mi>x</mi> <mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow></msub></mtd> <mtd><mo>=</mo></mtd> <mtd><msub><mi>x</mi> <mi>I</mi></msub><mo>+</mo><mfrac><mrow><msup><mi>r</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><msub><mi>x</mi> <mi>A</mi></msub><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><mo>&minus;</mo><mi>r</mi><msqrt><mrow><mn>1</mn><mo>&minus;</mo><msup><mi>r</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><msub><mi>x</mi> <mi>A</mi></msub></mrow></msqrt><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow><mrow><mtext>Longueur</mtext><mo stretchy="false">(</mo><msub><mi>c</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>c</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow></mfrac></mtd></mtr> <mtr><mtd><msub><mi>y</mi> <mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow></msub></mtd> <mtd><mo>=</mo></mtd> <mtd><msub><mi>y</mi> <mi>I</mi></msub><mo>+</mo><mfrac><mrow><msup><mi>r</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><msub><mi>x</mi> <mi>A</mi></msub><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><mo>+</mo><mi>r</mi><msqrt><mrow><mn>1</mn><mo>&minus;</mo><msup><mi>r</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><msub><mi>x</mi> <mi>A</mi></msub></mrow></msqrt><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow><mrow><mtext>Longueur</mtext><mo stretchy="false">(</mo><msub><mi>c</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>c</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow></mfrac><mo>,</mo></mtd></mtr> <mtr><mtd><msub><mi>x</mi> <mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow></msub></mtd> <mtd><mo>=</mo></mtd> <mtd><msub><mi>x</mi> <mi>I</mi></msub><mo>+</mo><mfrac><mrow><msup><mi>r</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><msub><mi>x</mi> <mi>A</mi></msub><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><mo>+</mo><mi>r</mi><msqrt><mrow><mn>1</mn><mo>&minus;</mo><msup><mi>r</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><msub><mi>x</mi> <mi>A</mi></msub></mrow></msqrt><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow><mrow><mtext>Longueur</mtext><mo stretchy="false">(</mo><msub><mi>c</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>c</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow></mfrac><mo>,</mo></mtd></mtr> <mtr><mtd><msub><mi>y</mi> <mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow></msub></mtd> <mtd><mo>=</mo></mtd> <mtd><msub><mi>y</mi> <mi>I</mi></msub><mo>+</mo><mfrac><mrow><msup><mi>r</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><msub><mi>x</mi> <mi>A</mi></msub><mo stretchy="false">(</mo><msub><mi>y</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">)</mo><mo>&minus;</mo><mi>r</mi><msqrt><mrow><mn>1</mn><mo>&minus;</mo><msup><mi>r</mi> <mn>2</mn></msup><mo stretchy="false">/</mo><msub><mi>x</mi> <mi>A</mi></msub></mrow></msqrt><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>&minus;</mo><msub><mi>x</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow><mrow><mtext>Longueur</mtext><mo stretchy="false">(</mo><msub><mi>c</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>c</mi> <mi>I</mi></msub><mo stretchy="false">)</mo></mrow></mfrac></mtd></mtr></mtable></mrow></mrow><annotation encoding='application/x-tex'> \begin{matrix}
 x_{M_1}&amp;=&amp;x_I+\frac{r^2/x_A(x_A&#x2d;x_I)&#x2d;r\sqrt{1&#x2d;r^2/x_A}(y_A&#x2d;y_I)}{\mbox{Longueur}(c_A,c_I)} \\
y_{M_1}&amp;=&amp;y_I+\frac{r^2/x_A(y_A&#x2d;y_I)+r\sqrt{1&#x2d;r^2/x_A}(x_A&#x2d;x_I)}{\mbox{Longueur}(c_A,c_I)}, \\
x_{M_2}&amp;=&amp;x_I+\frac{r^2/x_A(x_A&#x2d;x_I)+r\sqrt{1&#x2d;r^2/x_A}(y_A&#x2d;y_I)}{\mbox{Longueur}(c_A,c_I)},\\
y_{M_2}&amp;=&amp;y_I+\frac{r^2/x_A(y_A&#x2d;y_I)&#x2d;r\sqrt{1&#x2d;r^2/x_A}(x_A&#x2d;x_I)}{\mbox{Longueur}(c_A,c_I)}
 \end{matrix} </annotation></semantics></math>
On écrit la fonction <span style="font-family:monospace">Tangent(C,cA)</span> qui renvoie une liste 
(éventuellement vide) contenant la ou les équations des tangentes au cercle 
<span style="font-family:monospace">C</span> passant par le point <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> de coordonnées <span style="font-family:monospace">cA</span>, en utilisant 
<span style="font-family:monospace">Milieu</span> (cf <a href="#sec%3AMilieu">6.1.2</a>), <span style="font-family:monospace">Longueur</span> (cf <a href="#sec%3ALongueur">6.1.1</a>), 
<span style="font-family:monospace">Droite</span>(cf <a href="#sec%3ADroite">6.2.1</a>) et <span style="font-family:monospace">Cercle</span> (cf <a href="#sec%3ACercle">6.6.3</a>).<br>
On tape :

</p><pre class="verbatim">fonction Tangent(C,cA)
 local cI,r,xI,yI,xA,yA,XM1,YM1,xM1,yM1,XM2,YM2,xM2,yM2,l;
 cI:=C[0];
 xI:=cI[0];
 yI:=cI[1];
 r:=C[1];
 l:=Longueur(cA,cI);
 xA:=cA[0];
 yA:=cA[1];
 si l &lt; r alors 
   print("A n'est pas a l'exterieur de C");
   retourne [];
 fsi;
 si l==r et yA==yI alors 
   retourne [x-xA=0]; 
 fsi;
 si l==r et (yA-yI)!=0 alors 
   retourne [normal(Droite([xA,yA],-(xA-xI)/(yA-yI)))];
 fsi;
 XM1:=r^2/l;
 YM1:=r*sqrt(1-r^2/l^2);
 xM1:=normal(xI+(XM1*(xA-xI)-YM1*(yA-yI))/l);
 yM1:=normal(yI+(XM1*(yA-yI)+YM1*(xA-xI))/l);
 XM2:=r^2/l;
 YM2:=-r*sqrt(1-r^2/l^2);
 xM2:=normal(xI+(XM2*(xA-xI)-YM2*(yA-yI))/l);
 yM2:=normal(yI+(XM2*(yA-yI)+YM2*(xA-xI))/l);
 retourne [Droite([xM1,yM1],[xA,yA]),Droite([xM2,yM2],[xA,yA])];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cI:=[0,1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[2,1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">r:=sqrt(2);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">C1:=Cercle(cI,r)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
 <br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">T1:=Tangent(C1,cA)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On fait la figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">I:=point(cI);A:=point(cA);c1:=cercle(I,r);droite(T1[0]);droite(T1[1])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">C2:=Cercle([1,2],2);T2:=Tangent(C2,[1+sqrt(2),2+sqrt(2)])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On fait la figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">J:=point(1,2);B:=point(1+sqrt(2),2+sqrt(2));c2:=cercle(J,2);droite(T2[0]);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On vérifie avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">equation(tangent(c1,A))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">equation(tangent(c2,B))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

On peut utiliser non seulement <span style="font-family:monospace">Milieu</span> (cf <a href="#sec%3AMilieu">6.1.2</a>), 
<span style="font-family:monospace">Longueur</span> (cf <a href="#sec%3ALongueur">6.1.1</a>), <span style="font-family:monospace">Droite</span>(cf <a href="#sec%3ADroite">6.2.1</a>) et 
<span style="font-family:monospace">Cercle</span> (cf <a href="#sec%3ACercle">6.6.3</a>), mais aussi le programme de changement de 
repère écrit précedemment <span style="font-family:monospace">ChangeXY2xy</span> (cf <a href="#sec%3AChangeXY2xy">6.5.3</a> :

</p><pre class="verbatim">fonction Tangentes(C,cA)
 local cI,r,xI,yI,xA,yA,XA,CM1,CM2,cM1,cM2,cU;
 cI,r:=C; 
 xI,yI:=cI;
 xA,yA:=cA;
 XA:=Longueur(cA,cI);
 cU:=[xA-xI,yA-yI]/XA;
 si XA &gt;r alors
   CM1:=[r^2/XA,r*sqrt(1-r^2/XA^2)];
   CM2:=[r^2/XA,-r*sqrt(1-r^2/XA^2)];
   cM1:=ChangeXY2xy(CM1,cI,cU);
   cM2:=ChangeXY2xy(CM2,cI,cU);
   retourne [Droite(cM1,[xA,yA]),Droite(cM2,[xA,yA])];
 fsi;
 si XA==r alors 
   CM1:=[r,1];
   cM1:=ChangeXY2xy(CM1,cI,cU);
   retourne [Droite(cM1,[xA,yA])];
 fsi
 retourne [];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cI:=[0,1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[2,1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">r:=sqrt(2);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">C:=Cercle(cI,r)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
 <br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Tangentes(C,cA)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Tangentes(Cercle([1,2],1),[1,3])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On vérfie avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">equation(tangent(cercle(point(cI),r),point(cA)))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">equation(tangent(cercle(point([1,2]),1),point([1,3])))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC subsection id="sec112" Solution analytique des tangentes à un cercle-->
<h3 id="sec112" class="subsection">6.6.7  Solution analytique des tangentes à un cercle</h3><!--SEC END --><p>
On peut aussi faire une résolution analytique pour construire la (ou les) 
tangente(s) à un cercle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> passant par un point <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math>.<br>
On pourra se servir des programmes écrits précédement : <span style="font-family:monospace">Longueur</span> 
(cf <a href="#sec%3ALongueur">6.1.1</a>), <span style="font-family:monospace">Droite</span>(cf <a href="#sec%3ADroite">6.2.1</a>), <span style="font-family:monospace">Cercle</span> 
(cf <a href="#sec%3ACercle">6.6.3</a>) et <span style="font-family:monospace">Solution12</span> (cf <a href="#sec%3ASolution12">4.2</a>).</p><p>On considère un repère orthonormé dans lequel le centre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi></mrow><annotation encoding='application/x-tex'>I</annotation></semantics></math> du cercle 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math> de rayon <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi></mrow><annotation encoding='application/x-tex'>r</annotation></semantics></math> a pour coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>I</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>I</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[x_I,y_I]</annotation></semantics></math>.<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math> a pour équation <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mo>&minus;</mo><msub><mi>x</mi> <mi>I</mi></msub><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>+</mo><mo stretchy="false">(</mo><mi>y</mi><mo>&minus;</mo><msub><mi>y</mi> <mi>I</mi></msub><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>=</mo><msup><mi>r</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>(x&#x2d;x_I)^2+(y&#x2d;y_I)^2=r^2</annotation></semantics></math> soit
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>y</mi> <mn>2</mn></msup><mo>&minus;</mo><mn>2</mn><msub><mi>x</mi> <mi>I</mi></msub><mi>x</mi><mo>&minus;</mo><mn>2</mn><msub><mi>y</mi> <mi>I</mi></msub><mi>y</mi><mo>+</mo><msubsup><mi>x</mi> <mi>I</mi> <mn>2</mn></msubsup><mo>+</mo><msubsup><mi>y</mi> <mi>I</mi> <mn>2</mn></msubsup><mo>&minus;</mo><msup><mi>r</mi> <mn>2</mn></msup><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>x^2+y^2&#x2d;2x_Ix&#x2d;2y_Iy+x_I^2+y_I^2&#x2d;r^2=0 </annotation></semantics></math>
Soit <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math> un point de coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>A</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'> [x_A,y_A]</annotation></semantics></math>.<br>
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math> se trouve à l’extérieur du cercle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math>, on peut mener par 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math>, deux tangentes. Les points de contact <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'> M_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>M</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'> M_2</annotation></semantics></math> de ces 
tangentes avec <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math> sont aussi les points d’intersection de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math> et du 
cercle de diamètre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>A</mi></mrow><annotation encoding='application/x-tex'> IA</annotation></semantics></math>.<br>
Le cercle de diamètre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>A</mi></mrow><annotation encoding='application/x-tex'> IA</annotation></semantics></math> a pour centre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>K</mi></mrow><annotation encoding='application/x-tex'> K</annotation></semantics></math> et rayon <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>R</mi></mrow><annotation encoding='application/x-tex'>R</annotation></semantics></math>
où <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>K</mi></mrow><annotation encoding='application/x-tex'>K</annotation></semantics></math> est le milieu de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>A</mi></mrow><annotation encoding='application/x-tex'> IA</annotation></semantics></math>
de coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><msub><mi>x</mi> <mi>K</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>K</mi></msub><mo stretchy="false">]</mo><mo>=</mo><msub><mi>c</mi> <mi>K</mi></msub></mrow><annotation encoding='application/x-tex'> [x_K,y_K]=c_K</annotation></semantics></math>=Milieu<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>c</mi><mi>I</mi><mo>,</mo><mi>c</mi><mi>A</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>(cI,cA)</annotation></semantics></math> et
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>R</mi><mo>=</mo></mrow><annotation encoding='application/x-tex'> R=</annotation></semantics></math>Longueur<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>c</mi><mi>I</mi><mo>,</mo><mi>c</mi><mi>A</mi><mo stretchy="false">)</mo><mo stretchy="false">/</mo><mn>2</mn></mrow><annotation encoding='application/x-tex'>(cI,cA)/2</annotation></semantics></math>.
Ce cercle a donc comme équation <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mo>&minus;</mo><msub><mi>x</mi> <mi>K</mi></msub><msup><mo stretchy="false">)</mo> <mo>+</mo></msup><mo stretchy="false">(</mo><mi>y</mi><mo>&minus;</mo><msub><mi>y</mi> <mi>K</mi></msub><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>=</mo><msup><mi>R</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>(x&#x2d;x_K)^+(y&#x2d;y_K)^2=R^2</annotation></semantics></math> i.e.<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>y</mi> <mn>2</mn></msup><mo>&minus;</mo><mn>2</mn><msub><mi>x</mi> <mi>K</mi></msub><mi>x</mi><mo>&minus;</mo><mn>2</mn><msub><mi>y</mi> <mi>K</mi></msub><mi>y</mi><mo>+</mo><msubsup><mi>x</mi> <mi>K</mi> <mn>2</mn></msubsup><mo>+</mo><msubsup><mi>y</mi> <mi>K</mi> <mn>2</mn></msubsup><mo>&minus;</mo><msup><mi>R</mi> <mn>2</mn></msup><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>x^2+y^2&#x2d;2x_Kx&#x2d;2y_Ky+x_K^2+y_K^2&#x2d;R^2=0 </annotation></semantics></math>
Il faut donc résoudre le système d’inconnues <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>,</mo><mi>y</mi></mrow><annotation encoding='application/x-tex'>x,y</annotation></semantics></math>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mrow><mtable displaystyle="false" rowspacing="0.5ex"><mtr><mtd><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>y</mi> <mn>2</mn></msup><mo>&minus;</mo><mn>2</mn><mi>x</mi><mi>I</mi><mi>x</mi><mo>&minus;</mo><mn>2</mn><mi>y</mi><mi>I</mi><mi>y</mi><mo>+</mo><mi>x</mi><msup><mi>I</mi> <mn>2</mn></msup><mo>+</mo><mi>y</mi><msup><mi>I</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>r</mi> <mn>2</mn></msup></mtd> <mtd><mo>=</mo></mtd> <mtd><mn>0</mn></mtd></mtr> <mtr><mtd><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>y</mi> <mn>2</mn></msup><mo>&minus;</mo><mn>2</mn><msub><mi>x</mi> <mi>K</mi></msub><mi>x</mi><mo>&minus;</mo><mn>2</mn><msub><mi>y</mi> <mi>K</mi></msub><mi>y</mi><mo>+</mo><msubsup><mi>x</mi> <mi>K</mi> <mn>2</mn></msubsup><mo>+</mo><msubsup><mi>y</mi> <mi>K</mi> <mn>2</mn></msubsup><mo>&minus;</mo><msup><mi>R</mi> <mn>2</mn></msup></mtd> <mtd><mo>=</mo></mtd> <mtd><mn>0</mn></mtd></mtr></mtable></mrow></mrow><annotation encoding='application/x-tex'> \begin{matrix}
x^2+y^2&#x2d;2xIx&#x2d;2yIy+xI^2+yI^2&#x2d;r^2&amp;=&amp;0\\
x^2+y^2&#x2d;2x_Kx&#x2d;2y_Ky+x_K^2+y_K^2&#x2d;R^2&amp;=&amp;0
 \end{matrix} </annotation></semantics></math>
qui est équivalent à :
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mrow><mtable displaystyle="false" rowspacing="0.5ex"><mtr><mtd><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>y</mi> <mn>2</mn></msup><mo>&minus;</mo><mn>2</mn><mi>x</mi><mi>I</mi><mi>x</mi><mo>&minus;</mo><mn>2</mn><mi>y</mi><mi>I</mi><mi>y</mi><mo>+</mo><mi>x</mi><msup><mi>I</mi> <mn>2</mn></msup><mo>+</mo><mi>y</mi><msup><mi>I</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>r</mi> <mn>2</mn></msup></mtd> <mtd><mo>=</mo></mtd> <mtd><mn>0</mn></mtd></mtr> <mtr><mtd><mn>2</mn><mo stretchy="false">(</mo><mi>x</mi><mi>I</mi><mo>&minus;</mo><msub><mi>x</mi> <mi>K</mi></msub><mo stretchy="false">)</mo><mi>x</mi><mo>+</mo><mn>2</mn><mo stretchy="false">(</mo><mi>y</mi><mi>I</mi><mo>&minus;</mo><msub><mi>y</mi> <mi>K</mi></msub><mo stretchy="false">)</mo><mi>y</mi><mo>+</mo><msubsup><mi>x</mi> <mi>K</mi> <mn>2</mn></msubsup><mo>+</mo><msubsup><mi>y</mi> <mi>K</mi> <mn>2</mn></msubsup><mo>+</mo><msup><mi>r</mi> <mn>2</mn></msup><mo>&minus;</mo><mi>x</mi><msup><mi>I</mi> <mn>2</mn></msup><mo>&minus;</mo><mi>y</mi><msup><mi>I</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>R</mi> <mn>2</mn></msup></mtd> <mtd><mo>=</mo></mtd> <mtd><mn>0</mn></mtd></mtr></mtable></mrow></mrow><annotation encoding='application/x-tex'> \begin{matrix}
x^2+y^2&#x2d;2xIx&#x2d;2yIy+xI^2+yI^2&#x2d;r^2&amp;=&amp;0 \\
2(xI&#x2d;x_K)x+2(yI&#x2d;y_K)y+x_K^2+y_K^2+r^2&#x2d;xI^2&#x2d;yI^2&#x2d;R^2&amp;=&amp;0
 \end{matrix} </annotation></semantics></math>
On a <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>2</mn><mo stretchy="false">(</mo><mi>x</mi><mi>I</mi><mo>&minus;</mo><msub><mi>x</mi> <mi>K</mi></msub><mo stretchy="false">)</mo><mo>=</mo><mo stretchy="false">(</mo><mi>x</mi><mi>I</mi><mo>&minus;</mo><msub><mi>x</mi> <mi>A</mi></msub><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>2(xI&#x2d;x_K)=(xI&#x2d;x_A)</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>2</mn><mo stretchy="false">(</mo><mi>y</mi><mi>I</mi><mo>&minus;</mo><msub><mi>y</mi> <mi>K</mi></msub><mo stretchy="false">)</mo><mo>=</mo><mo stretchy="false">(</mo><mi>y</mi><mi>I</mi><mo>&minus;</mo><msub><mi>y</mi> <mi>A</mi></msub><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>2(yI&#x2d;y_K)=(yI&#x2d;y_A)</annotation></semantics></math><br>
Or <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mo>&ne;</mo><mi>I</mi></mrow><annotation encoding='application/x-tex'> A\neq I</annotation></semantics></math> donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>x</mi> <mi>A</mi></msub><mo>&ne;</mo><msub><mi>x</mi> <mi>I</mi></msub><mo>&ne;</mo><msub><mi>x</mi> <mi>K</mi></msub></mrow><annotation encoding='application/x-tex'>x_A\neq x_I \neq x_K</annotation></semantics></math> ou <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>y</mi> <mi>A</mi></msub><mo>&ne;</mo><msub><mi>y</mi> <mi>I</mi></msub><mo>&ne;</mo><msub><mi>y</mi> <mi>K</mi></msub></mrow><annotation encoding='application/x-tex'>y_A \neq y_I \neq y_K</annotation></semantics></math>.
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>y</mi><mi>I</mi><mo>&minus;</mo><msub><mi>y</mi> <mi>K</mi></msub><mo stretchy="false">)</mo><mo>&ne;</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>(yI&#x2d;y_K) \neq 0</annotation></semantics></math> (resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mi>I</mi><mo>&minus;</mo><msub><mi>x</mi> <mi>A</mi></msub><mo stretchy="false">)</mo><mo>&ne;</mo></mrow><annotation encoding='application/x-tex'>(xI&#x2d;x_A) \neq </annotation></semantics></math>) alors on connaît <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi></mrow><annotation encoding='application/x-tex'>y</annotation></semantics></math> 
(resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math>) en fonction 
de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> (resp <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi></mrow><annotation encoding='application/x-tex'>y</annotation></semantics></math>) et il faut résoudre une équation 
de degré 2 en <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> (res <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi></mrow><annotation encoding='application/x-tex'>y</annotation></semantics></math>).<br>
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math> est sur le cercle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math>, on peut mener par 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math>, une tangente 
(c’est une droite passant par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math> et qui est perpendiculaire à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>I</mi><mi>A</mi></mrow><annotation encoding='application/x-tex'> IA</annotation></semantics></math>. <br>
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math> est à l’intérieur du cercle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math>, il n’y a pas de 
tangente passant par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'> A</annotation></semantics></math>.<br>
On utilise encore <span style="font-family:monospace">Longueur</span> (cf <a href="#sec%3ALongueur">6.1.1</a>), <span style="font-family:monospace">Droite</span>
(cf <a href="#sec%3ADroite">6.2.1</a>) et <span style="font-family:monospace">Cercle</span> (cf <a href="#sec%3ACercle">6.6.3</a>), mais aussi le 
programme <span style="font-family:monospace">Solution12</span> écrit précedemment (cf <a href="#sec%3ASolution12">4.2</a> :
On tape :

</p><pre class="verbatim">fonction Tangenteq(C,cA)
 local cI,r,l,xI,yI,xA,yA,xK,yK,Eq,xM,yM,xM1,yM1,xM2,yM2,R,m;
 cI:=C[0];
 xI:=cI[0];
 yI:=cI[1];
 r:=C[1];
 l:=Longueur(cA,cI);
 xA:=cA[0];
 yA:=cA[1];
 R:=l/2;
 si l &gt;r alors
  xK:=(xI+xA)/2;
  yK:=(yI+yA)/2;
  si (yI-yA)!=0 alors 
    yM:=(xK^2+yK^2+r^2-xI^2-yI^2-R^2+2*(xI-xK)*x)/(yA-yI);
    Eq:=x^2+yM^2-2xI*x-2yI*yM+xI^2+yI^2-r^2=0;
    [xM1,xM2]:=Solution12(Eq,x);
    yM1:=subst(yM,x=xM1);
    yM2:=subst(yM,x=xM2);
  sinon
    xM:=(xK^2+yK^2+r^2-xI^2-yI^2-R^2+2*(yI-yK)*y)/(xA-xI);
    Eq:=xM^2+y^2-2xI*xM-2yI*y+xI^2+yI^2-r^2=0;
    [yM1,yM2]:=Solution12(Eq,y)
    xM1:=subst(xM,y=yM1);
    xM2:=subst(xM,y=yM2);
  fsi;
 retourne [Droite(cA,[xM1,yM1]),Droite(cA,[xM2,yM2])];
 fsi;
 si l==r alors
   si (yI-yA)!=0 alors
     m:=normal(-(xA-xI)/(yA-yI));
     retourne [Droite([xA,yA],m)];
   sinon
     retourne [Droite([xA,yA],[xA,yA+1])];
   fsi;
 fsi;
 retourne [];
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cI:=[0,1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">cA:=[2,1]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">r:=sqrt(2);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">C:=Cercle(cI,r)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
 <br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Tangenteq(C,cA)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Tangenteq(Cercle([1,2],1),[1,3])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On vérifie avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">equation(tangent(cercle(point([0,1]),r),point(cA)))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">equation(tangent(cercle(point([1,2]),1),point([1,3])))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC chapter id="sec113" Quelques tests géométriques-->
<h1 id="sec113" class="chapter">Chapitre 7  Quelques tests géométriques</h1><!--SEC END -->
<!--TOC section id="sec114" Test d’alignement de 3 points-->
<h2 id="sec114" class="section">7.1  Test d’alignement de 3 points</h2><!--SEC END --><p>
Établir que trois points sont alignés ou non alignés.<br>
Si les 3 points sont confondus <span style="font-family:monospace">Estaligne(A,B,C)</span> renvoie 2 <br>
Si les 3 points sont alignés <span style="font-family:monospace">Estaligne(A,B,C)</span> renvoie 1<br>
Si les 3 points ne sont pas alignés <span style="font-family:monospace">Estaligne(A,B,C)</span> renvoie 0<br>
On tape :

</p><pre class="verbatim">fonction Estaligne(cA,cB,cC)
 local xA,yA,xB,yB,xC,yC;
 si cA==cB et cA==cC alors retourne 2; fsi;
 si cA==cB ou cA==cC alors retourne 1; fsi;
 xA:=cA[0];
 yA:=cA[1];
 xB:=cB[0];
 yB:=cB[1];
 xC:=cC[0];
 yC:=cC[1];
 si normal((xB-xA)*(yC-yA)-(xC-xA)*(yB-yA))==0 alors 
   retourne 1;
 fsi; 
 retourne 0;

ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Estaligne([1,2],[1,2],[1,2])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Estaligne([1,2],[3,6],[1,2])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Estaligne([1,2],[3,6],[-1,-2])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Estaligne([1,2],[1,6],[-1,-2])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On fait la figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">A:=point(1,2);B:=point(3,1);C:=point(3,6);D:=point(-1,-2);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On vérifie avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">est_aligne([1,2],[3,6],[-1,-2])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">est_aligne([1,2],[3,1],[-1,-2])
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

</p>
<!--TOC section id="sec115" Test de parallélisme de 2 droites-->
<h2 id="sec115" class="section">7.2  Test de parallélisme de 2 droites</h2><!--SEC END --><p>
Soient deux droites <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>D_1</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>D</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>D_2</annotation></semantics></math> d’équation :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>1</mn></msub><mi>x</mi><mo>+</mo><msub><mi>b</mi> <mn>1</mn></msub><mi>y</mi><mo>+</mo><msub><mi>c</mi> <mn>1</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>a_1x+b_1y+c_1=0</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>2</mn></msub><mi>x</mi><mo>+</mo><msub><mi>b</mi> <mn>2</mn></msub><mi>y</mi><mo>+</mo><msub><mi>c</mi> <mn>2</mn></msub><mo>=</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>a_2x+b_2y+c_2=0</annotation></semantics></math><br>
Ces 2 droites sont parallèles si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>a</mi> <mn>1</mn></msub><msub><mi>b</mi> <mn>2</mn></msub><mo>=</mo><msub><mi>a</mi> <mn>2</mn></msub><msub><mi>b</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>a_1b_2=a_2b_1</annotation></semantics></math>.<br>
On utilise la fonction <span style="font-family:monospace">Coeffsdroite</span> (cf <a href="#sec%3ACoeffsdroite">6.2.2</a> qui calcule
les coefficients <span style="font-family:monospace">a</span>, <span style="font-family:monospace">b</span> et <span style="font-family:monospace">c</span> de l’équation d’une droite 
<span style="font-family:monospace">ax+by+c=0</span> :
On tape :

</p><pre class="verbatim">fonction Estparallele(d1,d2)
 local a1,a2,b1,b2,d,c1,c2;
 a1,b1,c1:=Coeffsdroite(d1);
 a2,b2,c2:=Coeffsdroite(d2);
 d:=normal(a2*b1-b2*a1);
 si d==0 alors retourne 1; fsi;
 retourne 0;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">D1:=Droite(2*x-3*y=1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">D2:=Droite(-4*x+6*y=23)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Estparallele(D1,D2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">D3:=Droite(-5*x+15*y=16)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Estparallele(D1,D3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On fait la figure avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">d1:=droite(2*x-3*y=1);d2:=droite(-4*x+6*y=23);d3:=droite(-5*x+15*y=16)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On vérifie avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">est_parallele(d1,d2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">est_parallele(d1,d3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec116" Caractériser alignement et parallélisme par la colinéarité-->
<h2 id="sec116" class="section">7.3  Caractériser alignement et parallélisme par la colinéarité</h2><!--SEC END --><p> 
Trois points <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi></mrow><annotation encoding='application/x-tex'> B</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'> C</annotation></semantics></math> sont alignés si les vecteurs 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'> AB</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'> AC</annotation></semantics></math> sont colinéaires.<br>
Deux droites <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'> AB</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'> CD</annotation></semantics></math> sont parallèles si les vecteurs <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'> AB</annotation></semantics></math> et 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi><mi>D</mi></mrow><annotation encoding='application/x-tex'> CD</annotation></semantics></math> sont colinéaires.</p>
<!--TOC chapter id="sec117" Statistiques-->
<h1 id="sec117" class="chapter">Chapitre 8  Statistiques</h1><!--SEC END --><p> <a id="chap:stats"></a>
</p>
<!--TOC section id="sec118" Calcul de moyenne et écart-type-->
<h2 id="sec118" class="section">8.1  Calcul de moyenne et écart-type</h2><!--SEC END --><p>
<span style="font-weight:bold">Exercice :</span> Écrire une fonction prenant en argument la liste des 
données et renvoyant sa moyenne et son écart-type, au
moyen d’une boucle <code>pour</code> (sans utiliser <code>mean</code> ou <code>stddev</code> qui 
sont les commandes <span style="font-family:monospace">Xcas</span> pour moyenne et écart-type).

</p><pre class="verbatim">fonction Stats(L)
  local j,Lj,n,s,s2;
  n:=dim(L);
  s:=0; s2:=0;
  pour j de 0 jusque n-1 faire
    Lj := L[j];
    s := s+Lj 
    s2 := s2+Lj^2;
  fpour
  retourne s/n,sqrt(s2/n-(s/n)^2);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=[7,9,11,10,7,14,11];
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Stats(L);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On vérifie avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large"> mean(L); stddev(L);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Exercice :</span> Écrire une fonction prenant en argument la liste des 
données et renvoyant sa médiane.<br>
<span style="font-weight:bold">Indication :</span> Pour déterminer une médiane, il faut au préalable 
trier les données, ce qui est la partie difficile de l’algorithme, le reste
de l’algorithme est simple. Au niveau du lycée on peut
utiliser la commande <span style="font-family:monospace">Xcas</span> <code>sort</code> qui trie une liste par ordre 
croissant, puis on renvoie l’élément d’indice la taille de la liste/2.

</p><pre class="verbatim">fonction Median(L)
  local n;
  n:=dim(L);
  L:=sort(L);
  si irem(n,2)==1 alors 
    retourne L[(n-1)/2];
  sinon
    retourne (L[n/2-1]+ L[n/2])/2.;
  fsi;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L1:=[148,143,142,146,144,146,142,147,140];
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Median(L1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L2:=[143,142,146,144,146,142,147,140];
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Median(L2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On vérifie avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">median(L1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
<span style="font-weight:bold">Exercice :</span> Écrire une fonction qui calcule la moyenne et l’écart-type 
et qui a comme argument soit la liste alternant valeur et effectif soit 
2 listes.

</p><pre class="verbatim">fonction Statexo1(L)
  local j,lj,n,n1,s,s2,vj,ej;
  n:=dim(L);
  si type(n)!=vecteur alors retourne "erreur"; fsi;
  s:=0; 
  s2:=0;
  n1:=n[0];
  n:=sum(col(L,1));
  pour j de 0 jusque n1-1 faire
    lj := L[j];
    vj := lj[0];
    ej := lj[1];
    s := s+vj*ej 
    s2 := s2+vj^2*ej;
  fpour;
  retourne s/n,sqrt(s2/n-(s/n)^2);
ffonction:;
fonction Statexo2(L1,L2)
  local j,vj,ej,n,n1,n2,s,s2;
  n1:=dim(L1);
  n2:=dim(L2);
  si n1!=n2 alors retourne "erreur"; fsi;
  n:=sum(L2);
  s:=0; 
  s2:=0;
  pour j de 0 jusque n1-1 faire
    vj := L1[j];
    ej := L2[j];
    s := s+vj*ej 
    s2 := s2+vj^2*ej;
  fpour;
  retourne s/n,sqrt(s2/n-(s/n)^2);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


On a mesuré la taille en cm (arrondie à l’entier le plus proche) de 200 
fossiles de la même espèce. On a obtenu pour <span style="font-family:monospace">k=0..12</span> une taille 
<span style="font-family:monospace">L1[k]</span> d’effectif de <span style="font-family:monospace">L2[k]</span>.<br>
Calculer la moyenne et l’écart-type de cette distribution.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L1:=[0,1,2,3,4,5,6,7,8,9,10,11,12]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L2:=[1,16,31,37,41,30,23,13,6,1,0,1,0]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L12:=seq([L1[k],L2[k]],k,0,12)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Statexo1(L12)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On a mesuré la taille en cm (arrondie à l’entier le plus proche) d’une autre
espèce de fossiles. On a obtenu pour <span style="font-family:monospace">k=0..12</span> une taille 
<span style="font-family:monospace">L1[k]</span> d’effectif de <span style="font-family:monospace">L3[k]</span>.<br>
Calculer la moyenne et l’écart-type de cette distribution.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L1:=[0,1,2,3,4,5,6,7,8,9,10,11,12]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L3:=[2,11,21,52,64,77,62,46,41,11,8,5,0]
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Statexo2(L1,L3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On vérifie avec <span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">mean(L1,L2),stddev(L1,L2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">mean(L1,L3),stddev(L1,L3)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec119" Simulation d’un échantillon-->
<h2 id="sec119" class="section">8.2  Simulation d’un échantillon</h2><!--SEC END --><p><a id="sec:Simu"></a>
<span style="font-weight:bold">Exercice :</span> Générer aléatoirement <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> valeurs 0 ou 1,
la probabilité d’avoir 1 étant fixée à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>p</mi></mrow><annotation encoding='application/x-tex'>p</annotation></semantics></math>
(pour faire cela, on comparera avec <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>p</mi></mrow><annotation encoding='application/x-tex'>p</annotation></semantics></math> le résultat de la commande <span style="font-family:monospace">Xcas</span>
<code>alea(0,1)</code> qui renvoie un réel entre 0 et 1). 
Calculer la fréquence de 1 observée.

</p><pre class="verbatim">fonction Simu(n,p)
  local j,a,n1;
  n1:=0;
  pour j de 1 jusque n faire
    a:=alea(0,1);
    si a&lt;=p alors n1:=n1+1; fsi;
  fpour
  retourne n1/n;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=seq(Simu(20.,.4),k,1,10);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On peut visualiser les fréquences obtenues avec la commande 
<span style="font-family:monospace">plotlist([y0,...,yn])</span> de <span style="font-family:monospace">Xcas</span> qui trace la ligne polygonale reliant 
les points d’abscisse <span style="font-family:monospace">k</span> et d’ordonnée <span style="font-family:monospace">yk</span> pour <span style="font-family:monospace">k=0..n</span>.<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">plotlist(L);droite(y=0.4-1/sqrt(20)); droite(y=0.4+1/sqrt(20))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>Commandes <span style="font-family:monospace">Xcas</span> permettant de faire le calcul directement :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">n:=20.; p:=.4; v:=randvector(n,binomial,1,p); sum(v)/n;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
La commande <code>randvector</code> génère ici <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> valeurs aléatoires
selon la loi binomiale de paramètres 1 et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>p</mi></mrow><annotation encoding='application/x-tex'>p</annotation></semantics></math>, on en fait ensuite
la moyenne. On peut bien sur utiliser d’autres lois que la loi binomiale,
par exemple la loi uniforme (<code>uniform</code>), la loi normale
(<code>normald</code>), la loi exponentielle (<code>exponential</code>), ...</p>
<!--TOC section id="sec120" Intervalle de fluctuation-->
<h2 id="sec120" class="section">8.3  Intervalle de fluctuation</h2><!--SEC END --><p>
Écrire un algorithme effectuant <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi></mrow><annotation encoding='application/x-tex'>N</annotation></semantics></math> simulations d’échantillons,
en utilisant la fonction précédente, renvoyer la liste
des fréquences ainsi que la proportion
de fréquences situées en-dehors de l’intervalle 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mi>p</mi><mo>&minus;</mo><mn>1</mn><mo stretchy="false">/</mo><msqrt><mi>n</mi></msqrt><mo>,</mo><mi>p</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><msqrt><mi>n</mi></msqrt><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[p&#x2d;1/\sqrt{n},p+1/\sqrt{n}]</annotation></semantics></math>.</p><p>Rappelons qu’on s’intéresse à cet intervalle, 
parce qu’une simulation suit une loi binomiale de moyenne <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi><mi>p</mi></mrow><annotation encoding='application/x-tex'>np</annotation></semantics></math> et 
d’écart-type <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&sigma;</mi><mo>=</mo><msqrt><mrow><mi>n</mi><mi>p</mi><mo stretchy="false">(</mo><mn>1</mn><mo>&minus;</mo><mi>p</mi><mo stretchy="false">)</mo></mrow></msqrt></mrow><annotation encoding='application/x-tex'>\sigma=\sqrt{n p (1&#x2d;p)}</annotation></semantics></math> donc 
les fréquences suivent une loi binomiale de moyenne <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>p</mi></mrow><annotation encoding='application/x-tex'>p</annotation></semantics></math> et 
d’écart-type <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mover><mi>&sigma;</mi><mo stretchy="false">&tilde;</mo></mover><mo>=</mo><mi>&sigma;</mi><mo stretchy="false">/</mo><mi>n</mi><mo>=</mo><msqrt><mrow><mi>p</mi><mo stretchy="false">(</mo><mn>1</mn><mo>&minus;</mo><mi>p</mi><mo stretchy="false">)</mo><mo stretchy="false">/</mo><mi>n</mi></mrow></msqrt></mrow><annotation encoding='application/x-tex'>\tilde{\sigma}=\sigma/n=\sqrt{p (1&#x2d;p)/n}</annotation></semantics></math>. Or
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mn>4</mn><mi>p</mi><mo stretchy="false">(</mo><mn>1</mn><mo>&minus;</mo><mi>p</mi><mo stretchy="false">)</mo><mo>=</mo><mn>1</mn><mo>&minus;</mo><mo stretchy="false">(</mo><mn>2</mn><mo>*</mo><mi>p</mi><mo>&minus;</mo><mn>1</mn><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>&Rightarrow;</mo><mn>4</mn><mi>p</mi><mo stretchy="false">(</mo><mn>1</mn><mo>&minus;</mo><mi>p</mi><mo stretchy="false">)</mo><mo>&leq;</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>4p(1&#x2d;p)=1&#x2d;(2*p&#x2d;1)^2 \Rightarrow 4p(1&#x2d;p)\leq 1 </annotation></semantics></math> 
donc
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mn>2</mn><mover><mi>&sigma;</mi><mo stretchy="false">&tilde;</mo></mover><mo>=</mo><mn>2</mn><mfrac><mi>&sigma;</mi><mi>n</mi></mfrac><mo>=</mo><msqrt><mfrac><mrow><mn>4</mn><mi>p</mi><mo stretchy="false">(</mo><mn>1</mn><mo>&minus;</mo><mi>p</mi><mo stretchy="false">)</mo></mrow><mi>n</mi></mfrac></msqrt><mo>&leq;</mo><mfrac><mn>1</mn><msqrt><mi>n</mi></msqrt></mfrac></mrow><annotation encoding='application/x-tex'>2\tilde{\sigma}=2\frac{\sigma}{n}=
\sqrt{\frac{4p(1&#x2d;p)}{n}} \leq \frac{1}{\sqrt{n}} </annotation></semantics></math>
Pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> grand, la loi binomiale s’approche d’une loi normale
ayant cet écart type.</p><p>On utilise la fonction <span style="font-family:monospace">Simu</span> écrite précédemment 
(cf <a href="#sec%3ASimu">8.2</a>).

</p><pre class="verbatim">fonction Fluctuat(N,n,p)
  local j,L,out;
  L:=[];
  out:=0;
  pour j de 0 jusque N-1 faire
    L[j]:=Simu(n,p);
    si abs(L[j]-p)&gt;1/sqrt(n) alors out:=out+1; fsi;
  fpour;
  retourne out/N,L;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


On lance 20 fois une pièce de de monnaie mal équilibrée, la 
probabilité d’obtenir face étant égale à 0.4.<br>
<span style="font-family:monospace">Simu(20,0.4)</span> renvoie donc la fréquence du nombre de faces observées.
On effectue plusieurs fois 100 simulations :

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">L:=Fluctuat(100.,20,.4);L1:=L[1]:;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">LL:=Fluctuat(100.,20,.4);LL1:=LL[1]:;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">LLL:=Fluctuat(100.,20,.4);LLL1:=LLL[1]:;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On peut visualiser la répartition de ces fréquences :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">gl_y=0..1;purge(x,y);
plotlist(L1,affichage=vert);
plotlist(LL1,affichage=rouge);
plotlist(LLL1,affichage=bleu);
droite(y=0.4-1/sqrt(20)); 
droite(y=0.4+1/sqrt(20))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-weight:bold">Avec les commandes de </span><span style="font-weight:bold"><span style="font-family:monospace">Xcas</span></span><br>
On génère une séquence de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi></mrow><annotation encoding='application/x-tex'>N</annotation></semantics></math> moyennes de vecteurs de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math>
valeurs aléatoires selon la loi binomiale de paramètres 1 et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>p</mi></mrow><annotation encoding='application/x-tex'>p</annotation></semantics></math> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">N:=100.; n:=20; p:=.4;l:=seq(sum(randvector(n,binomial,1,p))/n,j,1,N);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On compte les moyennes dont l’écart à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>p</mi></mrow><annotation encoding='application/x-tex'>p</annotation></semantics></math> est plus grand que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>1</mn><mo stretchy="false">/</mo><msqrt><mi>n</mi></msqrt></mrow><annotation encoding='application/x-tex'>1/\sqrt{n}</annotation></semantics></math> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">count(x->abs(x-p)>1/sqrt(n),l)/N;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>
On peut accélérer le calcul en utilisant le générateur
aléatoire selon la loi binomiale
de paramètres <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>p</mi></mrow><annotation encoding='application/x-tex'>p</annotation></semantics></math>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">N:=100.; n:=20; p:=.4;l:=randvector(N,binomial,n,p)/n;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">count(x->abs(x-p)>1/sqrt(n),l)/N;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>On peut enfin tracer le graphe de l’évolution de la 
proportion de fréquences en-dehors
de l’intervalle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mi>p</mi><mo>&minus;</mo><mn>1</mn><mo stretchy="false">/</mo><msqrt><mi>n</mi></msqrt><mo>,</mo><mi>p</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><msqrt><mi>n</mi></msqrt><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[p&#x2d;1/\sqrt{n},p+1/\sqrt{n}]</annotation></semantics></math> lorsque <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi></mrow><annotation encoding='application/x-tex'>N</annotation></semantics></math> augmente.
On génère une liste de fréquences :

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">N:=10000.; n:=20; p:=.4;l:=randvector(N,binomial,n,p)/n:;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

puis on compte les fréquences en-dehors de l’intervalle et on
stocke les fréquences dans une liste

</p><pre class="verbatim">L:=[]; compteur:=0; a:=p-1/sqrt(n); b:=p+1/sqrt(n);
pour j de 0 jusque N-1 faire 
  si l[j]&lt;a ou l[j]&gt;b alors compteur++; fsi;
  L[j]:=compteur/(j+1);
fpour;
gl_y=0..0.1;plotlist(L)
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


On a utilisé ici la fonction d’incrémentation, <span style="font-family:monospace">compteur++</span> est
équivalent à <span style="font-family:monospace">compteur=compteur+1</span>.</p><p>La probabilité théorique d’être dans l’intervalle 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mi>p</mi><mo>&minus;</mo><mn>1</mn><mo stretchy="false">/</mo><msqrt><mi>n</mi></msqrt><mo>,</mo><mi>p</mi><mo>+</mo><mn>1</mn><mo stretchy="false">/</mo><msqrt><mi>n</mi></msqrt><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[p&#x2d;1/\sqrt{n},p+1/\sqrt{n}]</annotation></semantics></math> est donnée par la commande
<span style="font-family:monospace">Xcas</span> :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">binomial_cdf(n,p,n*(p-1/sqrt(n)),n*(p+1/sqrt(n)))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Il y a donc une probabilité faible (de l’ordre de 4%) 
de ne pas être dans l’intervalle de fluctuation.<br>
La probabilité d’être dans l’intervalle plus précis
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mi>n</mi><mi>p</mi><mo>&minus;</mo><mi>&sigma;</mi><mo stretchy="false">/</mo><msqrt><mi>n</mi></msqrt><mo>,</mo><mi>n</mi><mi>p</mi><mo>+</mo><mi>&sigma;</mi><mo stretchy="false">/</mo><msqrt><mi>n</mi></msqrt><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[np&#x2d;\sigma/\sqrt{n},np+\sigma/\sqrt{n}]</annotation></semantics></math> est donnée par :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">sigma:=stddev(binomial(n,p));
binomial_cdf(n,p,n*p-2*sigma,n*p+2*sigma)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Elle est ici identique parce que les bornes de l’intervalle ont la même 
partie entière.</p>
<!--TOC section id="sec121" Évolution d’une fréquence.-->
<h2 id="sec121" class="section">8.4  Évolution d’une fréquence.</h2><!--SEC END --><p>
On illustre l’évolution d’une fréquence vers sa moyenne théorique
(espérance).</p><p>Expérience : on tire un dé à 6 faces, si le résultat est 1 on
renvoie 1, si c’est 2 à 4 on renvoie 2, si c’est 5 ou 6 on renvoie 4.
Simulation, en utilisant la fonction <code>piecewise</code> : 

</p><pre class="verbatim">fonction experience()
  local a;
  a:=alea(6)+1; // simule un de 6
  return piecewise(a&lt;2,1,a&lt;5,2,4);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>

</p><p>On effectue <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi></mrow><annotation encoding='application/x-tex'>N</annotation></semantics></math> expériences et on regarde l’évolution de la moyenne
des résultats.

</p><pre class="verbatim">fonction evolutionmoyenne1(N)
  local l,s,j,a;
  l:=[];
  s:=0;
  pour j de 1 jusque N faire
    s:=s+experience();
    l:=append(l,s/j);
  fpour;
  return l;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">purge(x,y);droite(y=2.5,couleur=rouge);
gl_y=0..4;plotlist(evolutionmoyenne1(1000))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Dans la version HTML interactive, 
cliquez plusieurs fois sur le bouton ok pour voir différents 
comportements.</p><p>On peut écrire une fonction plus générale en passant 
la fonction <code>experience</code> en argument

</p><pre class="verbatim">fonction evolutionmoyenne(experience,N)
  local l,s,j,a;
  l:=[];
  s:=0;
  pour j de 1 jusque N faire
    s:=s+experience();
    l:=append(l,s/j);
  fpour;
  return l;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>

</p>
<!--TOC section id="sec122" Triangles de spaghettis-->
<h2 id="sec122" class="section">8.5  Triangles de spaghettis</h2><!--SEC END --><p><a id="hevea_default125"></a>
On prend un spaghetti qu’on casse en 3 morceaux, peut-on construire
un triangle avec ces 3 morceaux ?
On fixe l’unité de longueur au spaghetti entier. On a donc
3 longueurs <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi><mo>=</mo><mn>1</mn><mo>&minus;</mo><mi>a</mi><mo>&minus;</mo><mi>b</mi></mrow><annotation encoding='application/x-tex'>c=1&#x2d;a&#x2d;b</annotation></semantics></math> et il faut vérifier
les inégalités triangulaires <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mi>&lt;</mi><mi>b</mi><mo>+</mo><mi>c</mi><mo>,</mo><mi>b</mi><mi>&lt;</mi><mi>a</mi><mo>+</mo><mi>c</mi><mo>,</mo><mi>c</mi><mi>&lt;</mi><mi>a</mi><mo>+</mo><mi>b</mi></mrow><annotation encoding='application/x-tex'>a&amp;lt;b+c, b&amp;lt;a+c, c&amp;lt;a+b</annotation></semantics></math> (voir
la section <a href="#sec%3Atrisolv">9.4</a>).</p><p>Première méthode de coupe : on tire au hasard <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi></mrow><annotation encoding='application/x-tex'>y</annotation></semantics></math> entre 0 et 1.
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mi>&lt;</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'>x&amp;lt;y</annotation></semantics></math>, on pose <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>=</mo><mi>x</mi><mo>,</mo><mi>b</mi><mo>=</mo><mi>y</mi><mo>&minus;</mo><mi>x</mi></mrow><annotation encoding='application/x-tex'>a=x, b=y&#x2d;x</annotation></semantics></math> (et donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi><mo>=</mo><mn>1</mn><mo>&minus;</mo><mi>y</mi></mrow><annotation encoding='application/x-tex'>c=1&#x2d;y</annotation></semantics></math>) sinon on échange <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi></mrow><annotation encoding='application/x-tex'>y</annotation></semantics></math>
(<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>=</mo><mi>y</mi></mrow><annotation encoding='application/x-tex'>a=y</annotation></semantics></math>, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi><mo>=</mo><mi>x</mi><mo>&minus;</mo><mi>y</mi></mrow><annotation encoding='application/x-tex'>b=x&#x2d;y</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi><mo>=</mo><mn>1</mn><mo>&minus;</mo><mi>x</mi></mrow><annotation encoding='application/x-tex'>c=1&#x2d;x</annotation></semantics></math>).
Simulation, <code>correct</code> vérifie l’inégalité triangulaire,
<code>spag1</code> renvoie 1 si on peut faire un triangle et 0 sinon :

</p><pre class="verbatim">correct(a,b,c):=a&lt;b+c et b&lt;a+c et c&lt;a+b:;

fonction spag1()
  local x,y,c;
  x:=alea(0,1);
  y:=alea(0,1);
  si y&gt;x alors 
    return correct(x,y-x,1-y); 
  sinon 
    return correct(y,x-y,1-x); 
  fsi;
ffonction:;

fonction spagn(n)
  local L,s;
  L:=[]; // liste des frequences de succes
  s:=0; // nombre de succes
  pour j de 1 jusque n faire
    si spag1() alors s++ fsi; 
    L:=append(L,s/j); 
  fpour;
  return L;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">gl_y=0..1;plotlist(spagn(5000))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

<span style="font-weight:bold">Exercice :</span> modifier <code>spag1</code> pour
couper le spaghetti en prenant au hasard, puis en coupant le
morceau le plus long au hasard.

</p><pre class="verbatim">fonction spag1()
  local x,y,c;
  x:=alea(0,1);
  si x&gt;1/2 alors
    y:=x; // on casse x
    x:=x*alea(0,1); 
  sinon // on casse 1-x
    y:=x+(1-x)*alea(0,1);
  fsi;
  return correct(x,y-x,1-y); 
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


Voir l’étude à la fin du manuel Algorithmes
et simulation de <span style="font-family:monospace">Xcas</span>.</p>
<!--TOC section id="sec123" Les aiguilles de Buffon-->
<h2 id="sec123" class="section">8.6  Les aiguilles de Buffon</h2><!--SEC END --><p><a id="sec:buffon"></a><a id="hevea_default126"></a>
Le naturaliste Buffon, en 1777 a posé le problème de l’aiguille en ces 
termes : "Je suppose que dans une chambre, dont le parquet est simplement 
divisé par des joints parallèles, on jette en l’air une baguette et que 
l’un des joueurs parie que la baguette ne croisera aucune des parallèles du
parquet..."</p><p>On peut modéliser le problème en supposant 
que la distance entre les paralléles est de 1, 
et que les parallèles sont horizontales,
d’équations <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi><mo>=</mo><mi>k</mi><mo>,</mo><mi>k</mi><mo>&Element;</mo><mi>&Zopf;</mi></mrow><annotation encoding='application/x-tex'>y=k, k \in \mathbb{Z}</annotation></semantics></math>.
On suppose que la longueur de l’aiguille est <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>l</mi></mrow><annotation encoding='application/x-tex'>l</annotation></semantics></math>. Lorsqu’elle tombe sur 
le parquet, on suppose qu’une de ses extrémités est en <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>(x,y)</annotation></semantics></math> 
et qu’elle fait un angle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&theta;</mi></mrow><annotation encoding='application/x-tex'>\theta</annotation></semantics></math> avec l’horizontale, son autre
extrémité est donc en <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mo>+</mo><mi>l</mi><mi>cos</mi><mo stretchy="false">(</mo><mi>&theta;</mi><mo stretchy="false">)</mo><mo>,</mo><mi>y</mi><mo>+</mo><mi>l</mi><mi>sin</mi><mo stretchy="false">(</mo><mi>&theta;</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>(x+l\cos(\theta),y+l\sin(\theta))</annotation></semantics></math>. Elle
coupe une des parallèle si l’intervalle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mi>y</mi><mo>,</mo><mi>y</mi><mo>+</mo><mi>l</mi><mi>sin</mi><mo stretchy="false">(</mo><mi>&theta;</mi><mo stretchy="false">)</mo><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[y,y+l\sin(\theta)]</annotation></semantics></math> contient
un entier c’est-à-dire si la partie entière de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi></mrow><annotation encoding='application/x-tex'>y</annotation></semantics></math> diffère 
de celle de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi><mo>+</mo><mi>l</mi><mi>sin</mi><mo stretchy="false">(</mo><mi>&theta;</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>y+l\sin(\theta)</annotation></semantics></math>. 
On observe que la valeur de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> n’a pas d’importance, et que
la valeur de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi></mrow><annotation encoding='application/x-tex'>y</annotation></semantics></math> modulo 1 non plus. 
Pour effectuer la simulation, on suppose donc que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi></mrow><annotation encoding='application/x-tex'>y</annotation></semantics></math> est un réel
aléatoire selon la loi uniforme entre 0 et 1, et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&theta;</mi></mrow><annotation encoding='application/x-tex'>\theta</annotation></semantics></math> un réel
aléatoire selon la loi uniforme entre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mfrac><mi>&pi;</mi><mn>2</mn></mfrac></mrow><annotation encoding='application/x-tex'>&#x2d;\frac{\pi}{2}</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mfrac><mi>&pi;</mi><mn>2</mn></mfrac></mrow><annotation encoding='application/x-tex'>\frac{\pi}{2}</annotation></semantics></math>

</p><pre class="verbatim">fonction buffonpi(l)
  local y,theta;
  y:=alea(0,1);
  theta:=alea(-.5,.5)*pi;
  si floor(y+l*sin(theta))!=0 alors return 1; sinon return 0; fsi;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


Tests pour quelques valeurs de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>l</mi></mrow><annotation encoding='application/x-tex'>l</annotation></semantics></math>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">experience():=buffonpi(0.7);
gl_y=0..1;plotlist(evolutionmoyenne(experience,1000))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">experience():=buffonpi(1);
gl_y=0..1;plotlist(evolutionmoyenne(experience,1000))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">experience():=buffonpi(2.5);
gl_y=0..1;plotlist(evolutionmoyenne(experience,1000))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>On peut aussi générer la direction aléatoire <span style="font-weight:bold">sans utiliser le
nombre </span><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&pi;</mi></mrow><annotation encoding='application/x-tex'>\pi</annotation></semantics></math> en tirant au hasard deux réels entre 0 et 1 et si le point 
obtenu est dans le disque unité, on prend la direction obtenue.

</p><pre class="verbatim">fonction buffonsanspi(l)
  local y,X,Y;
  y:=alea(0,1); 
  repeter X:=alea(0,1); Y:=alea(0,1) jusqua X*X+Y*Y&lt;=1;
  si floor(y+l*Y/sqrt(X^2+Y^2))!=0 alors return 1; sinon return 0; fsi;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">experience():=buffonsanspi(0.7);
gl_y=0..1;plotlist(evolutionmoyenne(experience,1000))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>On peut enfin définir algébriquement 

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">buffon(l):=floor(alea(0,1)+l*sin(pi*alea(-.5,.5)))!=0;
experience():=buffon(0.7);
gl_y=0..1;plotlist(evolutionmoyenne(experience,1000))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>Pour conjecturer le comportement de la probabilité en fonction de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>l</mi></mrow><annotation encoding='application/x-tex'>l</annotation></semantics></math>
on va l’estimer par la fréquence observée au bout de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi></mrow><annotation encoding='application/x-tex'>N</annotation></semantics></math>
d’expériences, par exemple on prendra <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi><mo>=</mo><mn>1000</mn></mrow><annotation encoding='application/x-tex'>N=1000</annotation></semantics></math> (pour éviter
un temps d’exécution trop long)

</p><pre class="verbatim">fonction probabuffon(l,N)
  local s,j;
  s:=0;
  pour j de 1 jusque N faire
    s := s+buffonpi(l);
  fpour;
  return s/N;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">plot('probabuffon(l,1000)',l=0..2,xstep=0.04)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>l</mi></mrow><annotation encoding='application/x-tex'>l</annotation></semantics></math> petit, le comportement est linéaire, pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>l</mi></mrow><annotation encoding='application/x-tex'>l</annotation></semantics></math> grand
on observe une asymptote horizontale (qui est <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>y=1</annotation></semantics></math> car lorsque
la taille <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>l</mi></mrow><annotation encoding='application/x-tex'>l</annotation></semantics></math> de l’aiguille est de plus en plus grande,
la probabilité de ne pas couper une horizontale tend vers 0
puisque la direction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&theta;</mi></mrow><annotation encoding='application/x-tex'>\theta</annotation></semantics></math> doit être de plus en plus proche). 
On peut démontrer que
le coefficient de proportionnalité pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>l</mi></mrow><annotation encoding='application/x-tex'>l</annotation></semantics></math> petit vaut <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mfrac><mn>2</mn><mi>&pi;</mi></mfrac></mrow><annotation encoding='application/x-tex'>\frac{2}{\pi}</annotation></semantics></math>,
(cf. le manuel Exercices de <span style="font-family:monospace">Xcas</span> pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>l</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding='application/x-tex'>l=1</annotation></semantics></math>).</p><p>Pour obtenir un tracé plus précis sans attendre trop longtemps,
il faut trouver une astuce pour accélérer le calcul dans
<code>probabuffon</code>.
Pour cela on part de la version algébrique de <code>buffon</code> qui
se prête au calcul appliqué en parallèle à une liste
(<code>sin</code> appliqué à une liste renvoie la liste des sinus
des éléments de la liste, <code>+</code> effectue la somme composante
par composante, etc.).
On doit renvoyer 0 si 
le nombre de parallèles traversées
est nul et 1 sinon, donc si on fait <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi></mrow><annotation encoding='application/x-tex'>N</annotation></semantics></math> expériences,
la proportion est donnée par :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Buffon(l,N):=1-count_eq(0,floor(randvector(N,uniformd,0,1)+l*sin(pi*randvector(N,uniformd,-.5,.5))))/N;
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On peut maintenant tracer le graphe de manière plus précise,
par exemple avec <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi><mo>=</mo><mn>5000</mn></mrow><annotation encoding='application/x-tex'>N=5000</annotation></semantics></math> et un pas de 0.03 sur <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mn>0</mn><mo>,</mo><mn>3</mn><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[0,3]</annotation></semantics></math>, sans patienter
trop longtemps :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">seq(point(l,Buffon(l,5000)),l,0,3,0.03)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Ce type d’optimisation est fréquent dans les langages interprétés,
on essaie d’utiliser les commandes natives du logiciel pour effectuer
les boucles les plus internes au lieu de les faire exécuter par
l’interpréteur, forcément plus lent que les commandes natives qui
sont compilées.</p>
<!--TOC section id="sec124" Marche aléatoire à 1 dimension.-->
<h2 id="sec124" class="section">8.7  Marche aléatoire à 1 dimension.</h2><!--SEC END --><p><a id="hevea_default127"></a>
Un marcheur ivre se déplace sur un trottoir, en faisant
un pas aléatoirement vers la droite ou vers la gauche.
On simule sa position après <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> pas (on suppose qu’il part de l’origine).

</p><pre class="verbatim">fonction marche(n)
  local j,x;
  x:=0;
  pour j de 1 jusque n faire
    si alea(2)==1 alors x++; sinon x--; fsi;
  fpour;
  return x;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


On effectue <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi></mrow><annotation encoding='application/x-tex'>N</annotation></semantics></math> marches aléatoires et on trace l’histogramme des
positions, par exemple pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi><mo>=</mo><mn>100</mn></mrow><annotation encoding='application/x-tex'>n=100</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi><mo>=</mo><mn>3000</mn></mrow><annotation encoding='application/x-tex'>N=3000</annotation></semantics></math><br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">histogram(seq(marche(100),3000),-50,2)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On peut aussi s’intéresser au nombre de passage par l’origine.

</p><pre class="verbatim">fonction retour(n)
  local j,x,r;
  x:=0; r:=0;
  pour j de 1 jusque n faire
    si alea(2)==1 alors x++; sinon x--; fsi;
    si x==0 alors r++; fsi;
  fpour;
  return r;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


et conjecturer son espérance par observation d’un nombre important
de marches<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">experience():=retour(100);
plotlist(evolutionmoyenne(experience,3000))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

On peut aussi observer l’espérance en fonction du nombre de pas.
Pour cela, on approche l’espérance par exemple par la moyenne de
1000 nombre de retours.

</p><pre class="verbatim">fonction moyenneretour1(n)
  local s,j;
  s:=0;
  pour j de 1 jusque 1000 faire
    s := s+retour(n);
  fpour;
  return s/1000;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">plot('moyenneretour1(n)',n=20..200,xstep=20)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>Comme pour les aiguilles de Buffon, le temps de calcul est long (c’est
pour cela que l’on a mis un pas de 20 dans la commande précédente),
mais il est possible d’accélérer en faisant plusieurs optimisations :
</p><ul class="itemize"><li class="li-itemize">
au lieu de décaler de 1 ou -1, on peut décaler de 1 ou 0
en décidant que l’origine se décale elle-même de 1/2.
</li><li class="li-itemize">le passage par l’origine ne peut s’effecteur qu’après un nombre
pair de pas, on peut donc faire 2 pas à la fois avant
de tester. À chaque itération, on fait 
donc deux pas de valeur 1 ou 0 et l’origine
est décalée de 1.
</li><li class="li-itemize">on remplace les boucles les plus internes
par du calcul sur des listes.
</li></ul><pre class="verbatim">fonction moyenneretour(N,n) // N experiences, marche de n
  local k,pos,r;
  pos:=seq(0,N); // N marcheurs a l'origine
  r:=0;
  n:=iquo(n,2);
  pour k de 1 jusque n faire
    pos:=pos+randvector(N,2)+randvector(N,2); 
    r:=r+count_eq(k,pos); // nombre de passage origine translatee
  fpour;
  retourne r/N;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


On peut maintenant faire le tracé avec une bonne précision en
quelques secondes :<br>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">seq(point(n,moyenneretour(2000,n)),n,1,200)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec125" Les urnes de Polya-->
<h2 id="sec125" class="section">8.8  Les urnes de Polya</h2><!--SEC END --><p><a id="hevea_default128"></a>
On place dans une urne <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi></mrow><annotation encoding='application/x-tex'>r</annotation></semantics></math> boules rouges et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> boules bleues, indiscernables
au toucher.
On tire une boule, on note sa couleur, et on remet dans l’urne cette boule 
ainsi qu’une boule de même couleur (le nombre total de boules
augmente donc de 1). On recommence, on effectue en tout <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> tirages.</p><p>On fait une simulation, on va renvoyer 
la liste des proportions de boules rouges
dans l’urne au cours de l’expérience.
Il y a <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi></mrow><annotation encoding='application/x-tex'>r</annotation></semantics></math> boules rouges parmi <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi><mo>+</mo><mi>b</mi></mrow><annotation encoding='application/x-tex'>r+b</annotation></semantics></math>, on convient donc que
la boule tirée est rouge si un tirage d’entier dans <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mn>0</mn><mo>,</mo><mi>r</mi><mo>+</mo><mi>b</mi><mo stretchy="false">[</mo></mrow><annotation encoding='application/x-tex'>[0,r+b[</annotation></semantics></math>
est strictement inférieur à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi></mrow><annotation encoding='application/x-tex'>r</annotation></semantics></math>.

</p><pre class="verbatim">fonction polya(r,b,n)
  local L,j;
  L:=[r/(r+b)];
  pour j de 1 jusque n faire
    si alea(r+b)&lt;r alors r++; sinon b++; fsi;
    L[j]:=r/(r+b);
  fpour;
  return L;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


<span style="font-weight:bold">Exemple :</span><br>
Simulation avec 1000 tirages et 1 boule rouge et 1 boule bleue au début :

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">gl_y=0..1;plotlist(polya(1,1,1000))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Dans la version HTML, si on clique plusieurs fois, on observe que la valeur
limite est très variable.
On peut s’intéresser à la répartition de cette proportion limite
de boules rouges (obtenue ici au bout de 1000 étapes). On modifie
la fonction précédente pour ne renvoyer que la dernière proportion.

</p><pre class="verbatim">fonction polya1(r,b,n)
  local j;
  pour j de 1 jusque n faire
    si alea(r+b)&lt;r alors r++; sinon b++; fsi;
  fpour;
  return r/(r+b);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


Puis on fait l’histogramme des fréquences pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi></mrow><annotation encoding='application/x-tex'>N</annotation></semantics></math> expériences

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">N:=100;histogramme(seq(polya1(1,1,1000),N),0,0.1);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Le temps de calcul commence
à s’allonger, on peut essayer d’optimiser un peu. On observe
que le nombre total de boules augmenté de 1 à chaque tirage, 
il suffit donc de suivre la valeur de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi></mrow><annotation encoding='application/x-tex'>r</annotation></semantics></math>

</p><pre class="verbatim">fonction polya2(r,b,n)
  local j,total,totalalafin;
  totalalafin:=r+b+n-1;
  pour total de r+b jusque totalalafin faire
    si alea(total)&lt;r alors r++; fsi;
  fpour;
  return r/(total-1);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">N:=1000;histogramme(seq(polya2(1,1,1000),N),0,0.1);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Une autre façon d’optimiser consiste à observer que <code>j</code>
ne sert pas dans la boucle <code>pour</code> de <code>polya1</code>.

</p><pre class="verbatim">fonction polya3(r,b,n)
  seq(when(alea(r+b)&lt;r,r++, b++),n);
  return r/(r+b);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">N:=1000;histogramme(seq(polya3(1,1,1000),N),0,0.1);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>N</mi><mo>=</mo><mn>1000</mn></mrow><annotation encoding='application/x-tex'>N=1000</annotation></semantics></math>, on s’aperçoit que
la distribution semble uniforme. Ceci n’est plus le cas pour
d’autres valeurs de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>r</mi></mrow><annotation encoding='application/x-tex'>r</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math>, dans la version HTML, vous pouvez
tester diverses valeurs initiales, par exemple 5,5 ou 1,5.

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">N:=1000;histogramme(seq(polya3(1,5,1000),N),0,0.1);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC chapter id="sec126" Les algorithmes du document ressource Python d’eduscol-->
<h1 id="sec126" class="chapter">Chapitre 9  Les algorithmes du document ressource Python d’eduscol</h1><!--SEC END --><p>
On propose dans ce chapitre des versions <span style="font-family:monospace">Xcas</span> de programmes
Python donnés dans ce
<a href="http://cache.media.eduscol.education.fr/file/Mathematiques/73/3/Algorithmique_et_programmation_787733.pdf">document</a></p><p>Pour les statistiques, voir le chapitre <a href="#chap%3Astats">8</a>. </p><p>Pour la dichotomie, voir <a href="#sec%3Adichotomie">4.1</a>.</p>
<!--TOC section id="sec127" Arithmétique-->
<h2 id="sec127" class="section">9.1  Arithmétique</h2><!--SEC END --><p>
On renvoie au manuel de programmation de <span style="font-family:monospace">Xcas</span> (menu Aide, Manuels), on
donne ici rapidement les équivalents <span style="font-family:monospace">Xcas</span> du document eduscol.</p>
<!--TOC subsection id="sec128" Euclide-->
<h3 id="sec128" class="subsection">9.1.1  Euclide</h3><!--SEC END --><p>
On calcule le PGCD de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> en observant que si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> est nul c’est <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math>,
sinon c’est le PGCD de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> et du reste de la division euclidienne de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> par
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> (<code>irem(a,b)</code>)

</p><pre class="verbatim">fonction pgcd(a,b)
  tantque b!=0 faire 
    a,b:=b,irem(a,b);
  ftantque;
  return a;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">pgcd(25,15)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec129" Écriture en base 2-->
<h3 id="sec129" class="subsection">9.1.2  Écriture en base 2</h3><!--SEC END --><p>
L’écriture de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> en base 2 est l’écriture de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi><mo stretchy="false">/</mo><mn>2</mn></mrow><annotation encoding='application/x-tex'>n/2</annotation></semantics></math> à laquelle
on ajoute le reste de la division <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> par 2.

</p><pre class="verbatim">fonction base2(n)
  local l;
  l:=[];
  tantque n&gt;0 faire
    l:=append(l,irem(n,2));
    n:=iquo(n,2);
  ftantque;
  return revlist(l);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


Il faut inverser l’ordre des éléments dans la liste 
avant de la renvoyer, parce qu’on calcule
en premier le dernier bit de l’écriture de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> en base 2.

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">l:=base2(12345)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>L’opération inverse se fait en utilisant le même principe : lorsqu’on
ajoute un bit à la fin de l’écriture de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> en base 2, cela revient
à multiplier <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> par 2 et lui ajouter la valeur de ce bit.

</p><pre class="verbatim">fonction base10(l)
  local n,x;
  n:=0;
  pour x in l faire
    n=2*n+x;
  fpour;
  return n;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">base10(l)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>La taille de l’écriture en base 2 s’obtient par <code>dim(l)</code>
ou directement par le programme suivant

</p><pre class="verbatim">fonction taille2(n)
  local l;
  l:=0;
  tantque n&gt;0 faire
    n:=iquo(n,2);
    l++;
  ftantque;
  return l;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">taille2(12345)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec130" Test de primalité-->
<h3 id="sec130" class="subsection">9.1.3  Test de primalité</h3><!--SEC END --><p>
On teste si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> est divisible par un entier <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>d</mi><mo>&leq;</mo><msqrt><mi>n</mi></msqrt></mrow><annotation encoding='application/x-tex'>d\leq \sqrt{n}</annotation></semantics></math>.

</p><pre class="verbatim">fonction estpremier(n)
  local d;
  si n&lt;2 alors return false; fsi;
  d:=2;
  tantque d*d&lt;=n faire
    si irem(n,d)=0 alors return false; fsi;
    d++;
  ftantque;
  return true;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">estpremier(1234567); isprime(1234567);
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>Remarque : cet algorithme est qualifié de naïf
car il ne permet pas de tester la primalité de grands
entiers. </p>
<!--TOC subsection id="sec131" Factorisation d’entiers-->
<h3 id="sec131" class="subsection">9.1.4  Factorisation d’entiers</h3><!--SEC END --><p>
Au lieu de s’arrêter et d’indiquer que le nombre n’est pas premier
lorsqu’on a une division exacte par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>d</mi></mrow><annotation encoding='application/x-tex'>d</annotation></semantics></math>, on ajoute <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>d</mi></mrow><annotation encoding='application/x-tex'>d</annotation></semantics></math>
à la liste des facteurs et on divise <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>d</mi></mrow><annotation encoding='application/x-tex'>d</annotation></semantics></math>.
Lorsqu’on sort de la boucle extérieure, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> vaut 1 ou est premier, 
il ne faut pas oublier de l’ajouter à la liste des facteurs.

</p><pre class="verbatim">fonction facto(n)
  local l,d;
  l:=[]; d:=2;
  tantque d*d&lt;=n faire
    tantque irem(n,d)=0 faire
      l:=append(l,d);
      n:=n/d;
    ftantque;
    d++;
  ftantque;
  si n&gt;1 alors l:=append(l,n); fsi;
  return l;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">facto(1234567); time(facto(1234567))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">ifactor(1234567); time(ifactor(1234567))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">facto(1234577); time(facto(1234577))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">ifactor(1234577); time(ifactor(1234577))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-weight:bold">Exercice :</span><br>
 Comparer l’efficacité de l’algorithme précédent avec l’algorithme du
document eduscol et compter le nombre d’itérations lorsque <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> est 
premier dans chacun de ces 2 programmes.</p><pre class="verbatim">fonction facto1(n)
  local l,d;
  l:=[]; d:=2;
  tantque n&gt;1 faire
    si irem(n,d)=0 alors
      tantque irem(n,d)=0 faire
        l:=append(l,d);
        n:=n/d;
      ftantque;
    fsi;
    d++;
  ftantque;
  return l;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">facto1(1234567); time(facto1(1234567))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>


<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">facto1(1234577); time(facto1(1234577))
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p>Remarque : ce type d’algorithme est qualifié de naïf,
car il ne permet pas de factoriser des nombres
ayant de grands facteurs premiers.</p>
<!--TOC section id="sec132" Longueur d’un arc de courbe-->
<h2 id="sec132" class="section">9.2  Longueur d’un arc de courbe</h2><!--SEC END --><p>
On cherche la longueur approchée d’un arc de courbe d’équation
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi><mo>=</mo><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>y=f(x)</annotation></semantics></math> entre les points d’abscisses <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math>. Pour cela
on approche l’arc de courbe par une ligne polygonale composée
de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> petits segments reliant les points de la courbe d’abscisses <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>+</mo><mi>k</mi><mi>h</mi></mrow><annotation encoding='application/x-tex'>a+kh</annotation></semantics></math> 
et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>+</mo><mo stretchy="false">(</mo><mi>k</mi><mo>+</mo><mn>1</mn><mo stretchy="false">)</mo><mi>h</mi></mrow><annotation encoding='application/x-tex'>a+(k+1)h</annotation></semantics></math> pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>k</mi><mo>&Element;</mo><mo stretchy="false">[</mo><mn>0</mn><mo>,</mo><mi>n</mi><mo>&minus;</mo><mn>1</mn><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>k \in [0,n&#x2d;1]</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>h</mi><mo>=</mo><mfrac><mrow><mi>b</mi><mo>&minus;</mo><mi>a</mi></mrow><mi>n</mi></mfrac></mrow><annotation encoding='application/x-tex'>h=\frac{b&#x2d;a}{n}</annotation></semantics></math>.

</p><pre class="verbatim">fonction longueurcourbe(f,a,b,n)
  local l,k,h;
  h:=evalf((b-a)/n);
  l:=0;
  pour k de 0 jusque n-1 faire
    l:=l+distance(point(a+k*h,f(a+k*h)),point(a+(k+1)*h,f(a+(k+1)*h)));
  fpour;
  return l;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


<div><textarea onkeypress="UI.ckenter(event,this,2)" 
style="width:800px;font-size:large">f(x):=sqrt(1-x^2); longueurcourbe(f,0,1,100) 
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value); tmp=UI.latexeval(tmp);nextSibling.innerHTML=tmp; if (UI.usemathjax) MathJax.Hub.Queue(['Typeset',MathJax.Hub,nextSibling])">ok</button><div style="width:800px;max-height:200px;overflow:auto;color:blue;text-align:center"></div></div>
</p><p><span style="font-weight:bold">Exercice :</span> <br>
Cette fonction <span style="font-family:monospace">longueurcourbe</span> est relativement inefficace, car on calcule 
plusieurs fois les mêmes quantités. Utilisez des variables locales
pour la rendre plus efficace.</p><p><span style="font-weight:bold">Solution :</span>

</p><pre class="verbatim">fonction longueurcourbe(f,a,b,n)
  local l,k,h,x,M,N;
  h:=evalf((b-a)/n);
  l:=0;
  x:=a;
  M:=point(x,f(x));
  pour k de 0 jusque n-1 faire
    x:=x+h;
    N:=point(x,f(x));
    l:=l+distance(M,N);
    M:=N;
  fpour;
  return l;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


<div><textarea onkeypress="UI.ckenter(event,this,2)" 
style="width:800px;font-size:large">f(x):=sqrt(1-x^2); longueurcourbe(f,0,1,100) 
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value); tmp=UI.latexeval(tmp);nextSibling.innerHTML=tmp; if (UI.usemathjax) MathJax.Hub.Queue(['Typeset',MathJax.Hub,nextSibling])">ok</button><div style="width:800px;max-height:200px;overflow:auto;color:blue;text-align:center"></div></div>
</p><p><span style="font-weight:bold">Remarque :</span> <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>h</mi></mrow><annotation encoding='application/x-tex'>h</annotation></semantics></math> est approché, donc en effectuant la boucle on
va accumuler des erreurs d’arrondis. Si l’erreur est faite par
excès, la dernière valeur de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> risque d’être un peu 
supérieure à 1, et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>f(x)</annotation></semantics></math> devient alors complexe, avec
une partie imaginaire très petite. Ceci n’a pas d’importance
dans <span style="font-family:monospace">Xcas</span>, car l’instruction <code>point(x,y)</code> renvoie
le point d’affixe <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>+</mo><mi>i</mi><mi>y</mi></mrow><annotation encoding='application/x-tex'>x+iy</annotation></semantics></math>. Dans d’autres langages, par exemple Python,
cela peut provoquer une erreur.</p><p><span style="font-weight:bold">Exercice :</span> <br>
Faire afficher la ligne polygonale dont on calcule la longueur.</p><p><span style="font-weight:bold">Solution :</span>

</p><pre class="verbatim">fonction approxcourbe(f,a,b,n)
  local L,k,h,x,M,N;
  h:=evalf((b-a)/n);
  x:=a;
  M:=point(x,f(x));
  L:=[M];
  pour k de 0 jusque n-1 faire
    x:=x+h;
    N:=point(x,f(x));
    L:=append(L,N);
    M:=N;
  fpour;
  return polygone_ouvert(L);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">f(x):=sqrt(1-x^2); plot(f(x),x=0..1,affichage=rouge);approxcourbe(f,0,1,10)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec133" Réfraction et recherche de minimas-->
<h2 id="sec133" class="section">9.3  Réfraction et recherche de minimas</h2><!--SEC END --><p>
On se donne une courbe d’équation <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi><mo>=</mo><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>y=f(x)</annotation></semantics></math> 
séparant deux milieux d’indices <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>n</mi> <mn>1</mn></msub></mrow><annotation encoding='application/x-tex'>n_1</annotation></semantics></math> et
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>n</mi> <mn>2</mn></msub></mrow><annotation encoding='application/x-tex'>n_2</annotation></semantics></math> et on cherche le chemin lumineux reliant deux points <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>A</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>A</mi></msub><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>A(x_A,y_A)</annotation></semantics></math>
et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi><mo stretchy="false">(</mo><msub><mi>x</mi> <mi>B</mi></msub><mo>,</mo><msub><mi>y</mi> <mi>B</mi></msub><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>B(x_B,y_B)</annotation></semantics></math> situés de part et d’autre de la courbe, 
il s’agit de deux segments de droite <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>M</mi></mrow><annotation encoding='application/x-tex'>AM</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi><mi>M</mi></mrow><annotation encoding='application/x-tex'>BM</annotation></semantics></math> où <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'>M</annotation></semantics></math>
est le point de la courbe tel que la somme
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>n</mi> <mn>1</mn></msub><mi>A</mi><mi>M</mi><mo>+</mo><msub><mi>n</mi> <mn>2</mn></msub><mi>B</mi><mi>M</mi></mrow><annotation encoding='application/x-tex'>n_1AM+n_2BM</annotation></semantics></math> est minimal. Comme <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'>M</annotation></semantics></math> a pour coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mo>,</mo><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>(x,f(x))</annotation></semantics></math>,
on peut calculer cette somme en fonction de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mi>n</mi> <mn>1</mn></msub><msqrt><mrow><mo stretchy="false">(</mo><mi>x</mi><mo>&minus;</mo><msub><mi>x</mi> <mi>A</mi></msub><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>+</mo><mo stretchy="false">(</mo><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>&minus;</mo><msub><mi>y</mi> <mi>A</mi></msub><msup><mo stretchy="false">)</mo> <mn>2</mn></msup></mrow></msqrt><mo>+</mo><msub><mi>n</mi> <mn>2</mn></msub><msqrt><mrow><mo stretchy="false">(</mo><mi>x</mi><mo>&minus;</mo><msub><mi>x</mi> <mi>B</mi></msub><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>+</mo><mo stretchy="false">(</mo><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>&minus;</mo><msub><mi>y</mi> <mi>B</mi></msub><msup><mo stretchy="false">)</mo> <mn>2</mn></msup></mrow></msqrt></mrow><annotation encoding='application/x-tex'>g(x)=n_1\sqrt{(x&#x2d;x_A)^2+(f(x)&#x2d;y_A)^2}+n_2\sqrt{(x&#x2d;x_B)^2+(f(x)&#x2d;y_B)^2} </annotation></semantics></math>
Il s’agit donc de déterminer le minimum de la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math>
(en supposant connue la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi></mrow><annotation encoding='application/x-tex'>f</annotation></semantics></math>).</p>
<!--TOC subsection id="sec134" Minimum d’une fonction-->
<h3 id="sec134" class="subsection">9.3.1  Minimum d’une fonction</h3><!--SEC END --><p>
On commence par la recherche approchée du minimum d’une fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math>.
On se donne un point de départ <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> et un pas <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>h</mi></mrow><annotation encoding='application/x-tex'>h</annotation></semantics></math>, on regarde si on
diminue la valeur de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> en se déplaçant vers la gauche.
Si c’est le cas, on continue à se déplacer vers la gauche
jusqu’à ce que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> ne diminue plus, on a alors atteint un
minimum local relativement à la discrétisation choisie.
Si ce n’est pas le cas, on essaie de se déplacer vers la 
droite.<sup><a id="text4" href="#note4">1</a></sup>

</p><pre class="verbatim">fonction minih(g,x,h) 
  // recherche d'un minimum local de g a partir de x en se deplacant
  // par pas de h vers la gauche ou vers la droite
  si g(x-h)&lt;g(x) alors
    tantque g(x-h)&lt;g(x) faire x:=x-h; ftantque;
  sinon
    tantque g(x+h)&lt;g(x) faire x:=x+h; ftantque;
  fsi;
  retourne x;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


<span style="font-weight:bold">Exemple :</span><br>
 Recherche du minimum de la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><msup><mi>x</mi> <mn>2</mn></msup><mo>&minus;</mo><mn>2</mn><msup><mo stretchy="false">)</mo> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>(x^2&#x2d;2)^2</annotation></semantics></math> en partant
de 2.0 (prendre le carré d’une expression, ici <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>x</mi> <mn>2</mn></msup><mo>&minus;</mo><mn>2</mn></mrow><annotation encoding='application/x-tex'>x^2&#x2d;2</annotation></semantics></math>, et en chercher
le minimum est une méthode de recherche d’une solution approchée)

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">g(x):=(x^2-2)^2:; minih(g,1.0,0.1)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

<span style="font-weight:bold">Attention !</span> ce programme peut tourner en boucle indéfiniment si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> 
décroit indéfiniment. Un programme plus robuste fixera un nombre
maximal d’itérations, par exemple ici 1000 par défaut.

</p><pre class="verbatim">fonction minih(g,x,h,N=1000) 
  local j;
  si g(x-h)&lt;g(x) alors
    pour j de 1 jusque N faire 
      si g(x-h)&gt;g(x) alors return x; fsi;
      x:=x-h;
    fpour;
  sinon
    pour j de 1 jusque N faire 
      si g(x+h)&gt;g(x) alors return x; fsi;
      x:=x+h;
    fpour;
  fsi;
  retourne "non trouve";
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


<span style="font-weight:bold">Exercice :</span><br>
 Améliorer ce programme pour calculer <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> une seule
fois par itération.</p><p><span style="font-weight:bold">Solution :</span><br>
Pour avoir une valeur de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math> avec une précision fixée à l’avance,
on commence avec un pas de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>h</mi></mrow><annotation encoding='application/x-tex'>h</annotation></semantics></math> (par défaut 0.1) et on divise le pas
par 10.

</p><pre class="verbatim">fonction mini(g,x,h=0.1,eps=1e-10) 
  // recherche d'un minimum local avec une precision de eps
  tantque h&gt;eps faire
    x:=minih(g,x,h);
    h:=h/10;
  ftantque;
  retourne minih(g,x,h);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


On effectue un dernier appel à <code>minih</code> pour assurer que la 
précision est meilleure que <code>1e-10</code>.

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">g(x):=(x^2-2)^2:; mini(g,1.0)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

<span style="font-weight:bold">Exercice :</span> <br>
expliquer pourquoi il est plus rapide d’appeler 
<code>mini(g,1.0,0.1,1e-10)</code> que <code>minih(g,1.0,1e-10)</code>.</p>
<!--TOC subsection id="sec135" Application à la réfraction-->
<h3 id="sec135" class="subsection">9.3.2  Application à la réfraction</h3><!--SEC END --><p>
Appliquons maintenant au problème de la réfraction.
La fonction <code>refraction</code>
prend en arguments la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi></mrow><annotation encoding='application/x-tex'>f</annotation></semantics></math> définissant la courbe séparatrice,
les points <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi></mrow><annotation encoding='application/x-tex'>B</annotation></semantics></math> et les indices de réfraction, elle
renvoie le point <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'>M</annotation></semantics></math>. 

</p><pre class="verbatim">fonction refraction(f,A,B,n1,n2)
  local g,x,tst;
  si f(abscisse(A))&lt;ordonnee(A) ou f(abscisse(B))&gt;ordonnee(B) alors 
    return "A et B sont du meme cote du graphe!"; 
  fsi;
  g(x):=n1*distance(A,point(x,f(x)))+n2*distance(B,point(x,f(x))); 
  x:=mini(g,abscisse(milieu(A,B)));
  return point(x,f(x));
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


Illustration avec une fonction linéaire <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>1</mn><mo>&minus;</mo><mn>2</mn><mi>x</mi></mrow><annotation encoding='application/x-tex'>1&#x2d;2x</annotation></semantics></math>, 
la séparatrice est la droite <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>D</mi></mrow><annotation encoding='application/x-tex'>D</annotation></semantics></math> d’équation <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi><mo>=</mo><mn>1</mn><mo>&minus;</mo><mn>2</mn><mi>x</mi></mrow><annotation encoding='application/x-tex'>y=1&#x2d;2x</annotation></semantics></math>

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">f(x):=1-2x;
gl_ortho=true;D:=plot(f(x),x=0..1,couleur=vert);
A:=point(0,0); B:=point(1,1); M:=refraction(f,A,B,2.5,1);
segment(A,M,couleur=rouge); segment(M,B,couleur=rouge)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

Pour tester avec une courbe non linéaire, par
exemple avec la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>=</mo><mi>cos</mi><mo stretchy="false">(</mo><mn>5</mn><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>f(x)=\cos(5x)</annotation></semantics></math>, il suffit de modifier la définition
de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>f</mi></mrow><annotation encoding='application/x-tex'>f</annotation></semantics></math> :

<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">f(x):=cos(5x);
gl_ortho=true;D:=plot(f(x),x=0..1,couleur=vert);
A:=point(0,0); B:=point(1,1); M:=refraction(f,A,B,2.5,1);
segment(A,M,couleur=rouge); segment(M,B,couleur=rouge)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC subsection id="sec136" Discussion-->
<h3 id="sec136" class="subsection">9.3.3  Discussion</h3><!--SEC END --><p>
L’application à la réfraction
est certainement trop difficile pour des élèves débutants, on 
définit en effet ici une fonctionnelle (fonction dont un argument
est une fonction), et on définit une fonction dans une 
autre fonction (la fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math>). De plus la définition
de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> ci-dessus n’est pas recommandée, car elle
dépend de la valeur de paramètres <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>n</mi> <mn>1</mn></msub><mo>,</mo><msub><mi>n</mi> <mn>2</mn></msub><mo>,</mo><mi>A</mi></mrow><annotation encoding='application/x-tex'>n_1,n_2, A</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi></mrow><annotation encoding='application/x-tex'>B</annotation></semantics></math> qui
ne sont pas passés en argument
(<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> n’est pas une fonction
pure, i.e. indépendante du contexte).
Pour rendre <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> indépendante du contexte, il faut remplacer 
dans son expression
<code>n1*distance(A,M)+n2*distance(B,M)</code><br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>n</mi> <mn>1</mn></msub><mo>,</mo><msub><mi>n</mi> <mn>2</mn></msub><mo>,</mo><mi>A</mi><mo>,</mo><mi>B</mi></mrow><annotation encoding='application/x-tex'>n_1,n_2,A,B</annotation></semantics></math> par leurs valeurs. Dans <span style="font-family:monospace">Xcas</span>, on peut le faire 
en utilisant le moteur de calcul formel. On utilise une variable
symbolique <code>x</code> pour calculer l’expression de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math>,
c’est le rôle de la commande <code>purge(x)</code> ci-dessous, 
et on utilise la commande <code>unapply</code> qui permet de définir
une fonction à partir d’une expression.

</p><pre class="verbatim">fonction refraction(f,A,B,n1,n2)
  local g,M,x,tst,xM;
  tst:=(f(abscisse(A))-ordonnee(A))*(f(abscisse(B))-ordonnee(B));
  si tst&gt;=0 alors return "A et B sont du meme cote du graphe!"; fsi;
  purge(x);
  M:=point(x,f(x));
  g:=unapply(n1*distance(A,M)+n2*distance(B,M),x);
  xM:=mini(g,abscisse(milieu(A,B)));
  return point(xM,f(xM));
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


On a aussi amélioré le test que les deux points <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> et 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi></mrow><annotation encoding='application/x-tex'>B</annotation></semantics></math> sont bien de part
et d’autre de la courbe
en introduisant une variable locale <code>tst</code>
qui doit être négative.</p><p>Dans des langages non formels, pour faire les choses proprement, il
faut passer explicitement les paramètres <code>A,B,n1,n2</code> à la
fonction <code>g</code>, en les regroupant (dans une liste dans un langage
de script, par un pointeur vers une structure en C).
Le prototype de la fonction <code>g</code> est alors <code>g(x,params)</code>,
celui des fonctions <code>mini</code> est <code>mini(g,param,x,h,eps)</code>. Mais
ceci complique bien sur la présentation au niveau du lycée.</p>
<!--TOC subsection id="sec137" Autre méthode de recherche de minimum-->
<h3 id="sec137" class="subsection">9.3.4  Autre méthode de recherche de minimum</h3><!--SEC END --><p>
On suppose ici qu’on cherche le minimum d’une fonction <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> sur
un intervalle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[a,b]</annotation></semantics></math> avec <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> d’abord décroissante puis croissante.
On suppose donc qu’on a un triplet <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>,</mo><mi>c</mi><mo>,</mo><mi>b</mi></mrow><annotation encoding='application/x-tex'>a,c,b</annotation></semantics></math> tel que 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(c)</annotation></semantics></math> est plus petit que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(a)</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>b</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(b)</annotation></semantics></math>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>a</mi><mi>&lt;</mi><mi>c</mi><mi>&lt;</mi><mi>b</mi><mo>,</mo><mspace width="1em"/><mi>g</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo><mi>&lt;</mi><mi>g</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo><mo>,</mo><mi>g</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo><mi>&lt;</mi><mi>g</mi><mo stretchy="false">(</mo><mi>b</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>a&amp;lt;c&amp;lt;b, \quad  g(c)&amp;lt;g(a), g(c)&amp;lt;g(b) </annotation></semantics></math>
On effectue ensuite une sorte de dichotomie. On se fixe une précision
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>&epsi;</mi></mrow><annotation encoding='application/x-tex'>\epsilon</annotation></semantics></math>
</p><ol class="enumerate" type=1><li class="li-enumerate">
On effectue une boucle tant que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi><mo>&minus;</mo><mi>a</mi><mi>&gt;</mi><mi>&epsi;</mi></mrow><annotation encoding='application/x-tex'>b&#x2d;a&amp;gt;\epsilon</annotation></semantics></math>
</li><li class="li-enumerate">On calcule la valeur de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> au milieu <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>u</mi></mrow><annotation encoding='application/x-tex'>u</annotation></semantics></math> de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mi>a</mi><mo>,</mo><mi>c</mi><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[a,c]</annotation></semantics></math>.
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>u</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(u)</annotation></semantics></math> est plus petit que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(a)</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(c)</annotation></semantics></math> on peut utiliser
le nouveau triplet <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>,</mo><mi>u</mi><mo>,</mo><mi>c</mi></mrow><annotation encoding='application/x-tex'>a,u,c</annotation></semantics></math>, on passe à l’itération suivante.
</li><li class="li-enumerate">Sinon, on calcule la valeur de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> au milieu <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>v</mi></mrow><annotation encoding='application/x-tex'>v</annotation></semantics></math> de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">[</mo><mi>c</mi><mo>,</mo><mi>b</mi><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>[c,b]</annotation></semantics></math>.
Si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>v</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(v)</annotation></semantics></math> est plus petit que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(c)</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>b</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(b)</annotation></semantics></math> on peut utiliser
le nouveau triplet <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi><mo>,</mo><mi>v</mi><mo>,</mo><mi>b</mi></mrow><annotation encoding='application/x-tex'>c,v,b</annotation></semantics></math>, on passe à l’itération suivante.
</li><li class="li-enumerate">Sinon, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>u</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(u)</annotation></semantics></math> est plus grand que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(c)</annotation></semantics></math> ou que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(a)</annotation></semantics></math> donc
est plus grand que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(c)</annotation></semantics></math> puisque <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo><mi>&lt;</mi><mi>g</mi><mo stretchy="false">(</mo><mi>a</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(c)&amp;lt;g(a)</annotation></semantics></math>, et de même <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>v</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(v)</annotation></semantics></math>
est plus grand que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi><mo stretchy="false">(</mo><mi>c</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>g(c)</annotation></semantics></math>, donc on utilise le nouveau triplet <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>u</mi><mo>,</mo><mi>c</mi><mo>,</mo><mi>v</mi></mrow><annotation encoding='application/x-tex'>u,c,v</annotation></semantics></math>
et on passe à l’itération suivante.
</li></ol><p>
Le programme se termine (En effet, si on applique la troisième règle,
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi><mo>&minus;</mo><mi>a</mi></mrow><annotation encoding='application/x-tex'>b&#x2d;a</annotation></semantics></math> est divisé par 2. Si on applique uniquement la 1ère et la
2ème règle, si on applique deux fois de suite la première règle
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> est remplacé par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi></mrow><annotation encoding='application/x-tex'>c</annotation></semantics></math> puis par le <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>u</mi></mrow><annotation encoding='application/x-tex'>u</annotation></semantics></math> précédent donc
on gagne un facteur 2, de même pour la deuxième règle, si
on applique la première puis la deuxième <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi></mrow><annotation encoding='application/x-tex'>b</annotation></semantics></math> est remplacé par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi></mrow><annotation encoding='application/x-tex'>c</annotation></semantics></math>
et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi></mrow><annotation encoding='application/x-tex'>a</annotation></semantics></math> par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>u</mi></mrow><annotation encoding='application/x-tex'>u</annotation></semantics></math> donc on gagne aussi un facteur 2).

</p><pre class="verbatim">fonction mini2(g,a,b,c,eps=1e-10)
  local u,v;
  si c&lt;=a ou c&gt;=b alors return "erreur"; fsi;
  si g(c)&gt;=g(a) ou g(c)&gt;=g(b) alors return "erreur"; fsi;
  tantque b-a&gt;eps faire
    u:=(a+c)/2;
    si g(u)&lt;g(a) et g(u)&lt;g(c) alors a,c,b:=a,u,c; continue; fsi;
    v:=(b+c)/2;
    si g(v)&lt;g(c) et g(v)&lt;g(b) alors a,c,b:=c,v,b; continue; fsi;
    a,c,b:=u,c,v;
  ftantque;
  return a,b,c;
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">mini2(cos,1.0,6.0,3.0)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

<span style="font-weight:bold">Exercice :</span> <br>
Rendre ce programme plus efficace en calculant le moins de fois
possible les images par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>g</mi></mrow><annotation encoding='application/x-tex'>g</annotation></semantics></math> de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>,</mo><mi>b</mi><mo>,</mo><mi>c</mi><mo>,</mo><mi>u</mi><mo>,</mo><mi>v</mi></mrow><annotation encoding='application/x-tex'>a,b,c,u,v</annotation></semantics></math>.</p>
<!--TOC section id="sec138" Solveur de triangle-->
<h2 id="sec138" class="section">9.4  Solveur de triangle</h2><!--SEC END --><p> <a id="sec:trisolv"></a>
On cherche à construire un triangle <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi><mi>B</mi><mi>C</mi></mrow><annotation encoding='application/x-tex'>ABC</annotation></semantics></math> dont les cotés sont
donnés par <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>=</mo><mi>B</mi><mi>C</mi><mo>,</mo><mi>b</mi><mo>=</mo><mi>A</mi><mi>C</mi><mo>,</mo><mi>c</mi><mo>=</mo><mi>A</mi><mi>B</mi></mrow><annotation encoding='application/x-tex'>a=BC,b=AC,c=AB</annotation></semantics></math> où <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>,</mo><mi>b</mi><mo>,</mo><mi>c</mi></mrow><annotation encoding='application/x-tex'>a,b,c</annotation></semantics></math> 
vérifient les inégalités triangulaires
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>a</mi><mi>&lt;</mi><mi>b</mi><mo>+</mo><mi>c</mi><mo>,</mo><mspace width="1em"/><mi>b</mi><mi>&lt;</mi><mi>a</mi><mo>+</mo><mi>c</mi><mo>,</mo><mspace width="1em"/><mi>c</mi><mi>&lt;</mi><mi>a</mi><mo>+</mo><mi>b</mi></mrow><annotation encoding='application/x-tex'>a&amp;lt;b+c, \quad b&amp;lt;a+c, \quad c&amp;lt;a+b </annotation></semantics></math>
On peut par translation se ramener au cas où <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> est l’origine, puis
par rotation à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi><mo stretchy="false">(</mo><mi>c</mi><mo>,</mo><mn>0</mn><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>B(c,0)</annotation></semantics></math>, il s’agit donc de déterminer les
coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>(x,y)</annotation></semantics></math> de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>C</mi></mrow><annotation encoding='application/x-tex'>C</annotation></semantics></math>. 

</p><pre class="verbatim">c:=3; x:=1; y:=2;
A:=point(0,0,legende="A(0,0)"); 
B:=point(c,0,legende="B(c,0)"); 
C:=point(x,y,legende="C(x,y)");
triangle(A,B,C);
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>


On a deux équations
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msup><mi>a</mi> <mn>2</mn></msup><mo>=</mo><mi>B</mi><msup><mi>C</mi> <mn>2</mn></msup><mo>=</mo><mo stretchy="false">(</mo><mi>x</mi><mo>&minus;</mo><mi>c</mi><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>+</mo><msup><mi>y</mi> <mn>2</mn></msup><mo>,</mo><mspace width="1em"/><msup><mi>b</mi> <mn>2</mn></msup><mo>=</mo><mi>A</mi><msup><mi>C</mi> <mn>2</mn></msup><mo>=</mo><msup><mi>x</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>y</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>a^2=BC^2=(x&#x2d;c)^2+y^2, \quad b^2=AC^2=x^2+y^2 </annotation></semantics></math>
En en faisant la différence, on obtient 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><msup><mi>a</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>b</mi> <mn>2</mn></msup><mo>=</mo><mo stretchy="false">(</mo><mi>x</mi><mo>&minus;</mo><mi>c</mi><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>x</mi> <mn>2</mn></msup><mo>=</mo><mo lspace="verythinmathspace" rspace="0em">&minus;</mo><mn>2</mn><mi>c</mi><mi>x</mi><mo>+</mo><msup><mi>c</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>a^2&#x2d;b^2=(x&#x2d;c)^2&#x2d;x^2=&#x2d;2cx+c^2 </annotation></semantics></math>
d’où l’on tire la valeur de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi></mrow><annotation encoding='application/x-tex'>x</annotation></semantics></math>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>x</mi><mo>=</mo><mfrac><mrow><msup><mi>c</mi> <mn>2</mn></msup><mo>&minus;</mo><mo stretchy="false">(</mo><msup><mi>a</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>b</mi> <mn>2</mn></msup><mo stretchy="false">)</mo></mrow><mrow><mn>2</mn><mi>c</mi></mrow></mfrac></mrow><annotation encoding='application/x-tex'>x=\frac{c^2&#x2d;(a^2&#x2d;b^2)}{2c} </annotation></semantics></math>
puis la deuxième équation nous donne deux valeurs pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>y</mi></mrow><annotation encoding='application/x-tex'>y</annotation></semantics></math> (correspondant
à deux triangles symétriques)
<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'><semantics><mrow><mi>y</mi><mo>=</mo><mo>&pm;</mo><msqrt><mrow><msup><mi>b</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>x</mi> <mn>2</mn></msup></mrow></msqrt></mrow><annotation encoding='application/x-tex'>y=\pm \sqrt{b^2&#x2d;x^2} </annotation></semantics></math>
<span style="font-weight:bold">Remarque :</span><br>
Puisque <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mo>,</mo><mi>b</mi><mo>,</mo><mi>c</mi></mrow><annotation encoding='application/x-tex'>a,b,c</annotation></semantics></math> vérifient les inégalités triangulaires
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>a</mi><mi>&lt;</mi><mi>b</mi><mo>+</mo><mi>c</mi><mo>,</mo><mspace width="1em"/><mi>b</mi><mi>&lt;</mi><mi>a</mi><mo>+</mo><mi>c</mi><mo>,</mo><mspace width="1em"/><mi>c</mi><mi>&lt;</mi><mi>a</mi><mo>+</mo><mi>b</mi></mrow><annotation encoding='application/x-tex'> a&amp;lt;b+c, \quad b&amp;lt;a+c, \quad c&amp;lt;a+b</annotation></semantics></math> si <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>x</mi><mo>=</mo><mfrac><mrow><msup><mi>c</mi> <mn>2</mn></msup><mo>&minus;</mo><mo stretchy="false">(</mo><msup><mi>a</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>b</mi> <mn>2</mn></msup><mo stretchy="false">)</mo></mrow><mrow><mn>2</mn><mi>c</mi></mrow></mfrac></mrow><annotation encoding='application/x-tex'>x=\frac{c^2&#x2d;(a^2&#x2d;b^2)}{2c}</annotation></semantics></math> alors 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>b</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>x</mi> <mn>2</mn></msup><mo>&geq;</mo><mn>0</mn></mrow><annotation encoding='application/x-tex'>b^2&#x2d;x^2\geq 0</annotation></semantics></math>, en effet :<br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>4</mn><msup><mi>c</mi> <mn>2</mn></msup><msup><mi>x</mi> <mn>2</mn></msup><mo>=</mo><mo stretchy="false">(</mo><msup><mi>b</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>c</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>a</mi> <mn>2</mn></msup><msup><mo stretchy="false">)</mo> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>4c^2x^2=(b^2+c^2&#x2d;a^2)^2</annotation></semantics></math> donc <br>
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>4</mn><msup><mi>c</mi> <mn>2</mn></msup><mo stretchy="false">(</mo><msup><mi>b</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>x</mi> <mn>2</mn></msup><mo stretchy="false">)</mo><mo>=</mo><mo stretchy="false">(</mo><mn>2</mn><mi>c</mi><mi>b</mi><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>&minus;</mo><mo stretchy="false">(</mo><msup><mi>b</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>c</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>a</mi> <mn>2</mn></msup><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>=</mo><mo stretchy="false">(</mo><mn>2</mn><mi>c</mi><mi>b</mi><mo>+</mo><msup><mi>b</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>c</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>a</mi> <mn>2</mn></msup><mo stretchy="false">)</mo><mo stretchy="false">(</mo><mn>2</mn><mi>c</mi><mi>b</mi><mo>&minus;</mo><msup><mi>b</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>c</mi> <mn>2</mn></msup><mo>+</mo><msup><mi>a</mi> <mn>2</mn></msup><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>4c^2(b^2&#x2d;x^2)=(2cb)^2&#x2d;(b^2+c^2&#x2d;a^2)^2=(2cb+b^2+c^2&#x2d;a^2)(2cb&#x2d;b^2&#x2d;c^2+a^2)</annotation></semantics></math>.<br>
Donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>b</mi> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>x</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>b^2&#x2d;x^2</annotation></semantics></math> a le même signe que <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mo stretchy="false">(</mo><mi>b</mi><mo>+</mo><mi>c</mi><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo>&minus;</mo><msup><mi>a</mi> <mn>2</mn></msup><mo stretchy="false">)</mo><mo stretchy="false">(</mo><msup><mi>a</mi> <mn>2</mn></msup><mo>&minus;</mo><mo stretchy="false">(</mo><mi>b</mi><mo>&minus;</mo><mi>c</mi><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>((b+c)^2&#x2d;a^2)(a^2&#x2d;(b&#x2d;c)^2)</annotation></semantics></math>.
Ce signe est positif puisque d’après les inégalités triangulaires on a :<br>
 <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mn>0</mn><mi>&lt;</mi><mi>a</mi><mi>&lt;</mi><mi>b</mi><mo>+</mo><mi>c</mi></mrow><annotation encoding='application/x-tex'>0&amp;lt;a&amp;lt;b+c</annotation></semantics></math> donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mi>a</mi> <mn>2</mn></msup><mi>&lt;</mi><mo stretchy="false">(</mo><mi>b</mi><mo>+</mo><mi>c</mi><msup><mo stretchy="false">)</mo> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>a^2&amp;lt;(b+c)^2</annotation></semantics></math> et<br>
 <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>b</mi><mo>&minus;</mo><mi>c</mi><mi>&lt;</mi><mi>a</mi></mrow><annotation encoding='application/x-tex'> b&#x2d;c&amp;lt;a</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>c</mi><mo>&minus;</mo><mi>b</mi><mi>&lt;</mi><mi>a</mi></mrow><annotation encoding='application/x-tex'>c&#x2d;b&amp;lt;a</annotation></semantics></math> donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">&vert;</mo><mi>b</mi><mo>&minus;</mo><mi>c</mi><mo stretchy="false">&vert;</mo><mi>&lt;</mi><mi>a</mi></mrow><annotation encoding='application/x-tex'>|b&#x2d;c|&amp;lt;a</annotation></semantics></math> donc <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>b</mi><mo>&minus;</mo><mi>c</mi><msup><mo stretchy="false">)</mo> <mn>2</mn></msup><mi>&lt;</mi><msup><mi>a</mi> <mn>2</mn></msup></mrow><annotation encoding='application/x-tex'>(b&#x2d;c)^2&amp;lt;a^2</annotation></semantics></math>.

</p><pre class="verbatim">fonction trisolve(a,b,c)
  local x,y;
  x:=(c^2+b^2-a^2)/(2*c);
  y:=sqrt(b^2-x^2);
  return point(0,0),point(c,0),point(x,y);
ffonction:;
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=UI.count_newline(tmp);var tmp1=UI.ltgt(tmp)[0];t.value=tmp1;tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span>onload</span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:800px;font-size:large">A,B,C:=trisolve(3,4,5); triangle(A,B,C)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p><p><span style="font-weight:bold">Remarque :</span> <br>
Le document ressource Python eduscol utilise une méthode
de résolution approchée pour déterminer le triangle. Cela nous
semble peu adapté, car la résolution exacte est accessible
au niveau lycée et est beaucoup plus simple.</p>
<!--BEGIN NOTES chapter-->
<hr class="footnoterule"><dl class="thefootnotes"><dt class="dt-thefootnotes">
<a id="note4" href="#text4">1</a></dt><dd class="dd-thefootnotes"><div class="footnotetext">Cette méthode se généralise en dimension plus grande,
on cherche la direction de plus grande pente et on se déplace dans
cette direction d’un pas constant</div></dd></dl>
<!--END NOTES-->
<!--TOC chapter id="sec139" Aide-->
<h1 id="sec139" class="chapter">Chapitre 10  Aide</h1><!--SEC END -->
<!--TOC section id="sec140" Les fonctions usuelles avec <span style="font-family:monospace">Xcas</span>-->
<h2 id="sec140" class="section">10.1  Les fonctions usuelles avec <span style="font-family:monospace">Xcas</span></h2><!--SEC END --><p>
<span style="font-family:monospace">abs</span> : valeur absolue ou le module de l’argument.<br>
<span style="font-family:monospace">ceil</span> : renvoie le plus petit entier &gt;= à l’argument.<br>
<span style="font-family:monospace">cos</span> : renvoie le cosinus de l’argument.<br>
<span style="font-family:monospace">Digits</span> : pseudo-variable pour modifier le nombre <span style="font-family:monospace">n</span> de chiffres 
significatifs (par ex <span style="font-family:monospace">Digits:=n</span>).<br>
<span style="font-family:monospace">evalf</span> : évaluation numérique du premier argument (le nombre de digits 
peut être donné comme second argument).<br>
<span style="font-family:monospace">floor</span> : renvoie la partie entière de l’argument (le plus grand entier 
&lt;= à l’argument.<br>
<span style="font-family:monospace">frac</span> : partie fractionnaire de l’argument.<br>
<span style="font-family:monospace">max</span> : renvoie le maximum des éléments d’une séquence ou d’une liste de réels.<br>
<span style="font-family:monospace">min</span> : renvoie le minimum des éléments d’une séquence ou d’une liste de réels.<br>
<span style="font-family:monospace">+</span> : renvoie la concaténation de 2 chaînes ou addition terme à terme 
de 2 expressions ou 2 listes (opérateur infixé).<br>
<span style="font-family:monospace">round</span> : renvoie l’argument réel arrondi à l’entier (ou le décimal)
le plus proche. <br>
<span style="font-family:monospace">sin</span> : renvoie le sinus de l’argument.<br>
<span style="font-family:monospace">sign</span> : renvoie le signe (-1,0,+1) de l’argument.<br>
<span style="font-family:monospace">sqrt</span> : renvoie la racine carrée de l’argument.<br>
<span style="font-family:monospace">tan</span> : renvoie la tangente de l’argument.
</p>
<!--TOC section id="sec141" Les fonctions <span style="font-family:monospace">Xcas</span> de calcul formel utilisées-->
<h2 id="sec141" class="section">10.2  Les fonctions <span style="font-family:monospace">Xcas</span> de calcul formel utilisées</h2><!--SEC END --><p>
<span style="font-family:monospace">coeff(P,var,[n]</span> : renvoie la liste des coefficients d’un polynôme
<span style="font-family:monospace">P</span> par rapport à la variable <span style="font-family:monospace">Var</span> ou le coefficient de 
degré <span style="font-family:monospace">n</span>.<br>
<span style="font-family:monospace">count(f,L)</span> : applique la fonction <span style="font-family:monospace">f</span> aux éléments de la liste 
<span style="font-family:monospace">L</span> et en renvoie la somme.<br>
<span style="font-family:monospace">degree(P,var</span> : renvoie le degré du polynôme <span style="font-family:monospace">P</span> par rapport à la 
variable <span style="font-family:monospace">var</span>.<br>
<span style="font-family:monospace">dim</span> : renvoie la longueur d’une liste, d’une séquence ou d’une chaîne de caractères.<br>
<span style="font-family:monospace">droit</span> : renvoie le côté droit d’une équation, d’un intervalle, 
d’une liste ou d’une chaîne .<br>
<span style="font-family:monospace">fsolve</span> ou <span style="font-family:monospace">resoudre_numerique</span> : renvoie la solution numérique d’une équation. <br>
<span style="font-family:monospace">gauche</span> : renvoie le côté gauche d’une équation, d’un intervalle, 
d’une liste ou d’une chaîne.<br>
<span style="font-family:monospace">iquo</span> : renvoie le quotient euclidien de 2 entiers. <br>
<span style="font-family:monospace">iquorem</span> : renvoie la liste du quotient et du reste euclidien de 2
entiers.<br>
<span style="font-family:monospace">irem</span> : renvoie le reste euclidien de 2 entiers.<br>
<span style="font-family:monospace">normal</span> : renvoie une simplification de l’argument.<br>
<span style="font-family:monospace">purge(a)</span> : enlève la valeur stockée dans la variable <span style="font-family:monospace">a</span>.<br>
<span style="font-family:monospace">simplify</span> ou <span style="font-family:monospace">simplifier</span> : renvoie une simplification de l’argument.<br>
<span style="font-family:monospace">solve</span> ou <span style="font-family:monospace">resoudre</span> : renvoie la solution d’une équation.<br>
<span style="font-family:monospace">sommets</span> : renvoie la liste des sommets d’un polygone.<br>
<span style="font-family:monospace">subst</span> ou <span style="font-family:monospace">substituer</span> : remplace dans une expression, une variable non affectée par 
une valeur.<br>
<span style="font-family:monospace">sum</span> ou <span style="font-family:monospace">somme</span> : somme des éléments d’une liste (ou séquence).<br>
<span style="font-family:monospace">subtype</span> : renvoie 1 pour une séquence, 2 pour un ensemble, 10 pour un 
polynôme et 0 sinon ce qui définit le sous-type de l’argument.<br>
<span style="font-family:monospace">type</span> : renvoie <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> dans [1..12] définissant le type de l’argument.</p>
<!--TOC section id="sec142" Les fonctions <span style="font-family:monospace">Xcas</span> de géométrie utilisées-->
<h2 id="sec142" class="section">10.3  Les fonctions <span style="font-family:monospace">Xcas</span> de géométrie utilisées</h2><!--SEC END --><p>
<span style="font-family:monospace">affichage</span> : employé comme option de commandes graphiques permet
de faire des dessins en couleur (par ex 
<span style="font-family:monospace">A:=point([1,1],affichage=rouge)</span>).<br>
<span style="font-family:monospace">carre</span> : renvoie et dessine le carré direct donné par 2 
points.<br>
<span style="font-family:monospace">centre</span> : renvoie et dessine le centre du cercle donné en argument.<br>
<span style="font-family:monospace">cercle</span> : renvoie et dessine le cercle donné par 1 point et 1 réel (son
centre et son rayon) ou par 2 points (son diamètre) ou par son équation.<br>
<span style="font-family:monospace">demi_droite</span> : renvoie et dessine la demi-droite donnée par son origine
et 1 point ou par son origine et son vecteur directeur [1,m].<br>
<span style="font-family:monospace">droite</span> : renvoie et dessine la droite donnée par 2 points ou par 1 point
et son vecteur directeur [1,m].<br>
<span style="font-family:monospace">est_aligne</span> : renvoie 1 si les points sont alignés, 2 si les points sont
confondus et 0 sinon.<br>
<span style="font-family:monospace">est_parallele</span> : renvoie 1 si 2 droites sont parallèles et 0 sinon.<br>
<span style="font-family:monospace">equation</span> : renvoie l’équation de l’argument.<br>
<span style="font-family:monospace">inter</span> dessine et renvoie la liste des points d’intersection de 2 objets géométriques.<br>
<span style="font-family:monospace">inter_unique</span> renvoie et dessine un des points d’intersection de 2 objets géométriques.<br>
<span style="font-family:monospace">longueur</span> : renvoie la longueur du segment défini par 2 points 
ou par les coordonnées de ces points.
<span style="font-family:monospace">norm</span> : renvoie la norme l2 d’un vecteur :<br>
<span style="font-family:monospace">norm</span><math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mo stretchy="false">[</mo><msub><mi>x</mi> <mn>1</mn></msub><mo>,</mo><mo>.</mo><mo>.</mo><msub><mi>x</mi> <mi>n</mi></msub><mo stretchy="false">]</mo><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>([x_1,..x_n])</annotation></semantics></math> : renvoie <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msqrt><mo stretchy="false">(</mo></msqrt><msubsup><mi>x</mi> <mn>1</mn> <mn>2</mn></msubsup><mo>+</mo><mo>.</mo><mo>.</mo><mo>.</mo><msubsup><mi>x</mi> <mi>n</mi> <mn>2</mn></msubsup><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>\sqrt(x_1^2+...x_n^2)</annotation></semantics></math><br>
<span style="font-family:monospace">point</span> : renvoie et dessine le point de coordonnées l’argument.<br>
<span style="font-family:monospace">polygone</span> : renvoie et dessine le polygone donné par une liste de 
points.<br>
<span style="font-family:monospace">polygone_ouvert</span> : renvoie et dessine la ligne polygonale donnée par une
liste de points.<br>
<span style="font-family:monospace">rayon</span> :renvoie le rayon du cercle donné en argument.<br>
<span style="font-family:monospace">segment</span> : renvoie et dessine soit le segment donné par 2 points ou 
le vecteur donné par un point et son vecteur directeur. <span style="font-weight:bold">Bien voir</span> la 
différence entre <span style="font-family:monospace">segment(point(cA),point(cB))</span> (c’est le segment (A,B)) 
et <span style="font-family:monospace">segment(cA,cB)</span> qui est aussi <span style="font-family:monospace">segment(point(cA),point(cA+cB))</span>.<br>
<span style="font-family:monospace">sommets</span> : renvoie la liste des sommets du polygone donné en argument et les dessine.<br>
<span style="font-family:monospace">translation(B-A,C)</span> : renvoie et dessine le translaté de <span style="font-family:monospace">C</span> dans la 
translation de vecteur <span style="font-family:monospace">AB</span>.<br>
<span style="font-family:monospace">triangle</span> : renvoie et dessine le triangle donné par 3 points.<br>
<span style="font-family:monospace">vecteur</span> : renvoie et dessine le vecteur donné par 2 points ou par un 
point et son vecteur directeur. <span style="font-weight:bold">Bien voir</span> la 
différence entre <span style="font-family:monospace">vecteur(point(cA),point(cB))</span>(c’est le vecteur (A,B)) et
<span style="font-family:monospace">vecteur(cA,cB)</span> qui est aussi <span style="font-family:monospace">vecteur(point(cA),point(cA+cB))</span>.
</p>
<!--TOC section id="sec143" Les fonctions <span style="font-family:monospace">Xcas</span> de programmation utilisées-->
<h2 id="sec143" class="section">10.4  Les fonctions <span style="font-family:monospace">Xcas</span> de programmation utilisées</h2><!--SEC END --><p>
<span style="font-family:monospace">break</span> : pour interrompre une boucle (tantque &lt;cond&gt; faire inst1; 
si &lt;cond&gt; alors inst2;break;fsi;ftantque;).<br>
<span style="font-family:monospace">fpour</span><br>
<span style="font-family:monospace">fsi</span><br>
<span style="font-family:monospace">ftantque</span><br>
<span style="font-family:monospace">jusque</span><br>
<span style="font-family:monospace">local</span><br>
<span style="font-family:monospace">pas</span><br>
<span style="font-family:monospace">pour &lt;k&gt; de &lt;k1&gt; jusque &lt;k2&gt; faire &lt;instructions&gt; pas &lt;p&gt; fpour</span><br>
<span style="font-family:monospace">quand</span><br>
<span style="font-family:monospace">retourne</span><br>
<span style="font-family:monospace">si &lt;condition&gt; alors &lt;instructions1&gt; sinon &lt;instructions2&gt; fsi</span><br>
<span style="font-family:monospace">tantque &lt;condition&gt; faire &lt;instructions&gt; ftantque</span></p>
<!--TOC section id="sec144" Les fonctions <span style="font-family:monospace">Xcas</span> utilisées en statistiques-->
<h2 id="sec144" class="section">10.5  Les fonctions <span style="font-family:monospace">Xcas</span> utilisées en statistiques</h2><!--SEC END --><p>
<span style="font-family:monospace">alea(n1,n2)</span> : renvoie un réel aléatoire de [n1,n2[.<br>
<span style="font-family:monospace">alea(n)</span> : renvoie un entier aléatoire entre 0 et <span style="font-family:monospace">n-1</span>.
<br>
<span style="font-family:monospace">binomial</span> : peut être employé comme option de la commande <span style="font-family:monospace">randvector</span>.<br>
<span style="font-family:monospace">binomial_cdf(n,p,x1,x2)</span> : renvoie Proba(x1&lt;=X&lt;=x2) quand X suit la loi 
binomiale B(n,p).<br>
<span style="font-family:monospace">mean</span> : renvoie la moyenne d’une liste ou d’une liste pondérée par le 
deuxième argument.<br>
<span style="font-family:monospace">median</span> : renvoie la médiane d’une liste ou d’une liste pondérée par 
le deuxième argument.<br>
<span style="font-family:monospace">plotlist</span> : lorsque l’argument est <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>L</mi><mo>=</mo><mo stretchy="false">[</mo><msub><mi>y</mi> <mn>0</mn></msub><mo>,</mo><mo>.</mo><mo>.</mo><mo>.</mo><mo>,</mo><msub><mi>y</mi> <mi>n</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding='application/x-tex'>L=[y_0,...,y_n]</annotation></semantics></math>, trace la ligne 
polygonale reliant les points d’abscisse <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>k</mi></mrow><annotation encoding='application/x-tex'>k</annotation></semantics></math> et d’ordonnée <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msub><mi>y</mi> <mi>k</mi></msub></mrow><annotation encoding='application/x-tex'>y_k</annotation></semantics></math> pour 
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>k</mi><mo>=</mo><mn>0</mn><mo>.</mo><mo>.</mo><mi>n</mi></mrow><annotation encoding='application/x-tex'>k=0..n</annotation></semantics></math>.<br>
<span style="font-family:monospace">randvector</span> : renvoie une liste de nombres aléatoires de taille <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> 
constituée d’entiers aléatoires distribués selon la loi indiquée.<br>
<span style="font-family:monospace">stddev</span> : renvoie l’écart-type d’une liste ou d’une liste pondérée
par le deuxième argument.<br>

<a id="sec;python"></a></p>
<!--TOC chapter id="sec145" Premiers pas avec les interfaces de <span style="font-family:monospace">Xcas</span>-->
<h1 id="sec145" class="chapter">Annexe A  Premiers pas avec les interfaces de <span style="font-family:monospace">Xcas</span></h1><!--SEC END -->
<!--TOC section id="sec146" Les différentes intefaces-->
<h2 id="sec146" class="section">A.1  Les différentes intefaces</h2><!--SEC END --><p>
Vous pouvez utiliser <span style="font-family:monospace">Giac/Xcas</span> avec plusieurs interfaces différentes :
</p><ul class="itemize"><li class="li-itemize">
<span style="font-family:monospace">Xcas</span> natif sur PC Windows ou Linux et sur Mac<br>
Pour cela il faudra installer <span style="font-family:monospace">Xcas</span> sur votre machine en suivant les 
instructions de la sous section <a href="#sec%3APcMac">A.3</a>.
</li><li class="li-itemize"><span style="font-family:monospace">Xcas</span> depuis votre navigateur (Firefox recommandé)<br>
Pour cela il suffira de se connecter une seule foisà Internet pour pouvoir
ensuite travailler dans Firefox en suivant les 
instructions de la sous section <a href="#sec%3AFirefox">A.2</a>.
</li><li class="li-itemize">depuis un interpréteur Python avec le module <span style="font-family:monospace">giacpy</span>,
cf. la section <a href="#sec%3Agiacpy">A.5</a>
</li><li class="li-itemize">En écrivant des documents interactifs comme celui-ci
<a href="https://www-fourier.ujf-grenoble.fr/~parisse/tice.html">en L<sup>A</sup>T<sub>E</sub>X</a>.
</li></ul><p>
A vous de choisir!</p>
<!--TOC section id="sec147" Avec <span style="font-family:monospace">Xcas</span> pour Firefox-->
<h2 id="sec147" class="section">A.2  Avec <span style="font-family:monospace">Xcas</span> pour Firefox</h2><!--SEC END --><p><a id="sec:Firefox"></a>
Depuis votre navigateur (il est conseillé 
d’utiliser Firefox pour des performances
optimales) ouvrez le lien<br>
<a href="http://www-fourier.ujf-grenoble.fr/%7eparisse/xcasfr.html">http://www-fourier.ujf-grenoble.fr/~parisse/xcasfr.html</a><br>
Lors de la première utilisation, vous êtes invités à choisir
entre la compatibilité de syntaxe Python ou la syntaxe <span style="font-family:monospace">Xcas</span> native.
Ceci peut être modifié ultérieurement en cliquant sur le bouton
<span style="font-family:monospace">Config</span> en haut à gauche.</p><p>La ligne de commande se trouve en bas de page, au-dessus se trouve
une ligne de boutons assistants
</p><ul class="itemize"><li class="li-itemize">
<code>123</code> permet d’afficher un clavier scientifique
</li><li class="li-itemize"><code>?</code> affiche une aide sur la commande ou le début de commande
à l’endroit du curseur
</li><li class="li-itemize">deux flèches de direction pour déplacer le curseur
sur les smartphones ou tablettes
</li><li class="li-itemize"><code>sel</code> pour sélectionner la ligne de commande
</li><li class="li-itemize"><code>math</code> qui affiche des assistants mathématique
</li><li class="li-itemize"><code>prog</code> qui affiche des assistants de programmation
<ul class="itemize"><li class="li-itemize">
<code>test</code>: assistant pour créer un test (si alors sinon finsi)
</li><li class="li-itemize"><code>boucle</code>: assistant pour créer une boucle (tantque ou pour)
</li><li class="li-itemize"><code>fonct</code>: assistant pour créer une fonction
</li><li class="li-itemize"><code>debug</code>: insère la commande <code>debug(</code> pour mettre
au point un programme
</li><li class="li-itemize"><code>//</code> ou <code>#</code> pour commencer un commentaire sur la ligne actuelle
</li><li class="li-itemize"><code>\n</code> pour passer à la ligne
</li><li class="li-itemize"><code>del</code> pour effacer un caractère
</li><li class="li-itemize"><code>-&gt;/</code> pour indenter le source
</li></ul>
</li><li class="li-itemize"><code>ok</code> (ou touche Entree du clavier) 
pour valider la ligne de commande.
Pour passer à la ligne sur un clavier physique 
on peut taper simultanément sur shift et Entree.
La ligne de commande est alors évaluée et le résultat affiché
en face ou en-dessous. Il est possible de modifier une ligne de commande
existante et de la réexécuter.
</li></ul><p>
Vous pouvez sauvegarder une session, vous pouvez aussi l’envoyer par mail.
Le lien Clone permet de 
</p><ul class="itemize"><li class="li-itemize">
de cloner une session (par exemple en cas de crash)
</li><li class="li-itemize">en utilisant clic droit,
de recopier le lien correspondant sur une page web, on peut
ainsi indiquer le lien vers un début de session à des élèves.
</li><li class="li-itemize">toujours en utilisant clic droit, de recopier la session
vers <span style="font-family:monospace">Xcas</span> natif. Dans <span style="font-family:monospace">Xcas</span> natif sur PC, cliquer sur le numéro
de niveau où vous voulez insérer la session de <span style="font-family:monospace">Xcas</span> pour Firefox
(par exemple sur <span class="textboxed">1</span> pour le niveau 1)
puis faites la copie en tapant simultanément sur <span style="font-family:monospace">Ctrl</span> et <span style="font-family:monospace">V</span>.
</li></ul><p>
Pour plus de détails, vous pouvez cliquer sur le bouton <span style="font-family:monospace">Tutoriel</span> en
haut à gauche en-dessous du bouton <span style="font-family:monospace">Config</span>.</p>
<!--TOC section id="sec148" <span style="font-family:monospace">Xcas</span> natif sur PC Windows et Linux et sur Mac.-->
<h2 id="sec148" class="section">A.3  <span style="font-family:monospace">Xcas</span> natif sur PC Windows et Linux et sur Mac.</h2><!--SEC END --><p>
<a id="sec:PcMac"></a>
Pour installer Xcas suivez les instructions depuis:<br>
<a href="http://www-fourier.ujf-grenoble.fr/%7eparisse/install_fr.html">http://www-fourier.ujf-grenoble.fr/~parisse/install_fr.html</a><br>

Vous pouvez ensuite taper des commandes dans les lignes de commande
en utilisant les menus, en particulier le menu Outils qui contient
les commandes mathématiques de calcul les plus utilisées, à défaut
le menu Cmd qui les contient classées par thèmes, le menu Graph pour
les commandes de type graphes de fonction, le menu Geo pour la géométrie,
pour plus de détails voir le menu Aide, Débuter en calcul formel, Tutoriel.</p><p>Pour programmer, il est plus confortable d’ouvrir un niveau de programmes
depuis le menu Prg, nouveau programme. Un assistant de création de
fonction s’ouvre immédiatement (vous pouvez l’ignorer en tapant sur
la touche Echap). Un niveau de programme apparait avec son propre menu
et des boutons assistants Test, Boucle et Fonction pour vous aider
à saisir les structures de base de l’algorithmique. Une fois
votre programme saisi, vous l’interprétez en tapant sur le bouton
OK (raccourci clavier F9). S’il est correct, vous pouvez tester votre
fonction depuis une ligne de commande.</p><p>Vous pouvez cloner une session simple vers Xcas pour Firefox à
partir du menu Fich, Clone, Online.</p>
<!--TOC section id="sec149" Conseils pour adapter des scripts Python.-->
<h2 id="sec149" class="section">A.4  Conseils pour adapter des scripts Python.</h2><!--SEC END --><p>
De nombreuses ressources Python d’algorithmique lycée
n’utilisent pas de sortie graphique et fonctionneront sans
changement avec <span style="font-family:monospace">Xcas</span>. Si ce n’est pas le cas :
</p><ul class="itemize"><li class="li-itemize">
Vérifiez que les délimiteurs de chaines de caractères
sont bien des <code>"</code> et non des <code>'</code>, si nécessaire
remplacez-les (N.B. si une chaine délimitée par des <code>'</code> contient
des <code>"</code>, remplacez-les par <code>\"</code>).
</li><li class="li-itemize">Les commandes agissant sur les listes ou les chaines de caractères
sont presque toutes compatibles. Attention toutefois <code>L:=[1,2];5*L</code>
renvoie <code>[5,10]</code> en <span style="font-family:monospace">Xcas</span> (utiliser <code>flatten(seq(L,5))</code>), 
et <code>L+l</code> renvoie <code>[2,4]</code> (utiliser <code>concat(L,l)</code>)
</li><li class="li-itemize">Les commmandes d’<code>import</code> sont ignorées par Xcas, sauf
la commande <code>from turtle import *</code> qui
affecte dans des variables de nom les raccourcis de commandes en anglais 
leurs équivalents français. Mais il est sans doute plus
simple d’utiliser directement les commandes en français !
</li><li class="li-itemize">Si le script utilise les modules math, cmath, random, 
il n’est pas nécessaire de les importer, les commandes sont
déjà connues dans <span style="font-family:monospace">Xcas</span>, vous pouvez donc simplifier le script.
</li></ul><p>
Pour les scripts utilisant des commandes graphiques du module
matplotlib, il faudra utiliser à la place des commandes 
graphiques de Xcas que vous trouverez
depuis le menu <code>Graphe</code> ou <code>Geo</code>,
par exemple :
</p><ul class="itemize"><li class="li-itemize">
<code>point(x,y)</code> trace le point de coordonnées <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mo stretchy="false">(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy="false">)</mo></mrow><annotation encoding='application/x-tex'>(x,y)</annotation></semantics></math>
</li><li class="li-itemize"><code>droite(A,B)</code> ou <code>droite(equation)</code> trace
une droite, <code>segment(A,B)</code> un segment, avec <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>A</mi></mrow><annotation encoding='application/x-tex'>A</annotation></semantics></math> et <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>B</mi></mrow><annotation encoding='application/x-tex'>B</annotation></semantics></math> 2 points
(ou deux affixes de point)
</li><li class="li-itemize"><code>plotlist(l)</code> affiche une ligne polygonale reliant
les points d’abscisse 0, 1, ... et d’ordonnées les éléments de la
liste <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>l</mi></mrow><annotation encoding='application/x-tex'>l</annotation></semantics></math>, <code>plotlist(X,Y)</code> relie les points d’abscisses de
la liste <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>X</mi></mrow><annotation encoding='application/x-tex'>X</annotation></semantics></math> et d’ordonnée de la liste <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>Y</mi></mrow><annotation encoding='application/x-tex'>Y</annotation></semantics></math>, 
<code>polygonscatterplot(X,Y)</code> fait de même et marque les points
</li><li class="li-itemize"><code>histogram</code> et <code>bar_plot</code> servent à faire
des graphes statistiques
</li><li class="li-itemize"><code>plot</code> trace le graphe d’une fonction
</li><li class="li-itemize">...
</li></ul>
<!--TOC section id="sec150" Python et giacpy-->
<h2 id="sec150" class="section">A.5  Python et giacpy</h2><!--SEC END --><p> <a id="sec:giacpy"></a>
Une partie des programmes en syntaxe Python de ce document peuvent
s’exécuter dans un interpréteur Python, après avoir chargé
le module <code>giacpy</code>. Il faut d’abord installer
ce module sur votre PC, en suivant les instructions ici:<br>
<a href="https://www-fourier.ujf-grenoble.fr/%7eparisse/giac_fr.html#python">https://www-fourier.ujf-grenoble.fr/~parisse/giac_fr.html#python</a><br>
Ensuite le chargement se fait par la ligne de commande<br>
<code>from giacpy import *</code><br>
Les commandes de <span style="font-family:monospace">Xcas</span> en anglais
sont en général accessibles depuis l’interpréteur
Python, mais il faut parfois faire des ajustements :
</p><ul class="itemize"><li class="li-itemize">
Pour avoir une variable symbolique, par exemple <code>x</code>, 
on écrira <code>x=giac('x')</code>
</li><li class="li-itemize">Pour afficher un objet géométrique ou un graphe de fonction,
on utilise la méthode <code>qcas()</code>, par exemple
<code>c=circle(0,1)</code> puis <code>c.qcas()</code>
</li><li class="li-itemize">Il ne faut pas oublier que la puissance est <code>**</code> et les règles
propres à Python pour la division d’entiers
</li></ul>
<!--TOC chapter id="sec151" Xcas, Python et Javascript.-->
<h1 id="sec151" class="chapter">Annexe B  Xcas, Python et Javascript.</h1><!--SEC END -->
<!--TOC section id="sec152" Le mode de compatibilité Python de Xcas-->
<h2 id="sec152" class="section">B.1  Le mode de compatibilité Python de Xcas</h2><!--SEC END --><p> <a id="sec:python"></a>
Xcas accepte une syntaxe compatible avec le langage <span style="font-family:monospace">Python</span>. 
La principale différence entre la programmation en français
et Python, c’est qu’il n’y a
pas de fin de bloc explicite en Python, c’est l’indentation qui joue
ce rôle. L’indentation consiste à ajouter au début de chaque 
ligne d’un même bloc le même nombre d’espaces.
Il est recommandé d’indenter les programmes en mode Xcas, en
mode Python c’est obligatoire.
Il faut donc faire attention :
</p><ul class="itemize"><li class="li-itemize">
lorsqu’on copie un programme <span style="font-family:monospace">Python</span> avec un copier-coller : cela 
risque de modifier l’indentation,
</li><li class="li-itemize">lorsqu’on écrit un texte contenant un programme <span style="font-family:monospace">Python</span>
de faire en sorte que ce programme apparaisse sur une seule page (ce qui 
n’est pas toujours possible pour un programme contenant beaucoup 
d’instructions !).
</li></ul><p>
Attention, le mode de compatibilité Python de Xcas n’est pas identique
à Python. Seules les constructions de base sont acceptées (pas de
programmation orientée objet)  :
</p><ul class="itemize"><li class="li-itemize">
<span style="font-family:monospace">def</span> pour définir une fonction,
</li><li class="li-itemize"><span style="font-family:monospace">if</span> pour un test, 
</li><li class="li-itemize"><span style="font-family:monospace">for</span> pour une boucle pour, 
</li><li class="li-itemize"><span style="font-family:monospace">while</span> pour une boucle tantque.
</li></ul><p>
Certaines commandes Xcas sont compatibles avec Python, par exemple
<span style="font-family:monospace">range</span>, <span style="font-family:monospace">assert</span>, <span style="font-family:monospace">random</span>, etc.
Notez que :
</p><ul class="itemize"><li class="li-itemize">
il est recommandé de déclarer explicitement les variables
locales (avec <span style="font-family:monospace"># local &lt;nom-var&gt;</span>). 
</li><li class="li-itemize">les chaînes de caractères sont délimitées par <span style="font-family:monospace">"</span> car 
dans <span style="font-family:monospace">Xcas</span> on réserve <span style="font-family:monospace">’</span> pour quoter un argument c’est à dire 
pour ne pas évaluer un argument, par exemple :<br>
<span style="font-family:monospace">"a"</span> désigne la lettre <span style="font-family:monospace">a</span> (c’est une chaîne de 1 caractère),
et si <span style="font-family:monospace">a:=2+2</span> (ou en Python <span style="font-family:monospace">a=2+2</span>)
<span style="font-family:monospace">a</span> renvoie <span style="font-family:monospace">4</span> alors que <span style="font-family:monospace">’a’</span> désigne la 
variable <span style="font-family:monospace">a</span> non évaluée et donc <span style="font-family:monospace">’a’</span> renvoie le nom <span style="font-family:monospace">a</span> de la 
variable <span style="font-family:monospace">a</span> (ce n’est pas une chaîne de 1 caractère, c’est un 
identificateur).<br>
On aura par exemple :<br>
<span style="font-family:monospace">"a"+3</span> renvoie <span style="font-family:monospace">"a3"</span> mais<br>
si <span style="font-family:monospace">a:=4</span> alors <span style="font-family:monospace">’a’+3</span> renvoie <span style="font-family:monospace">3+a</span> et <span style="font-family:monospace">a+3</span> renvoie <span style="font-family:monospace">7</span><br>
<span style="font-family:monospace">type("a")</span> renvoie <span style="font-family:monospace">string</span> (chaîne de caractères)<br>
<span style="font-family:monospace">type(a)</span> renvoie <span style="font-family:monospace">integer</span> (<span style="font-family:monospace">a</span> contient un entier)<br>
<span style="font-family:monospace">type(’a’)</span> renvoie <span style="font-family:monospace">identifier</span> (<span style="font-family:monospace">’a’</span> est un nom de variable).
</li><li class="li-itemize">les commandes graphiques des librairies Python 
ne sont pas implentées, il faut utiliser les commandes de Xcas
(par exemple <code>plot</code>, <code>plotlist</code>, <code>histogram</code>, ...)
</li><li class="li-itemize">les chaines de caractères peuvent être modifiées caractère
par caractère, comme les listes.
</li><li class="li-itemize">la taille des listes s’ajuste automatiquement lors d’une affectation
à un indice au-delà de la taille actuelle de la liste
</li><li class="li-itemize">Si on écrit un programme dans lequel l’utilisateur doit saisir des 
données, on utilise soit la commande <span style="font-family:monospace">saisir(a)</span> (ou <span style="font-family:monospace">input(a)</span>) pour 
saisir une expression, soit <span style="font-family:monospace">saisir_chaine(s)</span> (ou <span style="font-family:monospace">textinput(s)</span>) 
pour saisir une chaîne de caractères, alors que’en Python <span style="font-family:monospace">input</span>
renvoie une chaîne de caractères qu’il faut affecter dans une variable
</li><li class="li-itemize">il n’y a pas besoin d’importer de bibliothèques 
(import math, import random, etc...), 
</li></ul><p><span style="font-weight:bold">Exemple</span> :
On veut faire un programme qui teste si un 
nombre est parfait : un entier naturel <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> est parfait si il est égal à la 
somme de ses diviseurs (1 compris, <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> non compris).</p><p>On écrit la fonction <span style="font-family:monospace">Parfait</span> qui a comme argument un entier <span style="font-family:monospace">n</span>.<br>
On définit les variables locales à la fonction :
</p><ul class="itemize"><li class="li-itemize">
<span style="font-family:monospace">s</span> qui recevra la somme des diviseurs de <span style="font-family:monospace">n</span>.
au début <span style="font-family:monospace">s</span> est nul.
</li><li class="li-itemize"><span style="font-family:monospace">j</span> qui parcourt les diviseurs potentiels, 
</li></ul><p>
Pour tous les entiers <span style="font-family:monospace">j</span> entre <span style="font-family:monospace">1</span> et <span style="font-family:monospace">n-1</span> on teste si 
<span style="font-family:monospace">j</span> divise <span style="font-family:monospace">n</span> et pour cela on cherche le reste de la division
de <span style="font-family:monospace">n</span> par <span style="font-family:monospace">j</span>, c’est <span style="font-family:monospace">irem(n,j)</span> ou <span style="font-family:monospace">n%j</span> 
qui renvoie ce reste.
Si le reste est nul, c’est que <span style="font-family:monospace">j</span> divise <span style="font-family:monospace">n</span> donc on ajoute
<span style="font-family:monospace">j</span> à <span style="font-family:monospace">s</span>.
Quand <span style="font-family:monospace">j</span> a parcouru tous les entiers jusque <span style="font-family:monospace">n-1</span> (i.e. quand la 
boucle <span style="font-family:monospace">pour</span> est terminée), on teste si <span style="font-family:monospace">s</span> 
est égal à <span style="font-family:monospace">n</span>. Si il y a égalité alors <span style="font-family:monospace">n</span> est parfait, sinon 
<span style="font-family:monospace">n</span> n’est pas parfait.</p><p>Une implémentation en syntaxe Xcas en français :

</p><pre class="verbatim">fonction Parfait(n)
  local j,s;
  "Parfait(n) renvoie vrai si n est la somme de ses diviseurs";
  s:=0;
  pour j de 1 jusque n-1 faire
    si irem(n,j)==0 alors
      s:=s+j; // j divise n, on l'ajoute a la somme
    fsi;
  fpour;
  si s==n alors // on pourrait aussi recrire return s==n
    retourne vrai;
  sinon
    retourne faux;
  fsi;
ffonction:;  
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Parfait(6)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>

L’indentation permet de visualiser facilement la forme du programme, ici on a 
3 instructions : 1 affectation, 1 boucle <span style="font-family:monospace">pour</span> qui contient une instruction
(1 test si) et 1 test si/sinon.
L’indentation sert aussi à contrôler qu’on n’a pas fait
de faute de syntaxe (non-fermeture d’une parenthèse par exemple).
En syntaxe compatible Python, le programme <span style="font-family:monospace">Parfait</span> 
précédent s’écrit :

</p><pre class="verbatim">def Parfait(n):
    # local j,s
    '''Parfait(n) determine si l'entier n est la somme de ses diviseurs'''
    s=0
    for j in range(1,n):
        if n%j==0: 
            s=s+j # j divise n, on l'ajoute
    if s==n:
        return True
    else:
        return False 
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>



<textarea onkeypress="UI.ckenter(event,this,1)" 
style="width:400px;font-size:large">Parfait(24)
</textarea><button onclick="previousSibling.style.display='inherit';var tmp=UI.caseval(previousSibling.value);tmp=UI.rmquote(tmp); nextSibling.innerHTML='&nbsp;'+tmp;UI.render_canvas(nextSibling);">ok</button><span></span><br>
</p>
<!--TOC section id="sec153" Xcas et Javascript-->
<h2 id="sec153" class="section">B.2  Xcas et Javascript</h2><!--SEC END --><p>
Javascript<a id="hevea_default129"></a> est le langage des navigateurs, il est donc
extrêmement répandu et peut être utilisé
sans installation sur PC/Mac. De ce fait, un programme
écrit en javascript pourra facilement 
être intégré dans une petite interface
utilisateur en HTML (voir l’exemple ci-dessous), 
et exécuté depuis n’importe
quel autre navigateur, ce qui peut être assez 
motivant. <br>
Du point de vue des types
de variables utilisables, on dispose entre autres
de nombres approchés,
de chaines de caractères et de listes, il n’y a pas de type
particulier pour les entiers. Les structures de controle ont une
syntaxe proche du langage C, point-virgule en fin d’instruction,
délimiteurs de blocs explicites <code>{}</code>, test en 
<code>if () { ... } else { ... }</code> et boucle en
<code>for(init;condition;incrementation){...}</code> 
ou <code>while(condition){...}</code>, déclaration de variable
par <code>var</code> et retour de fonction par <code>return</code>. <br>
Si vous connaissez javascript, vous pouvez utiliser une syntaxe très
proche dans <span style="font-family:monospace">Xcas</span>. Exemple, syntaxe utilisable dans les
deux langages pour le calcul du <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math>-ième nombre de Fibonacci :

</p><pre class="verbatim">function fibo(n){
  var u,v,w,j;
  u=1; v=1;
  if (n&lt;2) return 1;
  for (j=2;j&lt;=n;j++){
    w=u+v; u=v; v=w; // ou en Xcas (u,v)=(v,u+v);
  }
  return v;
}
</pre><p> 
<button onclick="var field=parentNode.previousSibling; var tmp=field.innerHTML;if(tmp.length==0) tmp=field.value;var t=createElement('TEXTAREA');t.style.fontSize=16;t.cols=60;t.rows=10;var tmp1=UI.ltgt(tmp);t.value=tmp1[0];tmp=UI.caseval(tmp);tmp=UI.rmquote(tmp);nextSibling.innerHTML=tmp; UI.render_canvas(nextSibling.innerHTML); field.parentNode.insertBefore(t,field);field.parentNode.removeChild(field);">ok</button><span></span><br>


Pour avoir une interface HTML minimaliste pour cette fonction,
on crée un fichier nommé disons <code>fibo.html</code> (que l’on
consultera depuis un navigateur) contenant :
</p><pre class="verbatim">&lt;script&gt;
function fibo(n){
  var u,v,w,j;
  u=1; v=1;
  if (n&lt;2) return 1;
  for (j=2;j&lt;=n;j++){
    w=u+v; u=v; v=w; 
  }
  return v;
}
&lt;/script&gt;
Le 
&lt;textarea cols="5" rows="1" id="input" 
onkeypress="if (event.keyCode!=13) return true; 
document.getElementById('output').value=fibo(eval(value)); 
return false;"&gt;5&lt;/textarea&gt;
i&amp;egrave;me nombre de Fibonacci est
&lt;textarea rows="1" id="output"&gt;&lt;/textarea&gt;
</pre><p>
On peut utiliser les commandes de <span style="font-family:monospace">Xcas</span> depuis Javascript, c’est exactement
ce que fait l’interface <span style="font-family:monospace">Xcas</span> pour Firefox.</p>
<!--TOC section id="sec154" Xcas et Python-->
<h2 id="sec154" class="section">B.3  Xcas et Python</h2><!--SEC END --><p>
Python<a id="hevea_default130"></a> est un langage assez populaire
dans les milieux scientifiques et est facile à installer.
Il possède un type spécifique pour les entiers. 
Sa principale différence par rapport aux autres langages est
que les structures de controle n’ont pas de délimiteur explicite
de fin de bloc, c’est l’indentation qui joue ce role. L’obligation
d’indenter correctement a certaines vertus pédagogiques, mais 
pas l’absence de délimiteur explicite de fin de bloc. Ceci rend aussi
l’échange de code source Python avec des applications orientées
texte (copier/coller, mail, forums, traitement de texte) 
plus fragile<sup><a id="text5" href="#note5">1</a></sup>, 
ou même la lecture difficile si le code est affiché sur 
plus qu’une page. Si on modifie du code existant, par exemple
pour placer une boucle dans une autre ou dans un test, devoir réindenter
le code est une source d’erreur potentielle (d’où l’intérêt
d’avoir quelques espaces en réserve, ce qui explique
sans doute la recommandation d’utiliser 4 espaces pour indenter).
De plus, la déclaration
de variables locales dans une fonction
est implicite, ce qui n’est pas très pédagogique.
D’autre part, la syntaxe de la boucle
for en Python utilise des objets plus abstraits (itérateurs)
ou qui peuvent être inutiles (liste d’entiers en Python 2), elle
s’éloigne de celle de la grande majorité des
autres langages, y compris la traduction en langage machine.
Ainsi l’exemple de Fibonacci donne
</p><pre class="verbatim">def fibo(n):
    u=1 
    v=1
    if n&lt;2:
        return 1
    for j in range(2,n+1):
        w=u+v  # ou directement u,v=v,u+v
        u=v 
        v=w 
    return v
</pre>
<!--TOC section id="sec155" Comparaison rapide-->
<h2 id="sec155" class="section">B.4  Comparaison rapide</h2><!--SEC END --><p>
La principale différence entre les 3 langages, c’est que <span style="font-family:monospace">Xcas</span>
est un logiciel de calcul formel et permet 
de travailler avec des variables symboliques et des
expressions. Dans <span style="font-family:monospace">Xcas</span>, une variable globale 
peut ne pas avoir de valeur (son évaluation la renvoie),
ce n’est pas le cas en Javascript ou en Python (l’évaluation
d’une variable non initialisée renvoie une erreur). De ce fait,
il ne faut pas oublier de déclarer les variables locales
d’une fonction pour éviter des erreurs. En contrepartie pour
réaliser des fonctions comme la dichotomie ou la recherche
d’une valeur approchée d’intégrale par la méthode des 
rectangles,
on peut passer une expression symbolique en paramètre et
l’évaluer en un point, ce qui est conceptuellement plus 
simple que de passer une
fonction en argument à une autre fonction.
Avec <span style="font-family:monospace">Xcas</span>, on peut aussi faire du calcul symbolique à l’intérieur
d’une fonction, par exemple dériver une expression, calculer
des valeurs exactes ou approchée, et dans ce dernier cas travailler
avec un nombre arbitraire de décimales.</p><p>Des trois langages, Javascript est le plus rapide,
puis Python puis <span style="font-family:monospace">Xcas</span>.</p>
<!--BEGIN NOTES chapter-->
<hr class="footnoterule"><dl class="thefootnotes"><dt class="dt-thefootnotes">
<a id="note5" href="#text5">1</a></dt><dd class="dd-thefootnotes"><div class="footnotetext">Ainsi, l’exercice
de spécialité du sujet de bac S
2017 centres etrangers demande aux candidats d’interpréter un algorithme
écrit en syntaxe Python sans délimiteurs de blocs explicites ... et
l’un des blocs est mal indenté, très probablement au cours
d’un passage par un logiciel de traitement de texte</div></dd></dl>
<!--END NOTES-->
<!--TOC chapter id="sec156" Les biais des langages interprétés-->
<h1 id="sec156" class="chapter">Annexe C  Les biais des langages interprétés</h1><!--SEC END --><p>Les ordinateurs n’exécutent pas directement les instructions
données dans un langage comme <span style="font-family:monospace">Xcas</span>, Javascript, Python, C, Pascal, etc.,
ils exécutent uniquement du code machine spécifique au micro-processeur
de l’ordinateur. Il y a deux façons de traduire le langage en
code machine : soit une fois pour toutes lors d’une étape
appelée compilation, soit au moment de l’exécution de l’instruction
du langage par l’interpréteur (qui est lui-même un 
programme écrit dans un langage compilé), on parle alors de langage 
interprété (en toute rigueur, il existe une
troisième possibilité un peu intermédiaire qui consiste à compiler
au moment où on exécute l’instruction du langage).</p><p>Les langages interprétés sont par nature plus faciles à 
mettre en oeuvre (pas de compilation) et de ce fait
rendent l’apprentissage plus simple. Mais la traduction au moment
de l’exécution a bien entendu un impact sur le temps d’exécution,
parce que les boucles sont traduites autant de fois
qu’elles sont exécutées (des optimisations peuvent
y remédier plus ou moins, il est d’ailleurs fort possible
que la syntaxe de la boucle <code>for</code> en Python soit liée
à des considérations d’optimisation).
De plus, les langages interprétés
utilisent des variables dont le type est déterminé
au moment de l’exécution du code, ce qui a un impact aussi
bien pour la taille occupée par la variable que pour l’exécution
d’une opération qui doit commencer par déterminer le type des
arguments pour agir en conséquence. Enfin,
lorsqu’on utilise un langage compilé, on a accès
aux types de données directement manipulables par le 
microprocesseur, dont la place occupée en mémoire est optimale 
et le temps d’exécution très rapide,
par exemple on peut multiplier deux entiers dont le produit est
inférieur à <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><msup><mn>2</mn> <mn>63</mn></msup></mrow><annotation encoding='application/x-tex'>2^{63}</annotation></semantics></math> en moins d’un milliardième de seconde.</p><p>Bien entendu, on peut améliorer le temps d’exécution
avec un langage interprété si certaines taches répétitives
sont codées dans une instruction du langage, par exemple
l’instruction effectuant le produit de deux matrices n’est pas 
programmé dans le langage interprété lui-même mais est compilé
une fois pour toutes dans le code exécutable de l’interpréteur. 
Le programmeur qui souhaite avoir un code suffisamment rapide va
donc adopter un style de programmation qui favorisera l’utilisation
de commandes du langage effectuant en une seule instruction ce
qui nécessiterait une ou plusieurs boucles imbriquées
si on le programmait uniquement avec les
instructions de base d’un langage compilé. 
C’est pour cette raison
que les programmeurs expérimentés travaillant avec un 
langage interprété écrivent souvent dans un style
“algébrique” avec le moins possible de structures de controle explicites
et des types de données souvent assez complexes.
Par exemple pour écrire un produit scalaire de deux listes en <span style="font-family:monospace">Xcas</span>,
on utilisera la commande <code>dot</code>, si elle n’existait pas, on
pourrait écrire <code>sum(x[j]*y[j],j,0,size(x)-1)</code> pour éviter
de faire une boucle <code>pour</code>, le chapitre statistiques <a href="#chap%3Astats">8</a> 
contient quelques exemples d’optimisation de ce type. 
Pour des commandes plus compliquées,
on utilisera sans doute des commandes <code>seq</code> imbriquées au lieu
de boucles.
Mais ce style présente un risque, celui de calculer
plusieurs fois la même quantité : une expression algébrique
n’a pas de variables locales pour stocker de résultats 
intermédiaires. 
Il faut donc prendre garde au biais de ne
pas calculer des quantités intermédiaires.
Ce n’est pas le seul biais, 
il faut également faire attention à l’utilisation
d’instructions faisant des boucles implicitement et
à l’utilisation de types de données puissants qui risquent de masquer
la complexité des opérations nécessaires et pourraient être
remplacés par des types plus simples, par exemple
utiliser un dictionnaire (ou annuaire) 
alors qu’un tableau ferait l’affaire.
Un exemple avec la recherche de nombres premiers plus petits que
<math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> par crible, écrit de deux manières
</p><pre class="verbatim">def premiers1(n):
    prem=list(range(2,n+1))
    k=2
    nRacine=n**0.5
    while k&lt;nRacine :
        prem=[p for p in prem if p&lt;=k or p%k!=0]
        k=prem[prem.index(k)+1]   # nouveau nombre premier
    return prem

def premiers2(n):
    prem=list(range(0,n))
    k=2
    while k*k&lt;n :
        for j in range(2*k,n,k): # on barre les multiples de k
            prem[j]=0
        k += 1
        while prem[k]==0: k += 1 # cherche le premier non barre
    res=[]  
    for k in prem:
        if k!=0: res.append(k) # on garde les 0 uniquement
    return res
</pre><p>
<code>premiers2</code> est un crible, il n’effectue aucune division
et travaille sur une seule liste (plus une deuxième à la fin
pour garder uniquement les nombres premiers).
<code>premiers1</code> a un code plus compact, mais il effectue des divisions
pour tester la primalité
et recrée une liste à chaque itération, et est donc significativement
plus lent, par exemple pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi><mo>=</mo></mrow><annotation encoding='application/x-tex'>n=</annotation></semantics></math><code>10**6</code>, il prend presque 
10 fois plus de temps.</p><p>D’ailleurs d’un point de vue
pédagogique il est toujours bon de savoir ce qu’il y a derrière une boite
noire lorsque c’est accessible au niveau de l’élève ou de l’étudiant. 
De plus le style algébrique
est certes compact, mais il est souvent plus difficile à maintenir 
(aussi bien à relire qu’à corriger), 
et il peut aussi générer une occupation mémoire inutile : par
exemple en simulation, générer une grosse matrice de nombre aléatoires
alors qu’une boucle agissant sur des lignes de cette matrice générées
une par une et effacées après usage est incomparablement
moins gourmand en mémoire.</p><p>Enfin, l’optimisation d’un code destiné à être vraiment utilisé
nécessite souvent la compilation des parties critiques, et l’optimisation
de ces parties critiques se fait souvent de manière différente et
parfois opposée aux habitudes acquises en optimisant du code interprété.
Illustrons cela plus en détails
sur un exemple très utile en mathématique: le produit
scalaire de deux vecteurs et le produit d’une matrice
par un vecteur. Il s’agit d’une boucle <code>pour</code>
que l’on code par
</p><pre class="verbatim">fonction ps(u,v)
 local r,j,n
 r:=0;
 pour j de 0 jusque n-1 faire
  r:=r+u[j]*v[j];
 fpour;
 return r;
ffonction
</pre><p>
On peut optimiser en utilisant l’instruction d’incrémentation
<code>r += u[j]*v[j];</code> au lieu de <code>r:=r+u[j]*v[j];</code>.</p><p>Traduit dans un langage compilé, 
ce code n’est pas loin d’être optimal, 
par exemple en C++ :
</p><pre class="verbatim">double ps(const vector&lt;double&gt; &amp; u,const vector&lt;double&gt; &amp; v){
  size_t j,n=u.size();
  double r=0;
  for (j=0;j&lt;n;j++){
    r += u[j]*v[j];
  }
  return r;
}
</pre><p>
Les variables <code>r,j,n</code> sont stockées dans des régistres
du microprocesseur. Par itération, 
il y a 2 additions d’entiers 64 bits 
(adresse de base des vecteurs et valeur de l’indice), 2 lectures
en mémoire de 8 octets (<code>u[j]</code> et <code>v[j]</code>),
puis une multiplication de flottants, une addition de flottant,
une incrémentation d’entier 64 bits (l’indice), une comparaison
entre 2 entiers 64 bits, un branchement. Ce qui prend le plus de
temps c’est la lecture en mémoire des double des
vecteurs <code>u</code> et <code>v</code>
et le branchement/test de fin de boucle.</p><p>En langage interprété, ce code sera beaucoup plus lent, car à chaque 
itération, pour déterminer la valeur de <code>u[j]</code> et <code>v[j]</code>, 
il faut évaluer la variable d’indice <code>j</code> (lue dans l’annuaire
des variables affectées), de même pour les variables <code>u</code>
et <code>v</code>, s’apercevoir que ce sont bien des tableaux, comparer <code>j</code>
à la taille de <code>u</code> et de <code>v</code> (erreur si l’indice est trop
grand), extraire la <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>j</mi></mrow><annotation encoding='application/x-tex'>j</annotation></semantics></math>-ième case
du tableau. Ensuite on fait le produit, ce qui nécessite de tester
le type des variables, on ajoute le résultat à <code>r</code> ce qui
nécessite à nouveau de tester le type des arguments de <code>+=</code>. 
Puis on incrémente <code>j</code> de 1 et on compare à <code>n</code> (qu’il
faut évaluer).
Pour diminuer les opérations de gestion de la boucle, 
certains langages interprétés
ont une instruction de boucle spécifique pour itérer sur
les éléments d’une liste, par exemple si on veut afficher les
éléments d’une liste au lieu de faire
</p><pre class="verbatim">fonction aff(u)
 local j,n
 pour j de 0 jusque n-1 faire
  afficher(u[j]);
 fpour;
ffonction;
</pre><p>
on écrira
</p><pre class="verbatim">fonction aff(u)
 local j;
 pour j in u faire
  afficher(j);
 fpour;
ffonction;
</pre><p>
Cette boucle est implémentée en interne par
une variable de longueur de la liste <code>n</code>, une autre 
d’indice, disons <code>k</code>,
et <code>j</code> est évalué par calcul de <code>u[k]</code>, mais
les opérations de gestion de la boucle 
sont pré-compilées et donc plus rapides.
Dans ce type de boucle, le code est plus compact et ne pose aucun
problème de maintenance.
Par contre, pour le produit scalaire,
faire la même chose nécessite d’introduire des objets plus
complexes : on peut imaginer générer la liste des paires
<code>u[j],v[j]</code>
puis itérer sur cette liste. Mais si on ne veut pas créer inutilement
en mémoire une liste de paires, cette liste doit être générée
de manière virtuelle (par exemple au moyen d’une paire de pointeurs
sur les tableaux <code>u</code> et <code>v</code>)
et il faut disposer d’une commande capable
de prendre en argument une liste virtuelle. Par exemple en Python 
on pourrait écrire <code>sum(i*j for i,j in zip(u,v))</code>. Un mécanisme
de création de liste virtuelle peut bien entendu avoir un intérêt
intrinsèque, mais il faut avoir conscience que les objets que
l’on manipule sont plus complexes que les listes (qui sont déjà
des objets non triviaux), et que l’utilisation de cet objet dans l’exemple du
produit scalaire pour optimiser une boucle est un artéfact
de langage interprété, et qu’il sera difficile d’optimiser plus avec
ce style de programmation. Il sera d’ailleurs plus facile d’optimiser
en langage compilé sans utiliser ce type d’objets.</p><p>Ainsi, il est possible d’optimiser la boucle du produit scalaire,
on peut pour <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>n</mi></mrow><annotation encoding='application/x-tex'>n</annotation></semantics></math> grand regrouper plusieurs itérations,
et gagner du temps sur les parties test/branchement, par exemple 2 par 2
</p><pre class="verbatim">double ps(const vector&lt;double&gt; &amp; u,const vector&lt;double&gt; &amp; v){
  size_t j,n=u.size();
  double r=0;
  n--;
  for (j=0;j&lt;n;j+=2){
    r += u[j]*v[j]+u[j+1]*v[j+1];
  }
  n++;
  for (;j&lt;n;j++){
    r += u[j]*v[j];
  }
  return r;
}
</pre><p>Et si on effectue le produit d’une matrice <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>M</mi></mrow><annotation encoding='application/x-tex'>M</annotation></semantics></math> par un vecteur <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>v</mi></mrow><annotation encoding='application/x-tex'>v</annotation></semantics></math>, on peut
optimiser le temps d’exécution en mutualisant la lecture des coefficients
de <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>v</mi></mrow><annotation encoding='application/x-tex'>v</annotation></semantics></math>, on fait plusieurs produits scalaires avec <math xmlns='http://www.w3.org/1998/Math/MathML' display='inline'><semantics><mrow><mi>v</mi></mrow><annotation encoding='application/x-tex'>v</annotation></semantics></math> simultanément.
</p><pre class="verbatim">double ps(const vector&lt;double&gt; &amp; u1,
  const vector&lt;double&gt; &amp; u2,const vector&lt;double&gt; &amp; v){
  size_t j,n=u1.size();
  double r1=0,r2=0;
  n--;
  for (j=0;j&lt;n;j+=2){
    double vj=v[j],vj1=v[j+1];
    r1 += u1[j]*vj+u1[j+1]*vj1;
    r2 += u2[j]*vj+u2[j+1]*vj1;
  }
  n++;
  for (;j&lt;n;j++){
    r1 += u1[j]*v[j];
    r2 += u1[j]*v[j];
  }
  return r;
}
</pre><p>
Ici en faisant 2 produits scalaires simultanément, 
on fait 6 lectures en mémoire au lieu de 8 pour 2 itérations.</p><p>Il nous parait donc essentiel pour un scientifique d’apprendre aussi
un langage pas trop éloigné de la machine, ou au moins
d’être capable de coder avec des objets de base.


</div>
<div id="controldiv" style="max-height: 400px; overflow:auto">
<span id="controlindex"></span>
<button title="Clone la derni&egrave;re commande ex&eacute;cut&eacute;ee vers Xcas en ligne" onclick="UI.clone()">Clone</button>
<button title="Efface la console" onclick="document.getElementById('output').innerHTML='';">Efface</button>
<button title="Increase console size" onclick="var field=document.getElementById('output'); var s=field.style.maxHeight; s=s.substr(0,s.length-2);s=eval(s)+20 ;if(s<innerHeight/2){s=s+'px';field.style.maxHeight=s; field=document.getElementById('maindiv'); s=field.style.maxHeight; s=s.substr(0,s.length-2);s=eval(s)-20; s=s+'px';field.style.maxHeight=s;}">+</button>
<button title="Decrease console size" onclick="var field=document.getElementById('output'); var s=field.style.maxHeight; s=s.substr(0,s.length-2);s=eval(s)-20 ; if(s>80){s=s+'px';field.style.maxHeight =s;field=document.getElementById('maindiv'); s=field.style.maxHeight; s=s.substr(0,s.length-2);s=eval(s)+20; s=s+'px';field.style.maxHeight=s;}">-</button>
<textarea title="Ligne de commande pour un calcul rapide" onkeypress="UI.ckenter(event,this,3)" style="width:400px;height:20px;font-size:large"></textarea><button  title="Evalue cellule precedente" onclick="UI.quick(this);">-></button><span></span>
&nbsp;&nbsp;<button onclick="var s=UI.caseval('restart;'); Module.print(s);" title="Reinitialise le moteur de calcul formel">Restart</button>
<button onclick="UI.exec(document.documentElement);" title='Cliquer ici pour executer toutes les commandes (attention cela peut etre long!)'>Exec. tout</button>
<canvas id='canvas' width=0 height=0   onmousedown="UI.canvas_pushed=true;UI.canvas_lastx=event.clientX; UI.canvas_lasty=event.clientY;"  onmouseup="UI.canvas_pushed=false;" onmousemove="UI.canvas_mousemove(event,'')"></canvas>
<div id="output" style="max-height: 80px; overflow:auto"></div>
</div>
</div>


<script language="javascript"> 
var Module = { 
        htmlcheck:true,
        htmlbuffer:'',
        ready:false,
        preRun: [],
        postRun: [],
        print: (function() {
          var element = document.getElementById('output');
          element.innerHTML='';// element.value = ''; // clear browser cache
          return function(text) {
            //console.log(text.charCodeAt(0));
            if (text.length==1 && text.charCodeAt(0)==12){ element.innerHTML=''; return; }
            if (text.length>=1 && text.charCodeAt(0)==2) {console.log('STX');Module.htmlcheck=false; htmlbuffer='';return;}
            if (text.length>=1 && text.charCodeAt(0)==3) {console.log('ETX');Module.htmlcheck=true; element.style.display='inherit'; element.innerHTML += htmlbuffer;htmlbuffer='';element.scrollTop = 99999; return;}
            if (Module.htmlcheck){
            // These replacements are necessary if you render to raw HTML 
             text = text.replace(/&/g, "&amp;");
             text = text.replace(/</g, "&lt;");
             text = text.replace(/>/g, "&gt;");
             text = text.replace('\n', '<br>', 'g');
             text += '<br>'
             element.style.display='inherit';
             element.innerHTML += text; // element.value += text + "\n";
             element.scrollTop = 99999; // focus on bottom
            } else htmlbuffer += text;
          };
        })(),
     canvas: document.getElementById('canvas'),};
Module['onRuntimeInitialized']=function(){ console.log('UI is ready'); Module.ready=true;}
</script>



<script async>
  var UI={
   detectmob:function() { 
    if( navigator.userAgent.match(/Android/i)
	|| navigator.userAgent.match(/webOS/i)
	|| navigator.userAgent.match(/iPhone/i)
	|| navigator.userAgent.match(/iPad/i)
	|| navigator.userAgent.match(/iPod/i)
	|| navigator.userAgent.match(/BlackBerry/i)
	|| navigator.userAgent.match(/Windows Phone/i)
      ) return true;
    else 
      return false;
   },
   readCookie:function(name) {
    if (window.localStorage){
      var tmp=localStorage.getItem(name);
      if (tmp!=null) return tmp;
    }
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
      var c = ca[i];
      while (c.charAt(0)==' ') c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
   },
  }
  var script = document.createElement("script");
  script.type = "text/javascript";
  var webAssemblyAvailable = false;
  if (Boolean(window.chrome)){
    if (!UI.detectmob()) webAssemblyAvailable =  window.location.href.substr(0,4)!='file';
  }
  else {
    var ua = window.navigator.userAgent;
    var old_ie = ua.indexOf('MSIE ');
    var new_ie = ua.indexOf('Trident/');
    if (!UI.detectmob() && old_ie<=-1 && new_ie<=-1)
      webAssemblyAvailable =!!window.WebAssembly;
  }
  if (webAssemblyAvailable){
`<    var ck=UI.readCookie('xcas_wasm');
    if (ck)
      webAssemblyAvailable=(ck=='1');
  }
  if (webAssemblyAvailable) // fixme: enable
    script.src =""+"giacwasm.js";
  else
    script.src  =""+"giac.js";
  document.getElementsByTagName("head")[0].appendChild(script);
</script>

""


<script language="javascript">
 var UI = {
  histcount:0,
  usemathjax:false,
  lastcmd:'',
  clone:function(){
    if (UI.lastcmd.length){
       var tmp=UI.giaceval('VARS(-1)');
       tmp=encodeURIComponent(tmp);
       var url='https://www-fourier.ujf-grenoble.fr/~parisse/xcasfr.html#+'+tmp+':;&+'+UI.lastcmd;
       console.log(url);
       window.open(url,'_blank');
    }
  },
  canvas_pushed:false,
  canvas_lastx:0,
  canvas_lasty:0,
  canvas_mousemove:function(event,no){
    if (UI.canvas_pushed){
      // Module.print(event.clientX);
      if (UI.canvas_lastx!=event.clientX){
        if (event.clientX>UI.canvas_lastx)
          giac3d('r'+no);
        else
          giac3d('l'+no);
        UI.canvas_lastx=event.clientX;
      }
      if (UI.canvas_lasty!=event.clientY){
        if (event.clientY>UI.canvas_lasty)
          giac3d('d'+no);
        else
          giac3d('u'+no);
        UI.canvas_lasty=event.clientY;
      }
    }
  },  
  count_newline:function(s){
    var ss=s.length,i,res=1;
    for (i=0;i<ss;i++){
      if (s[i]=='\n') res++;
    }
    return res;
  },
  ltgt:function(s){
    var ss=s.length,i,res='',c=0;
    for (i=0;i<ss-4;i++){
      if (s[i]=='\n') c++;
      if (s[i]!='&' || s[i+2]!='t' || s[i+3]!=';'){
        res += s[i];
        continue;
      }
      if (s[i+1]=='l'){
        res += '<';
        i +=3;
        continue;
      }
      if (s[i+1]=='g'){
        res += '>';
        i +=3;
        continue;
      }
      res += s[i];
    }
    for (;i<ss;i++) res+=s[i];
    return [res,c];
  },
  rmquote:function(tmp){
    var s=tmp.length;
    if (s>2 && tmp.charCodeAt(0)==34 && tmp.charCodeAt(s-1)==34)
      tmp=tmp.substr(1,s-2);
    return tmp;
  },
  quick:function(field){
    var tmp1=field.previousSibling.value;
    var tmp=UI.caseval(tmp1);
    tmp=UI.rmquote(tmp); 
    tmp=UI.latexeval(tmp);
    Module.print(String.fromCharCode(2));
    Module.print("<tt>");
    Module.print(tmp1);
    Module.print("</tt><br>&nbsp;&nbsp;");
    Module.print(tmp);
    Module.print("<br>");
    Module.print(String.fromCharCode(3));
    field.nextSibling.innerHTML='&nbsp;'+tmp;
   //UI.render_canvas(nextSibling);  
  },
  giaceval:function(text){
     if (!Module.ready){ window.setTimeout(UI.giaceval,100,text); return "Not ready";}
     var dogiaceval=Module.cwrap('caseval',  'string', ['string']);
     return dogiaceval(text);
  },
  caseval:function(text){
    UI.lastcmd=text;
    var s="non evalu&eacute;",err;
    try {
       s= UI.giaceval(text);
    } catch (err) { s=err.message;}
    var is_3d=s.length>5 && s.substr(0,5)=='gl3d ';
    if (is_3d){
	var n3d=s.substr(5,s.length-5);
	s = '<canvas id="gl3d_'+n3d+'" onmousedown="UI.canvas_pushed=true;UI.canvas_lastx=event.clientX; UI.canvas_lasty=event.clientY;" onmouseup="UI.canvas_pushed=false;" onmousemove="UI.canvas_mousemove(event,'+n3d+')" width=400 height=250></canvas>';
    }
    return s;
  },
  render_canvas:function(field){
   var n=field.id;
   if (n && n.length>5 && n.substr(0,5)=='gl3d_'){
    Module.print(n);
    var n3d=n.substr(5,n.length-5);
    giac3d(n3d);
    return;
   }
   var f=field.firstChild;
   for (;f;f=f.nextSibling){
     UI.render_canvas(f);
   }
  },
  eval_form: function(field){
    UI.giaceval('assume('+field.name.value+'=round('+field.valname.value+',12))');
    var s=UI.caseval(field.prog.value);
    var is_svg=s.substr(1,4)=='<svg';
    if (is_svg) field.parentNode.lastChild.innerHTML=s.substr(1,s.length-2);
    else field.parentNode.lastChild.innerHTML=s;
    UI.render_canvas(field.parentNode.lastChild);
  },
  latexeval:function(text){
    var tmp=text;
    if (tmp.length>5 && tmp.substr(0,5)=='gl3d_') return tmp;
    if (tmp.length>10 && tmp.substr(0,10)=='GIAC_ERROR') return '"'+tmp.substr(11,tmp.length-11)+'"';
    if (tmp.length>5 && tmp.substr(1,4)=='<svg') return tmp.substr(1,tmp.length-2);
    if (tmp.length>5 && tmp.substr(0,4)=='<svg') return tmp;
     if (UI.usemathjax){
       tmp=UI.giaceval('latex(quote('+tmp+'))');
       var dollar=String.fromCharCode(36);
       tmp=dollar+dollar+tmp.substr(1,tmp.length-2)+dollar+dollar;
       return tmp;
     }
     tmp=UI.giaceval('mathml(quote('+tmp+',1))');
     tmp=tmp.substr(1,tmp.length-2);
    return tmp;   
  },
  ckenter:function(event,field,mode){
    var key = event.keyCode;
    if (key != 13 || event.shiftKey) return true;
   if (mode==3){ UI.quick(field.nextSibling); event.preventDefault(); field.select(); return true; }
    var tmp=field.value;
   Module.print(tmp);
    tmp=UI.caseval(tmp);
    if (mode==1){
      tmp=UI.rmquote(tmp); 
   }
   if (mode==2){
     tmp=UI.latexeval(tmp);
   }
   field.nextSibling.nextSibling.innerHTML=tmp;
   UI.render_canvas(field.nextSibling.nextSibling);
   if (UI.usemathjax) MathJax.Hub.Queue(["Typeset",MathJax.Hub,field.nextSibling.nextSibling]);
   if (event.preventDefault) event.preventDefault();
    return false;
  },
  exec: function(field){
     if (field.nodeName=="BUTTON" && field.innerHTML!='Clone' && field.innerHTML!='Restart' && field.innerHTML!='Exec. tout' ){
        field.click();
        return;
     }
     var f=field.firstChild;
     while (f){
       UI.exec(f);
       f=f.nextSibling;
     }
   },
  execonload: function(field){
     var f=field.nextSibling;
     if (f && f.innerHTML=="onload" && field.nodeName=="BUTTON"){
        field.click();
        return;
     }
     f=field.firstChild;
     while (f){
       UI.execonload(f);
       f=f.nextSibling;
     }
   },
  textarealtgt: function(field){
     if (field.nodeName=="TEXTAREA"){
        var tmp=UI.ltgt(field.value);
        field.value=tmp[0];
        //field.style.height=20*(tmp[1]+1)+'px';
        field.rows=tmp[1]+1;
        //console.log(tmp,field.rows);
        return;
     }
     var f=field.firstChild;
     while (f){
       UI.textarealtgt(f);
       f=f.nextSibling;
     }
   }
 };
 window.onload = function(e){
   var isFirefox = typeof InstallTrigger !== 'undefined';   // Firefox 1.0+
   var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
  var ua = window.navigator.userAgent;
  var old_ie = ua.indexOf('MSIE ');
  var new_ie = ua.indexOf('Trident/');
  if ((!isFirefox && !isSafari) || (old_ie > -1) || (new_ie > -1) || window.chrome){
     UI.usemathjax=true;
     alert("Votre navigateur ne supporte MathML, on utilise MathJax pour l'affichage 2d.  Les calculs seraient plus rapides et les resultats seraient mieux affiches avec Firefox.");
  }
  if (UI.usemathjax){
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "file:///usr/share/javascript/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  }
  var elem= document.getElementById('controlindex');
  elem.innerHTML='<hr><a href="'+String.fromCharCode(35)+'sec1">Table</a>, <a href="'+String.fromCharCode(35)+'sec2">Index</a>'+elem.innerHTML;
  elem=document.getElementById('maindiv');
  if (elem.style.maxHeight=='500px')
    elem.style.maxHeight=(window.innerHeight-120)+'px';
  elem= document.getElementById('maindiv');
  elem.style.maxHeight=(window.innerHeight-150)+'px';
  giac3d = Module.cwrap('_ZN4giac13giac_rendererEPKc','number', ['string']);
  UI.giaceval('set_language(1);');
  //UI.giaceval('factor(x^4-1)');
  //UI.giaceval('sin(x+y)+f(t)');
  UI.textarealtgt(document.documentElement);
  UI.execonload(document.documentElement);
  document.getElementById('output').innerHTML='';
 // if (confirm('Executer les commandes?')) UI.exec(document.documentElement);
 };
</script>


</p><!--CUT END -->
<!--HTMLFOOT-->
<!--ENDHTML-->
<!--FOOTER-->
<hr style="height:2"></body>
</html>