rpn.cc 167 KB
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
// -*- mode:C++ ; compile-command: "g++-3.4 -I.. -g -c rpn.cc  -DIN_GIAC -DHAVE_CONFIG_H" -*-
#include "giacPCH.h"
/*
 *  Copyright (C) 2001,14 B. Parisse, Institut Fourier, 38402 St Martin d'Heres
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

using namespace std;
#include "rpn.h"
#include "symbolic.h"
#include "unary.h"
#include <algorithm>
#include "prog.h"
#include "usual.h"
#include "identificateur.h"
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#if !defined NSPIRE && !defined NUMWORKS
#include <dirent.h>
#ifndef __MINGW_H
#include <pwd.h>
#endif // MINGW
#endif // NSPIRE
#endif // UNISTD
#include "input_lexer.h"
#include "plot.h"
#include "tex.h"
#include "ti89.h"
#include "maple.h"
#include "misc.h"
#include "permu.h"
#include "intg.h"
#include "derive.h"
#include "sym2poly.h"
#include "input_parser.h"
#include "solve.h"
#include "subst.h"
#include "csturm.h"
#include "giacintl.h"

#ifdef GIAC_HAS_STO_38
#include "aspen.h"
//THPObj *EditMat(int);
#endif


#ifndef NO_NAMESPACE_GIAC
namespace giac {
#endif // ndef NO_NAMESPACE_GIAC

  string enmajuscule(const string & s){
    string res;
    string::const_iterator it=s.begin(),itend=s.end();
    for (;it!=itend;++it){
      if ((*it>='a') && (*it<='z'))
        res += char(*it-32);
      else
        res += char(*it);
    }
    return res;
  }

  string printasconstant(const gen & feuille,const char * sommetstr,GIAC_CONTEXT){
    return sommetstr;
  }
#ifdef RTOS_THREADX
  gen return_undef(const gen &,GIAC_CONTEXT){
    return undef;
  }
  static const char _rpn_s []="rpn";
  static define_unary_function_eval2 (__rpn,&return_undef,_rpn_s,&printasconstant);
  define_unary_function_ptr5( at_rpn ,alias_at_rpn ,(unary_function_eval*)&__rpn,0,true);

  static const char _alg_s []="alg";
  static define_unary_function_eval2 (__alg,&return_undef,_alg_s,&printasconstant);
  define_unary_function_ptr5( at_alg ,alias_at_alg ,(unary_function_eval *)&__alg,0,true);

  static const char _ROLL_s []="ROLL";
  static define_unary_function_eval (__ROLL,&return_undef,_ROLL_s);
  define_unary_function_ptr( at_ROLL ,alias_at_ROLL ,&__ROLL);

  static const char _ROLLD_s []="ROLLD";
  static define_unary_function_eval (__ROLLD,&return_undef,_ROLLD_s);
  define_unary_function_ptr( at_ROLLD ,alias_at_ROLLD ,&__ROLLD);

  static const char _SWAP_s []="SWAP";
  static define_unary_function_eval (__SWAP,&return_undef,_SWAP_s);
  define_unary_function_ptr5( at_SWAP ,alias_at_SWAP ,&__SWAP,0,T_RPN_OP);

  static const char _DUP_s []="DUP";
  static define_unary_function_eval (__DUP,&return_undef,_DUP_s);
  define_unary_function_ptr5( at_DUP ,alias_at_DUP ,&__DUP,0,T_RPN_OP);

  static const char _OVER_s []="OVER";
  static define_unary_function_eval (__OVER,&return_undef,_OVER_s);
  define_unary_function_ptr5( at_OVER ,alias_at_OVER ,&__OVER,0,T_RPN_OP);

  static const char _PICK_s []="PICK";
  static define_unary_function_eval (__PICK,&return_undef,_PICK_s);
  define_unary_function_ptr5( at_PICK ,alias_at_PICK ,&__PICK,0,T_RPN_OP);

  static const char _DROP_s []="DROP";
  static define_unary_function_eval (__DROP,&return_undef,_DROP_s);
  define_unary_function_ptr5( at_DROP ,alias_at_DROP ,&__DROP,0,T_RPN_OP);

  static const char _NOP_s []="NOP";
  static define_unary_function_eval2_index (136,__NOP,&return_undef,_NOP_s,&printasconstant);
  define_unary_function_ptr5( at_NOP ,alias_at_NOP ,&__NOP,0,T_RPN_OP);

  static const char _IFTE_s []="IFTE";
  static define_unary_function_eval2_index (126,__IFTE,&return_undef,_IFTE_s,&printasconstant);
  define_unary_function_ptr5( at_IFTE ,alias_at_IFTE ,&__IFTE,0,T_RPN_OP);

  static const char _RPN_LOCAL_s []="RPN_LOCAL";
  static define_unary_function_eval2_index (130,__RPN_LOCAL,&return_undef,_RPN_LOCAL_s,&printasconstant);
  define_unary_function_ptr5( at_RPN_LOCAL ,alias_at_RPN_LOCAL ,&__RPN_LOCAL,0,T_RPN_OP);

  static const char _RPN_FOR_s []="RPN_FOR";
  static define_unary_function_eval2_index (132,__RPN_FOR,&return_undef,_RPN_FOR_s,&printasconstant);
  define_unary_function_ptr5( at_RPN_FOR ,alias_at_RPN_FOR ,&__RPN_FOR,0,T_RPN_OP);

  static const char _RPN_WHILE_s []="RPN_WHILE";
  static define_unary_function_eval2_index (134,__RPN_WHILE,&return_undef,_RPN_WHILE_s,&printasconstant);
  define_unary_function_ptr5( at_RPN_WHILE ,alias_at_RPN_WHILE ,&__RPN_WHILE,0,T_RPN_OP);

  static const char _RPN_CASE_s []="RPN_CASE";
  static define_unary_function_eval2_index (128,__RPN_CASE,&return_undef,_RPN_CASE_s,&printasconstant);
  define_unary_function_ptr5( at_RPN_CASE ,alias_at_RPN_CASE ,&__RPN_CASE,0,T_RPN_OP);

  static const char _RPN_UNTIL_s []="RPN_UNTIL";
  static define_unary_function_eval2 (__RPN_UNTIL,&return_undef,_RPN_UNTIL_s,&printasconstant);
  define_unary_function_ptr( at_RPN_UNTIL ,alias_at_RPN_UNTIL ,&__RPN_UNTIL);

  static const char _rpn_prog_s []="rpn_prog";
  static define_unary_function_eval2_index (83,__rpn_prog,&return_undef,_rpn_prog_s,&printasconstant);
  define_unary_function_ptr5( at_rpn_prog ,alias_at_rpn_prog,&__rpn_prog,_QUOTE_ARGUMENTS,0);
#else // RTOS_THREADX
  static gen symb_rpn(const gen & args){
    return symbolic(at_rpn,args);
  }
  gen _rpn(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    rpn_mode(contextptr)=true;
    return symb_rpn(args);
  }
  static const char _rpn_s []="rpn";
  static define_unary_function_eval2 (__rpn,&_rpn,_rpn_s,&printasconstant);
  define_unary_function_ptr5( at_rpn ,alias_at_rpn ,(unary_function_eval*)&__rpn,0,true);

  static gen symb_alg(const gen & args){
    return symbolic(at_alg,args);
  }
  gen _alg(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    rpn_mode(contextptr)=false;
    return symb_alg(args);
  }
  static const char _alg_s []="alg";
  static define_unary_function_eval2 (__alg,&_alg,_alg_s,&printasconstant);
  define_unary_function_ptr5( at_alg ,alias_at_alg ,(unary_function_eval *)&__alg,0,true);

  void roll(int i,vecteur & v){
    if (i<2)
      return;
    iterateur it=v.begin(),itend=v.end();
    if (itend-it<i)
      return;
    it=itend-i;
    gen save=*it;
    for (;;){
      ++it;
      if (it==itend)
	break;
      *(it-1)=*it;
    }
    *(it-1)=save;
  }

  void ROLL(int i,GIAC_CONTEXT){
    roll(i,history_in(contextptr));
    roll(i,history_out(contextptr));
  }

  gen _ROLL(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args._VECTptr->empty())
      return args;
    gen e=args._VECTptr->back();
    args._VECTptr->pop_back();
    if (e.type==_INT_)
      roll(e.val,*args._VECTptr);
    if (e.type==_DOUBLE_)
      roll(int(e._DOUBLE_val),*args._VECTptr);
    return args;
  }
  static const char _ROLL_s []="ROLL";
  static define_unary_function_eval (__ROLL,&_ROLL,_ROLL_s);
  define_unary_function_ptr( at_ROLL ,alias_at_ROLL ,&__ROLL);

  void rolld(int i,vecteur & v){
    if (i<2)
      return;
    iterateur it=v.begin(),itend=v.end();
    if (itend-it<i)
      return;
    it=itend-i;
    --itend;
    gen save=*itend;
    for (;it!=itend;){
      --itend;
      *(itend+1)=*itend;
    }
    *it=save;
  }

  void ROLLD(int i,GIAC_CONTEXT){
    rolld(i,history_in(contextptr));
    rolld(i,history_out(contextptr));
  }
  gen _ROLLD(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args._VECTptr->empty())
      return args;
    gen e=args._VECTptr->back();
    args._VECTptr->pop_back();
    if (e.type==_INT_)
      rolld(e.val,*args._VECTptr);
    if (e.type==_DOUBLE_)
      rolld(int(e._DOUBLE_val),*args._VECTptr);
    return args;
  }
  static const char _ROLLD_s []="ROLLD";
  static define_unary_function_eval (__ROLLD,&_ROLLD,_ROLLD_s);
  define_unary_function_ptr( at_ROLLD ,alias_at_ROLLD ,&__ROLLD);

  void stack_swap(vecteur & v){
    iterateur it=v.begin(),itend=v.end();
    int s=int(itend-it);
    if (s<2)
      return;
    --itend;
    gen tmp=*itend;
    *itend=*(itend-1);
    *(itend-1)=tmp;
  }

  void SWAP(GIAC_CONTEXT){
    stack_swap(history_in(contextptr));
    stack_swap(history_out(contextptr));
  }

  gen _SWAP(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    stack_swap(*args._VECTptr);
    return args;
  }
  static const char _SWAP_s []="SWAP";
  static define_unary_function_eval (__SWAP,&_SWAP,_SWAP_s);
  define_unary_function_ptr5( at_SWAP ,alias_at_SWAP ,&__SWAP,0,T_RPN_OP);

  void dup(vecteur & v){
    if (!v.empty())
      v.push_back(v.back());
  }
  gen _DUP(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    dup(*args._VECTptr);
    return args;
  }
  static const char _DUP_s []="DUP";
  static define_unary_function_eval (__DUP,&_DUP,_DUP_s);
  define_unary_function_ptr5( at_DUP ,alias_at_DUP ,&__DUP,0,T_RPN_OP);

  void over(vecteur & v){
    int s=int(v.size());
    if (s>=2)
      v.push_back(v[s-2]);
  }
  gen _OVER(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    over(*args._VECTptr);
    return args;
  }
  static const char _OVER_s []="OVER";
  static define_unary_function_eval (__OVER,&_OVER,_OVER_s);
  define_unary_function_ptr5( at_OVER ,alias_at_OVER ,&__OVER,0,T_RPN_OP);

  void pick(int i,vecteur & v){
    int s=int(v.size());
    if ((i>=1) && (s>=i))
      v.push_back(v[s-i]);
  }
  gen _PICK(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args._VECTptr->empty())
      return args;
    gen e=args._VECTptr->back();
    args._VECTptr->pop_back();
    if (e.type==_INT_)
      pick(e.val,*args._VECTptr);
    if (e.type==_DOUBLE_)
      pick(int(e._DOUBLE_val),*args._VECTptr);
    return args;
  }
  static const char _PICK_s []="PICK";
  static define_unary_function_eval (__PICK,&_PICK,_PICK_s);
  define_unary_function_ptr5( at_PICK ,alias_at_PICK ,&__PICK,0,T_RPN_OP);

  void drop(vecteur & v){
    if (v.empty())
      return;
    v.pop_back();
  }
  gen _DROP(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    drop(*args._VECTptr);
    return args;
  }
  static const char _DROP_s []="DROP";
  static define_unary_function_eval (__DROP,&_DROP,_DROP_s);
  define_unary_function_ptr5( at_DROP ,alias_at_DROP ,&__DROP,0,T_RPN_OP);

  static string printasNOP(const gen & feuille,const char * sommetstr,GIAC_CONTEXT){
    return sommetstr;
  }
  gen symb_NOP(const gen & args){
    return vecteur(1,symbolic(at_NOP,args));
  }
  gen _NOP(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    return args;
  }
  static const char _NOP_s []="NOP";
  static define_unary_function_eval2_index (136,__NOP,&_NOP,_NOP_s,&printasNOP);
  define_unary_function_ptr5( at_NOP ,alias_at_NOP ,&__NOP,0,T_RPN_OP);

  static string printasIFTE(const gen & feuille,const char * sommetstr,GIAC_CONTEXT){
    const_iterateur it=feuille._VECTptr->begin();
    string res("IF " + printinner_VECT(*it->_VECTptr,_RPN_FUNC__VECT,contextptr));
    res += " THEN ";
    ++it;
    res += printinner_VECT(*it->_VECTptr,_RPN_FUNC__VECT,contextptr) + " ELSE ";
    ++it;
    return res + printinner_VECT(*it->_VECTptr,_RPN_FUNC__VECT,contextptr)+ " END";
  }
  gen symb_IFTE(const gen & args){
    return symbolic(at_IFTE,args);
  }
  gen _IFTE(const gen & args,const context * contextptr){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args.type!=_VECT || args._VECTptr->size()<3)
      return gensizeerr(contextptr);
    gen no=args._VECTptr->back();
    args._VECTptr->pop_back();
    gen yes=args._VECTptr->back();
    args._VECTptr->pop_back();
    gen e=args._VECTptr->back();
    args._VECTptr->pop_back();
    if (e.type==_VECT){
      rpn_eval(e,*args._VECTptr,contextptr);
      if (args._VECTptr->empty())
	return args;
      e=args._VECTptr->back();
      args._VECTptr->pop_back();
    }
    if (is_zero(e))
      return rpn_eval(no,*args._VECTptr,contextptr);
    else
      return rpn_eval(yes,*args._VECTptr,contextptr);
  }
  static const char _IFTE_s []="IFTE";
  static define_unary_function_eval2_index (126,__IFTE,&_IFTE,_IFTE_s,&printasIFTE);
  define_unary_function_ptr5( at_IFTE ,alias_at_IFTE ,&__IFTE,0,T_RPN_OP);

  static string printasRPN_LOCAL(const gen & feuille,const char * sommetstr,GIAC_CONTEXT){
    string s("-> ");
    s += printinner_VECT(*feuille._VECTptr->front()._VECTptr,_RPN_FUNC__VECT,contextptr);
    gen e= feuille._VECTptr->back();
    if ( (e.type==_VECT) && (e.subtype==_RPN_FUNC__VECT))
      return s + " " +e.print(contextptr);
    else { 
      if ( (e.type==_SYMB) && (e._SYMBptr->sommet==at_quote))
	return s + " '"+e._SYMBptr->feuille.print(contextptr)+"'";
      else
	return s + " '"+e.print(contextptr)+"'";
    }
  }
  gen symb_RPN_LOCAL(const gen & a,const gen & b){
    return symbolic(at_RPN_LOCAL,makesequence(a,b));
  }
  gen _RPN_LOCAL(const gen & args,const context * contextptr) {
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    // stack level 2=symbolic names, level 1=program
    if (args.type!=_VECT)
      return symbolic(at_RPN_LOCAL,args);
    int s=int(args._VECTptr->size());
    if (s<3)
      return gentoofewargs("RPN_LOCAL must have at least 3 args");
    gen prog=args._VECTptr->back();
    args._VECTptr->pop_back();
    vecteur names=*(args._VECTptr->back()._VECTptr); // must be a vector
    args._VECTptr->pop_back();
    // get values from stack
    int nvars=int(names.size());
    if (s-2<nvars)
      return gentoofewargs("RPN_LOCAL");
    vecteur values(names);
    for (int j=nvars-1;j>=0;--j){
      values[j]=args._VECTptr->back();
      args._VECTptr->pop_back();
    }
    // Initialization
    context * newcontextptr = (context *) contextptr;
    int protect=giac::bind(values,names,newcontextptr);
    vecteur res;
    if ((prog.type==_SYMB) && (prog._SYMBptr->sommet==at_quote)){
      args._VECTptr->push_back(prog._SYMBptr->feuille.eval(eval_level(contextptr),newcontextptr));
      res=*args._VECTptr;
    }
    else
      res=rpn_eval(prog,*args._VECTptr,newcontextptr);
    leave(protect,names,newcontextptr);
    return gen(res,_RPN_STACK__VECT);
  }
  static const char _RPN_LOCAL_s []="RPN_LOCAL";
  static define_unary_function_eval2_index (130,__RPN_LOCAL,&_RPN_LOCAL,_RPN_LOCAL_s,&printasRPN_LOCAL);
  define_unary_function_ptr5( at_RPN_LOCAL ,alias_at_RPN_LOCAL ,&__RPN_LOCAL,0,T_RPN_OP);

  static string printasRPN_FOR(const gen & feuille,const char * sommetstr,GIAC_CONTEXT){
    if ( (feuille.type!=_VECT) && (feuille._VECTptr->size()!=2))
      return "Invalid_RPN_FOR";
    string s;
    gen controle=feuille._VECTptr->front();
    gen prog=feuille._VECTptr->back();
    bool is_start= (controle[0].print(contextptr)==" j");
    if (is_start)
      s="START ";
    else
      s="FOR "+controle[0].print(contextptr)+" ";
    s += printinner_VECT(*prog._VECTptr,_RPN_FUNC__VECT,contextptr);
    if (is_one(controle[1]))
      s+=" NEXT";
    else
      s+= " "+controle[1].print(contextptr)+" STEP";
    return s;
  }
  gen symb_RPN_FOR(const gen & a,const gen & b){
    return symbolic(at_RPN_FOR,makesequence(a,b));
  }
  gen _RPN_FOR(const gen & args,const context * contextptr) {
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    // stack level 4=init
    // stack level 3=end
    // stack level 2=[init_var,step]
    // level 1=program to execute, 
    if (args.type!=_VECT)
      return symbolic(at_RPN_FOR,args);
    int s=int(args._VECTptr->size());
    if (s<4)
      return gentoofewargs("RPN_FOR must have at least 4 args");
    gen prog=args._VECTptr->back();
    args._VECTptr->pop_back();
    vecteur controle=*(args._VECTptr->back()._VECTptr); // it must be a vector
    args._VECTptr->pop_back();
    gen fin=args._VECTptr->back();
    args._VECTptr->pop_back();
    gen debut=args._VECTptr->back();
    args._VECTptr->pop_back();
    // Initialization
    vecteur names(1,controle[0]);
    gen test=inferieur_egal(controle[0],fin,contextptr);
    context * newcontextptr = (context *) contextptr;
    int protect=giac::bind(vecteur(1,debut),names,newcontextptr);
    vecteur res;
    for (;!is_zero(test.eval(eval_level(newcontextptr),newcontextptr).evalf(eval_level(contextptr),newcontextptr));sto(eval(controle[0]+controle[1],eval_level(newcontextptr),newcontextptr),controle[0],newcontextptr)){
      res=rpn_eval(prog,*args._VECTptr,newcontextptr);
    }
    leave(protect,names,newcontextptr);
    return gen(res,_RPN_STACK__VECT);
  }
  static const char _RPN_FOR_s []="RPN_FOR";
  static define_unary_function_eval2_index (132,__RPN_FOR,&_RPN_FOR,_RPN_FOR_s,&printasRPN_FOR);
  define_unary_function_ptr5( at_RPN_FOR ,alias_at_RPN_FOR ,&__RPN_FOR,0,T_RPN_OP);

  static string printasRPN_WHILE(const gen & feuille,const char * sommetstr,GIAC_CONTEXT){
    if ( (feuille.type!=_VECT) && (feuille._VECTptr->size()!=2))
      return "Invalid_RPN_WHILE";
    return "WHILE "+ printinner_VECT(*feuille._VECTptr->front()._VECTptr,_RPN_FUNC__VECT,contextptr) + " REPEAT "+printinner_VECT(*feuille._VECTptr->back()._VECTptr,_RPN_FUNC__VECT,contextptr)+ " END ";
  }
  gen symb_RPN_WHILE(const gen & a,const gen & b){
    return symbolic(at_RPN_WHILE,makesequence(a,b));
  }
  gen _RPN_WHILE(const gen & args,const context * contextptr) {
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    // stack level 2=condition
    // level 1=program to execute 
    if (args.type!=_VECT)
      return symbolic(at_RPN_WHILE,args);
    int s=int(args._VECTptr->size());
    if (s<2)
      return gentoofewargs("RPN_WHILE must have at least 2 args");
    gen prog=args._VECTptr->back();
    args._VECTptr->pop_back();
    gen controle=args._VECTptr->back();
    args._VECTptr->pop_back();
    vecteur res;
    for (;;){
      res=rpn_eval(controle,*args._VECTptr,contextptr);
      if (args._VECTptr->empty())
	return gentoofewargs("WHILE");
      gen tmp=args._VECTptr->back();
      args._VECTptr->pop_back();
      if (is_zero(tmp.eval(1,contextptr).evalf(1,contextptr)))
	break;
      res=rpn_eval(prog,*args._VECTptr,contextptr);
    }
    return gen(res,_RPN_STACK__VECT);
  }
  static const char _RPN_WHILE_s []="RPN_WHILE";
  static define_unary_function_eval2_index (134,__RPN_WHILE,&_RPN_WHILE,_RPN_WHILE_s,&printasRPN_WHILE);
  define_unary_function_ptr5( at_RPN_WHILE ,alias_at_RPN_WHILE ,&__RPN_WHILE,0,T_RPN_OP);

  static string printasRPN_CASE(const gen & feuille,const char * sommetstr,GIAC_CONTEXT){
    if (feuille.type!=_VECT)
      return "Invalid_RPN_CASE";
    vecteur v=*feuille._VECTptr;
    if ((v.size()!=1) ||(v.front().type!=_VECT))
      return "Invalid_RPN_CASE";
    string res("CASE ");
    const_iterateur it=v.front()._VECTptr->begin(),itend=v.front()._VECTptr->end();
    for (;it!=itend;){
      res += printinner_VECT(*it->_VECTptr,_RPN_FUNC__VECT,contextptr);
      ++it;
      if (it==itend)
	break;
      res += " THEN " + printinner_VECT(*it->_VECTptr,_RPN_FUNC__VECT,contextptr) + " END ";
      ++it;
    }
    return res+" END ";
  }
  gen symb_RPN_CASE(const gen & a){
    return symbolic(at_RPN_CASE,vecteur(1,a));
  }
  gen _RPN_CASE(const gen & args,const context * contextptr) {
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    // level 1=[case1, prg1, case2,prg2,..., [default]]
    if (args.type!=_VECT)
      return symbolic(at_RPN_CASE,args);
    int s=int(args._VECTptr->size());
    if (s<1)
      return gentoofewargs("RPN_CASE must have at least 1 arg");
    vecteur controle=*args._VECTptr->back()._VECTptr;
    args._VECTptr->pop_back();
    const_iterateur it=controle.begin(),itend=controle.end();
    vecteur res;
    for (;it!=itend;){
      res=rpn_eval(*it,*args._VECTptr,contextptr);
      if (args._VECTptr->empty())
	return gentoofewargs("CASE");
      ++it;
      if (it==itend) // default of the case struct
	break;
      gen test=args._VECTptr->back();
      args._VECTptr->pop_back();
      if (!(is_zero(test.eval(1,contextptr).evalf(1,contextptr)))){
	res=rpn_eval(*it,*args._VECTptr,contextptr);
	break;
      }
      ++it;
    }
    return gen(*args._VECTptr,_RPN_STACK__VECT);
  }
  static const char _RPN_CASE_s []="RPN_CASE";
  static define_unary_function_eval2_index (128,__RPN_CASE,&_RPN_CASE,_RPN_CASE_s,&printasRPN_CASE);
  define_unary_function_ptr5( at_RPN_CASE ,alias_at_RPN_CASE ,&__RPN_CASE,0,T_RPN_OP);

  static string printasRPN_UNTIL(const gen & feuille,const char * sommetstr,GIAC_CONTEXT){
    if ( (feuille.type!=_VECT) && (feuille._VECTptr->size()!=2))
      return "Invalid_RPN_UNTIL";
    return "DO "+ printinner_VECT(*feuille._VECTptr->front()._VECTptr,_RPN_FUNC__VECT,contextptr) + " UNTIL "+printinner_VECT(*feuille._VECTptr->back()._VECTptr,_RPN_FUNC__VECT,contextptr)+ " END ";
  }
  gen symb_RPN_UNTIL(const gen & a,const gen & b){
    return symbolic(at_RPN_UNTIL,makesequence(a,b));
  }
  gen _RPN_UNTIL(const gen & args,const context * contextptr) {
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    // stack level 2=program
    // level 1=condition 
    if (args.type!=_VECT)
      return symbolic(at_RPN_UNTIL,args);
    int s=int(args._VECTptr->size());
    if (s<2)
      return gentoofewargs("RPN_UNTIL must have at least 2 args");
    gen controle=args._VECTptr->back();
    args._VECTptr->pop_back();
    gen prog=args._VECTptr->back();
    args._VECTptr->pop_back();
    vecteur res;
    for (;;){
      res=rpn_eval(prog,*args._VECTptr,contextptr);
      res=rpn_eval(controle,*args._VECTptr,contextptr);
      if (args._VECTptr->empty())
	return gentoofewargs("UNTIL");
      gen tmp=args._VECTptr->back();
      args._VECTptr->pop_back();
      if (!is_zero(tmp.eval(eval_level(contextptr),contextptr).evalf(eval_level(contextptr),contextptr)))
	break;
    }
    return gen(res,_RPN_STACK__VECT);
  }
  static const char _RPN_UNTIL_s []="RPN_UNTIL";
  static define_unary_function_eval2 (__RPN_UNTIL,&_RPN_UNTIL,_RPN_UNTIL_s,&printasRPN_UNTIL);
  define_unary_function_ptr( at_RPN_UNTIL ,alias_at_RPN_UNTIL ,&__RPN_UNTIL);

  // RPN evaluation loop (_VECTEVAL), no return stack currently
  vecteur rpn_eval(const vecteur & prog,vecteur & pile,const context * contextptr){
    const_iterateur it=prog.begin(),itend=prog.end();
    for (;it!=itend;++it){
      if (it->type==_FUNC){
	// test nargs with subtype
	int nargs=it->subtype;
	if (nargs>signed(pile.size()))
	  return vecteur(1,gentoofewargs(it->print(contextptr)+": stack "+gen(pile).print(contextptr)));
	if (nargs==1){
	  pile.back()=(*it->_FUNCptr)(pile.back(),contextptr);
	}
	else {
	  if (nargs){
	    vecteur v(nargs);
	    for (int k=nargs-1;k>=0;--k){
	      v[k]=pile.back();
	      pile.pop_back();
	    }
	    pile.push_back((*it->_FUNCptr)(v,contextptr));
	  }
	  else {
	    gen res;
	    if (*it->_FUNCptr==at_eval){ // eval stack level 1
	      if (pile.empty())
		return vecteur(1,gentoofewargs("EVAL"));
	      res=pile.back();
	      pile.pop_back();
	      if ( (res.type==_SYMB) && (res._SYMBptr->sommet==at_rpn_prog))
		res=res._SYMBptr->feuille;
	      res=rpn_eval(res,pile,contextptr);
	    }
	    else
	      res=(*it->_FUNCptr)(pile,contextptr);
	    if ( (res.type==_VECT) && (res.subtype==_RPN_STACK__VECT) )
	      pile= *res._VECTptr;
	    else
	      pile= vecteur(1,res);
	  }
	}
      }
      else {
	// test for special symbolic (control struct)
	const unary_function_ptr control_op[]={*at_RPN_LOCAL,*at_RPN_FOR,*at_IFTE,*at_RPN_CASE,*at_RPN_WHILE,*at_RPN_UNTIL,0};
	if ( (it->type==_SYMB) && equalposcomp(control_op,it->_SYMBptr->sommet)){
	  // push args of it to the stack and call sommet on the stack
	  if (it->_SYMBptr->feuille.type!=_VECT) // should not happen!
	    pile.push_back(it->_SYMBptr->feuille);
	  else
	    pile=mergevecteur(pile,*it->_SYMBptr->feuille._VECTptr);
	  gen res=it->_SYMBptr->sommet(pile,contextptr);
	  if ( (res.type==_VECT) && (res.subtype==_RPN_STACK__VECT) )
	    pile= *res._VECTptr;
	  else
	    pile= vecteur(1,res);	  
	}
	else {
	  if ( (it->type!=_VECT) 
	       // || (it->subtype==_RPN_FUNC__VECT) 
	       ){
	    gen res=it->eval(1,contextptr);
	    if ( (res.type==_VECT) && (res.subtype==_RPN_STACK__VECT))
	      pile=*res._VECTptr;
	    else
	      pile.push_back(res);
	  }
	  else
	    pile.push_back(*it);
	}
      }
    }
    return pile;
  }

  vecteur rpn_eval(const gen & prog,vecteur & pile,const context * contextptr){
    if (prog.type!=_VECT)
      return rpn_eval(vecteur(1,prog),pile,contextptr);
    else
      return rpn_eval(*prog._VECTptr,pile,contextptr);
  }

  static string printasrpn_prog(const gen & feuille,const char * sommetstr,GIAC_CONTEXT){
    if (feuille.type!=_VECT)
      return "<< "+feuille.print(contextptr)+" >>";
    return "<< "+printinner_VECT(*feuille._VECTptr,_RPN_FUNC__VECT,contextptr)+" >>";
  }
  gen symb_rpn_prog(const gen & args){
    return symbolic(at_rpn_prog,args);
  }
  gen _rpn_prog(const gen & args,const context * contextptr){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (!rpn_mode(contextptr) || (args.type!=_VECT))
      return symbolic(at_rpn_prog,args);
    vecteur pile(history_out(contextptr));
    *logptr(contextptr) << pile << " " << args << endl;
    return gen(rpn_eval(*args._VECTptr,pile,contextptr),_RPN_STACK__VECT);
  }
  static const char _rpn_prog_s []="rpn_prog";
  static define_unary_function_eval2_index (83,__rpn_prog,&_rpn_prog,_rpn_prog_s,&printasrpn_prog);
  define_unary_function_ptr5( at_rpn_prog ,alias_at_rpn_prog,&__rpn_prog,_QUOTE_ARGUMENTS,0);

#endif // RTOS_THREADX

  gen _RCL(const gen & args,const context * contextptr) {
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    // stack level 2=condition
    // level 1=program to execute 
    if (args.type!=_IDNT)
      return symbolic(at_RCL,args);
    return args._IDNTptr->eval(1,args,contextptr);
  }
  static const char _RCL_s []="RCL";
  static define_unary_function_eval (__RCL,&_RCL,_RCL_s);
  define_unary_function_ptr5( at_RCL ,alias_at_RCL ,&__RCL,0,T_RPN_OP);

#if defined(__APPLE__) // || defined(__FreeBSD__)
  static int int_one (struct dirent *unused){
    return 1;
  }
#else
  static int int_one (const struct dirent *unused){
    return 1;
  }
#endif

  gen _VARS(const gen & args,const context * contextptr) {
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    bool val=is_one(args);
    bool valsto=is_minus_one(args);
    vecteur res;
    if (contextptr){
      if (contextptr->globalcontextptr && contextptr->globalcontextptr->tabptr){
	sym_tab::const_iterator it=contextptr->globalcontextptr->tabptr->begin(),itend=contextptr->globalcontextptr->tabptr->end();
	vecteur * keywordsptr=keywords_vecteur_ptr();
	for (;it!=itend;++it){
	  gen g=identificateur(it->first);
	  if (!equalposcomp(*keywordsptr,g)){
	    if (val)
	      g=symbolic(at_equal,makesequence(g,it->second));
	    if (valsto)
	      g=symb_sto(it->second,g);
	    res.push_back(g);
	  }
	}
      }
      return res;
    }
    if (!variables_are_files(contextptr)){
      lock_syms_mutex();  
      sym_string_tab::const_iterator it=syms().begin(),itend=syms().end();
      for (;it!=itend;++it){
	gen id=it->second;
	if (id.type==_IDNT && id._IDNTptr->value){
	  res.push_back(id);
	}
      }
      unlock_syms_mutex();  
      if (is_one(args) && current_folder_name.type==_IDNT && current_folder_name._IDNTptr->value){ // add variables of the current folder
	gen & tmp=*current_folder_name._IDNTptr->value;
	if (tmp.type==_VECT){
	  vecteur v=*current_folder_name._IDNTptr->value->_VECTptr;
	  iterateur it=v.begin(),itend=v.end();
	  for (;it!=itend;++it){
	    if (it->type!=_VECT || it->_VECTptr->size()!=2)
	      continue;
	    vecteur & w=*it->_VECTptr;
	    res.push_back(w[0]);
	  }
	}
      }
      return res;
    }
#ifndef VARIABLE_ARE_FILES
    return undef;
#else
    struct dirent **eps;
    int n;
    n = scandir ("./", &eps, int_one, alphasort);
    if (n >= 0){
      string s;
      int cnt;
      for (cnt = 0; cnt < n; ++cnt){
	s=string(eps[cnt]->d_name);
	unsigned k=0;
	for (;k<s.size();++k){
	  if (!isalphan(s[k]))
	    break;
	}
	if ( (k==s.size()-4) && (s[k]=='.') && (s.substr(k+1,3)=="cas") )
	  res.push_back(identificateur(s.substr(0,k)));
      }
      if ( rpn_mode(contextptr) && (args.type==_VECT) && (args.subtype==_RPN_STACK__VECT) ){
	args._VECTptr->push_back(res);
	return args;
      }
      return res;
    }
    else
      settypeerr ("Couldn't open the directory");
    return 0;
#endif
  }

  static const char _VARS_s []="VARS";
  static define_unary_function_eval (__VARS,&_VARS,_VARS_s);
  define_unary_function_ptr( at_VARS ,alias_at_VARS ,&__VARS);

  gen purgenoassume(const gen & args,const context * contextptr){
    if (args.type==_VECT){
      vecteur & v=*args._VECTptr;
      vecteur res;
      for (unsigned i=0;i<v.size();++i)
	res.push_back(purgenoassume(v[i],contextptr));
      return res;
    }
    if (args.type!=_IDNT)
      return gensizeerr("Invalid purgenoassume "+args.print(contextptr));
    if (!contextptr)
      return _purge(args,0);
    const char * ch=args._IDNTptr->id_name;
    if (strlen(ch)==1){
      if (ch[0]=='O' && (series_flags(contextptr) & (1<<6)) )
	series_flags(contextptr) ^= (1<<6);
      if (ch[0]==series_variable_name(contextptr)){
	if (series_flags(contextptr) & (1<<5))
	  series_flags(contextptr) ^= (1<<5);
	if (series_flags(contextptr) & (1<<6))
	  series_flags(contextptr) ^= (1<<6);
      }
    }
    // purge a global variable
    sym_tab::iterator it=contextptr->tabptr->find(ch),itend=contextptr->tabptr->end();
    if (it==itend)
      return string2gen("No such variable "+args.print(contextptr),false);
    gen res=it->second;
    if (it->second.type==_POINTER_ && it->second.subtype==_THREAD_POINTER)
      return gentypeerr(args.print(contextptr)+" is locked by thread "+it->second.print(contextptr));
    if (contextptr->previous)
      it->second=identificateur(it->first);
    else
      contextptr->tabptr->erase(it);
    if (res.is_symb_of_sommet(at_rootof))
      _purge(res,contextptr);
    return res;
  }

  gen _purge(const gen & args,const context * contextptr) {
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (rpn_mode(contextptr) && (args.type==_VECT)){
      if (!args._VECTptr->size())
	return gentoofewargs("purge");
      gen apurger=args._VECTptr->back();
      _purge(apurger,contextptr);
      args._VECTptr->pop_back();
      return gen(*args._VECTptr,_RPN_STACK__VECT);
    }
    if (args.type==_VECT)
      return apply(args,contextptr,giac::_purge);
    if (args.is_symb_of_sommet(at_at)){
      gen & f = args._SYMBptr->feuille;
      if (f.type==_VECT && f._VECTptr->size()==2){
	gen m = eval(f._VECTptr->front(),eval_level(contextptr),contextptr);
	gen indice=eval(f._VECTptr->back(),eval_level(contextptr),contextptr);
	if (m.type==_MAP){
	  gen_map::iterator it=m._MAPptr->find(indice),itend=m._MAPptr->end();
	  if (it==itend)
	    return gensizeerr(gettext("Bad index")+indice.print(contextptr));
	  m._MAPptr->erase(it);
	  return 1;
	}
      }
    }
    if (contextptr && args.is_symb_of_sommet(at_rootof)){
      gen a=eval(args,1,contextptr);
      if (!a.is_symb_of_sommet(at_rootof))
	return gensizeerr(gettext("Bad rootof"));
      if (!contextptr->globalcontextptr->rootofs)
	contextptr->globalcontextptr->rootofs=new vecteur;
      gen Pmin=a._SYMBptr->feuille;
      if (Pmin.type!=_VECT || Pmin._VECTptr->size()!=2 || Pmin._VECTptr->front()!=makevecteur(1,0))
	return gensizeerr(gettext("Bad rootof"));
      Pmin=Pmin._VECTptr->back();
      vecteur & r =*contextptr->globalcontextptr->rootofs;
      for (unsigned i=0;i<r.size();++i){
	gen ri=r[i];
	if (ri.type==_VECT && ri._VECTptr->size()==2 && Pmin==ri._VECTptr->front()){
	  gen a=ri._VECTptr->back();
	  r.erase(r.begin()+i);
	  return _purge(a,contextptr);
	}
      }
      return 0;
    }
    if (args.type!=_IDNT)
      return symbolic(at_purge,args);
    // REMOVED! args.eval(eval_level(contextptr),contextptr); 
    if (contextptr){
      if (contextptr->globalcontextptr!=contextptr){ 
	// purge a local variable = set it to assume(DOM_SYMBOLIC)
	gen a2(_SYMB);
	a2.subtype=1;
	return sto(gen(makevecteur(a2),_ASSUME__VECT),args,contextptr);
      }
      return purgenoassume(args,contextptr);
    }
    if (current_folder_name.type==_IDNT && current_folder_name._IDNTptr->value && current_folder_name._IDNTptr->value->type==_VECT){
      vecteur v=*current_folder_name._IDNTptr->value->_VECTptr;
      iterateur it=v.begin(),itend=v.end();
      gen val;
      for (;it!=itend;++it){
	if (it->type!=_VECT || it->_VECTptr->size()!=2)
	  continue;
	vecteur & w=*it->_VECTptr;
	if (w[0]==args){
	  val=w[1];
	  break;
	}
      }
      if (it!=itend){
	v.erase(it);
	gen res=gen(v,_FOLDER__VECT);
	*current_folder_name._IDNTptr->value=res;
#ifdef HAVE_SIGNAL_H_OLD
	if (!child_id && signal_store)
	  _signal(symb_quote(symbolic(at_sto,makesequence(res,current_folder_name))),contextptr);
#endif
	return val;
      }
    }
    if (args._IDNTptr->value){
#if !defined RTOS_THREADX && !defined BESTA_OS && !defined FREERTOS
      if (variables_are_files(contextptr))
	unlink((args._IDNTptr->name()+string(cas_suffixe)).c_str());
#endif
      gen res=*args._IDNTptr->value;
      if (res.type==_VECT && res.subtype==_FOLDER__VECT){
	if (res._VECTptr->size()!=1)
	  return gensizeerr(gettext("Non-empty folder"));
      }
      delete args._IDNTptr->value;
      args._IDNTptr->value=0;
#ifdef HAVE_SIGNAL_H_OLD
      if (!child_id && signal_store)
	_signal(symb_quote(symb_purge(args)),contextptr);
#endif
      return res;
    }
    else
      return string2gen(args.print(contextptr)+" not assigned",false);
  }
  static const char _purge_s []="purge";
  static define_unary_function_eval_quoted (__purge,&_purge,_purge_s);
  define_unary_function_ptr5( at_purge ,alias_at_purge,&__purge,_QUOTE_ARGUMENTS,0);

  static string printasdivision(const gen & feuille,const char * s,GIAC_CONTEXT){
    if (feuille.type!=_VECT || feuille._VECTptr->size()!=2)
      return printsommetasoperator(feuille,s,contextptr);
    gen n=feuille._VECTptr->front();
    bool need=need_parenthesis(n);
    string res;
    if (need) res+='(';
    res += n.print(contextptr);
    if (need) res += ')';
    res += '/';
    gen f=feuille._VECTptr->back();
    if ( (f.type==_SYMB && ( f._SYMBptr->sommet==at_plus || f._SYMBptr->sommet==at_prod || f._SYMBptr->sommet==at_division || f._SYMBptr->sommet==at_inv  || need_parenthesis(f._SYMBptr->sommet) )) || (f.type==_CPLX) || (f.type==_MOD)){
      res += '(';
      res += f.print(contextptr);
      res += ')';
    }
    else
      res += f.print(contextptr);
    return res;
  }

  static string texprintasdivision(const gen & feuille,const char * s,GIAC_CONTEXT){
    if (feuille.type!=_VECT || feuille._VECTptr->size()!=2)
      return "invalid /";
    return "\\frac{"+gen2tex(feuille._VECTptr->front(),contextptr)+"}{"+gen2tex(feuille._VECTptr->back(),contextptr)+"}";
  }
  static gen symb_division(const gen & args){
    return symbolic(at_division,args);
  }
  gen _division(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if ( (args.type!=_VECT) || (args._VECTptr->size()!=2) )
      return symb_division(args);
    gen a=args._VECTptr->front(),b=args._VECTptr->back();
    if (a.is_approx()){
      gen b1;
      if (has_evalf(b,b1,1,contextptr) && b.type!=b1.type){
#ifdef HAVE_LIBMPFR
	if (a.type==_REAL){
	  gen b2=accurate_evalf(b,mpfr_get_prec(a._REALptr->inf));
	  if (b2.is_approx())
	    return (*a._REALptr)/b2;
	}
#endif
	return rdiv(a,b1,contextptr);
      }
    }
    if (b.is_approx()){
      gen a1;
      if (has_evalf(a,a1,1,contextptr) && a.type!=a1.type){
#ifdef HAVE_LIBMPFR
	if (b.type==_REAL){
	  gen a2=accurate_evalf(a,mpfr_get_prec(b._REALptr->inf));
	  if (a2.is_approx())
	    return a2/b;
	}
#endif
	return rdiv(a1,b,contextptr);
      }
    }
    return rdiv(a,b,contextptr);
  }
  static const char _division_s []="/";
  static define_unary_function_eval4_index (10,__division,&_division,_division_s,&printasdivision,&texprintasdivision);
  define_unary_function_ptr( at_division ,alias_at_division ,&__division);

  static gen symb_binary_minus(const gen & args){
    return symbolic(at_binary_minus,args);
  }
  gen _binary_minus(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if ( (args.type!=_VECT) || (args._VECTptr->size()!=2) )
      return symb_binary_minus(args);
    return args._VECTptr->front()-args._VECTptr->back();
  }
  static const char _binary_minus_s[]="-";
  static define_unary_function_eval4_index (6,__binary_minus,&_binary_minus,_binary_minus_s,&printsommetasoperator,&texprintsommetasoperator);
  define_unary_function_ptr( at_binary_minus ,alias_at_binary_minus ,&__binary_minus);

  vecteur tab2vecteur(gen tab[]){
    vecteur res;
    for (;!is_zero(*tab);++tab)
      res.push_back(*tab);
    return res;
  }

  // hp38 compatibility
  // model
  gen _hp38(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if ( (args.type!=_VECT) || (args._VECTptr->size()!=2) )
      return gensizeerr(contextptr);
    return undef;
  }
  static const char _hp38_s[]="hp38";
  static define_unary_function_eval (__hp38,&_hp38,_hp38_s);
  define_unary_function_ptr5( at_hp38 ,alias_at_hp38,&__hp38,0,true);

  // real/complex
  gen _ABS(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args.type!=_VECT)
      return abs(args,contextptr);
    if (args.subtype)
      return apply(args,giac::_abs,contextptr);
    vecteur v;
    aplatir(*args._VECTptr,v);
    return _l2norm(v,contextptr);
  }
  static const char _ABS_s[]="ABS";
  static define_unary_function_eval (__ABS,&_ABS,_ABS_s);
  define_unary_function_ptr5( at_ABS ,alias_at_ABS,&__ABS,0,T_UNARY_OP_38);

  gen _ARG38(const gen & g,GIAC_CONTEXT){
    // if (angle_radian(contextptr)==0) return arg(evalf2bcd(g,1,contextptr),contextptr);
    return arg(g,contextptr);
  }
  static const char _ARG38_s[]="ARG";
  static define_unary_function_eval (__ARG38,&_ARG38,_ARG38_s);
  define_unary_function_ptr5( at_ARG38 ,alias_at_ARG38,&__ARG38,0,T_UNARY_OP_38);

  static const char _CONJ_s[]="CONJ";
  static define_unary_function_eval (__CONJ,(const gen_op_context)giac::conj,_CONJ_s);
  define_unary_function_ptr5( at_CONJ ,alias_at_CONJ,&__CONJ,0,T_UNARY_OP_38);

  static const char _RE_s[]="RE";
  static define_unary_function_eval (__RE,(const gen_op_context)giac::re,_RE_s);
  define_unary_function_ptr5( at_RE ,alias_at_RE,&__RE,0,T_UNARY_OP_38);

  static const char _IM_s[]="IM";
  static define_unary_function_eval (___IM,(const gen_op_context)giac::im,_IM_s);
  define_unary_function_ptr5( at_IM ,alias_at_IM,&___IM,0,T_UNARY_OP_38);

  static const char _FLOOR_s[]="FLOOR";
  static define_unary_function_eval (__FLOOR,(const gen_op_context)giac::_floor,_FLOOR_s);
  define_unary_function_ptr5( at_FLOOR ,alias_at_FLOOR,&__FLOOR,0,T_UNARY_OP_38);

  static const char _CEILING_s[]="CEILING";
  static define_unary_function_eval (__CEILING,(const gen_op_context)giac::_ceil,_CEILING_s);
  define_unary_function_ptr5( at_CEILING ,alias_at_CEILING,&__CEILING,0,T_UNARY_OP_38);

  gen FP(const gen & g,GIAC_CONTEXT){
    if (is_undef(g))
      return g;
    if (is_equal(g))
      return apply_to_equal(g,FP,contextptr);
    return g-_INT(g,contextptr);
  }
  static const char _FRAC_s[]="FP";
  static define_unary_function_eval (__FRAC,&giac::FP,_FRAC_s);
  define_unary_function_ptr5( at_FRAC ,alias_at_FRAC,&__FRAC,0,T_UNARY_OP_38);

  static const char _MAX_s[]="MAX";
  static define_unary_function_eval (__MAX,&giac::_max,_MAX_s);
  define_unary_function_ptr5( at_MAX ,alias_at_MAX,&__MAX,0,T_UNARY_OP_38);

  static const char _MIN_s[]="MIN";
  static define_unary_function_eval (__MIN,&giac::_min,_MIN_s);
  define_unary_function_ptr5( at_MIN ,alias_at_MIN,&__MIN,0,T_UNARY_OP_38);

  gen _MODULO(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args.type==_VECT && args._VECTptr->size()==2){
      gen a=args._VECTptr->front(),b=args._VECTptr->back();
      if (is_zero(b))
	return a;
      if (is_integer(a)&&is_integer(b))
	return _irem(args,contextptr);
      if (a.type==_FLOAT_){
	if (b.type==_FLOAT_)
	  return fmod(a._FLOAT_val,b._FLOAT_val);
	if (b.type==_INT_)
	  return fmod(a._FLOAT_val,giac_float(b.val));
      }
      return a-b*_floor(a/b,contextptr);
    }
    return gentypeerr(contextptr);
  }
  static const char _MOD_s[]="MOD";
  static define_unary_function_eval4 (__MOD,&giac::_MODULO,_MOD_s,&printsommetasoperator,&texprintsommetasoperator);
  define_unary_function_ptr5( at_MOD ,alias_at_MOD,&__MOD,0,T_DIV);

  static const char _ROUND_s[]="ROUND";
  static define_unary_function_eval (__ROUND,&giac::_round,_ROUND_s); 
  define_unary_function_ptr5( at_ROUND ,alias_at_ROUND,&__ROUND,0,T_UNARY_OP_38);

  gen _INTERSECT(const gen & g,GIAC_CONTEXT){
    return _intersect(g,contextptr);
  }
  static const char _INTERSECT_s[]="INTERSECT";
  static define_unary_function_eval (__INTERSECT,&giac::_INTERSECT,_INTERSECT_s); 
  define_unary_function_ptr5( at_INTERSECT ,alias_at_INTERSECT,&__INTERSECT,0,T_UNARY_OP_38);

  gen _UNION(const gen & g,GIAC_CONTEXT){
    return _union(g,contextptr);
  }
  static const char _UNION_s[]="UNION";
  static define_unary_function_eval (__UNION,&giac::_UNION,_UNION_s); 
  define_unary_function_ptr5( at_UNION ,alias_at_UNION,&__UNION,0,T_UNARY_OP_38);

  gen _MINUS(const gen & g,GIAC_CONTEXT){
    return _minus(g,contextptr);
  }
  static const char _MINUS_s[]="MINUS";
  static define_unary_function_eval (__MINUS,&giac::_MINUS,_MINUS_s); 
  define_unary_function_ptr5( at_MINUS ,alias_at_MINUS,&__MINUS,0,T_UNARY_OP_38);

  gen _trunc(const gen & args,GIAC_CONTEXT);

  static const char _TRUNCATE_s[]="TRUNCATE";
  static define_unary_function_eval (__TRUNCATE,&giac::_trunc,_TRUNCATE_s); 
  define_unary_function_ptr5( at_TRUNCATE ,alias_at_TRUNCATE,&__TRUNCATE,0,T_UNARY_OP_38);

  static const char _QUOTE_s[]="QUOTE";
  static define_unary_function_eval_quoted (__QUOTE,&giac::quote,_QUOTE_s); 
  define_unary_function_ptr5( at_QUOTE ,alias_at_QUOTE,&__QUOTE,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  // Note that 0 is necessary otherwise conflict on freeBSD
  static const char _SIGN_s[]="SIGN";
  static define_unary_function_eval (__SIGN0,&giac::sign,_SIGN_s);
  define_unary_function_ptr5( at_SIGN ,alias_at_SIGN,&__SIGN0,0,T_UNARY_OP_38);
  
  // proba
  static const char _COMB_s[]="COMB";
  static define_unary_function_eval (__COMB,&giac::_comb,_COMB_s); 
  define_unary_function_ptr5( at_COMB ,alias_at_COMB,&__COMB,0,T_UNARY_OP_38);  

  static const char _PERM_s[]="PERM";
  static define_unary_function_eval (__PERM,&giac::_perm,_PERM_s); 
  define_unary_function_ptr5( at_PERM ,alias_at_PERM,&__PERM,0,T_UNARY_OP_38);  

  string printasRANDOM(const gen & feuille,const char * s,GIAC_CONTEXT){
    if (feuille.type==_VECT && feuille._VECTptr->empty())
      return s;
    return "("+(s+(" "+feuille.print())+")");
  }
  gen _RANDOM(const gen & g0,GIAC_CONTEXT){
    gen g(g0);
    if ( g.type==_STRNG && g.subtype==-1) return  g;
    is_integral(g);
    if (g.type==_CPLX)
      return _rand(gen(makevecteur(*g._CPLXptr,*(g._CPLXptr+1)),_SEQ__VECT),contextptr);
    if (g.type!=_VECT || g.subtype!=_SEQ__VECT || !g._VECTptr->empty())
      return _rand(g,contextptr);
    return double(giac_rand(contextptr))/rand_max2;
  }
  static const char _RANDOM_s[]="RANDOM";
  static define_unary_function_eval2 (__RANDOM,&giac::_RANDOM,_RANDOM_s,&printasRANDOM); 
  define_unary_function_ptr5( at_RANDOM ,alias_at_RANDOM,&__RANDOM,0,T_RETURN);  

  static const char _RANDSEED_s[]="RANDSEED";
  static define_unary_function_eval (__RANDSEED,&giac::_srand,_RANDSEED_s); 
  define_unary_function_ptr5( at_RANDSEED ,alias_at_RANDSEED,&__RANDSEED,0,T_RETURN);  

  gen _MAXREAL(const gen & g,GIAC_CONTEXT){
    if ( g.type==_STRNG && g.subtype==-1) return  g;
#if 0 // def BCD
    return_bcd_maxreal;
#else
    return 1.79769313486e+308;
#endif
  }
  static const char _MAXREAL_s[]="MAXREAL";
  static define_unary_function_eval (__MAXREAL,&giac::_MAXREAL,_MAXREAL_s); 
  define_unary_function_ptr5( at_MAXREAL ,alias_at_MAXREAL,&__MAXREAL,0,T_NUMBER);  

  gen _MINREAL(const gen & g,GIAC_CONTEXT){
    if ( g.type==_STRNG && g.subtype==-1) return  g;
#if 0 // def BCD
    return_bcd_minreal;
    // return_bcd_minreal;
#else
    return 2.22507385851e-308; // smallest non-denormalized double
    // return 1.26480805335e-321;
#endif
  }
  static const char _MINREAL_s[]="MINREAL";
  static define_unary_function_eval (__MINREAL,&giac::_MINREAL,_MINREAL_s); 
  define_unary_function_ptr5( at_MINREAL ,alias_at_MINREAL,&__MINREAL,0,T_NUMBER);  

  // transcendent
  static const char _EXP_s[]="EXP";
  static define_unary_function_eval (__EXP,&giac::exp,_EXP_s);
  define_unary_function_ptr5( at_EXP ,alias_at_EXP,&__EXP,0,T_UNARY_OP_38);

#if 0
  define_partial_derivative_onearg_genop( D_at_expm1,"D_at_expm1",&giac::exp);
#endif
  gen _EXPM1(const gen & g,GIAC_CONTEXT){
    if ( g.type==_STRNG && g.subtype==-1) return  g;
    return exp(g,contextptr)-1;
  }
  static const char _EXPM1_s[]="EXPM1";
  static define_unary_function_eval (__EXPM1,&giac::_EXPM1,_EXPM1_s);
  define_unary_function_ptr5( at_EXPM1 ,alias_at_EXPM1,&__EXPM1,0,T_UNARY_OP_38);

#if 0
  static gen d_lnp1(const gen & args,GIAC_CONTEXT){
    return inv(args+1,contextptr);
  }
  define_partial_derivative_onearg_genop( D_at_lnp1,"D_at_lnp1",&d_lnp1);
#endif
  gen _LNP1(const gen & g,GIAC_CONTEXT){
    if ( g.type==_STRNG && g.subtype==-1) return  g;
    return ln(g+1,contextptr);
  }
  static const char _LNP1_s[]="LNP1";
  static define_unary_function_eval (__LNP1,&giac::_LNP1,_LNP1_s);
  define_unary_function_ptr5( at_LNP1 ,alias_at_LNP1,&__LNP1,0,T_UNARY_OP_38);

  static const char _LN_s[]="LN";
  static define_unary_function_eval (__LN,&giac::ln,_LN_s);
  define_unary_function_ptr5( at_LN ,alias_at_LN,&__LN,0,T_UNARY_OP_38);

  gen _LOG(const gen & g,GIAC_CONTEXT){
    if (g.type==_VECT && g.subtype==_SEQ__VECT && g._VECTptr->size()==2)
      return _logb(g,contextptr);
    return giac::log10(g,contextptr);
  }
  static const char _LOG_s[]="LOG";
  static define_unary_function_eval (__LOG,&_LOG,_LOG_s);
  define_unary_function_ptr5( at_LOG ,alias_at_LOG,&__LOG,0,T_UNARY_OP_38);

  static const char _ALOG_s[]="ALOG";
  static define_unary_function_eval (__ALOG,&giac::alog10,_ALOG_s);
  define_unary_function_ptr5( at_ALOG ,alias_at_ALOG,&__ALOG,0,T_UNARY_OP_38);

  static const char _SIN_s[]="SIN";
  static define_unary_function_eval (__SIN,&giac::sin,_SIN_s);
  define_unary_function_ptr5( at_SIN ,alias_at_SIN,&__SIN,0,T_UNARY_OP_38);

  static const char _COS_s[]="COS";
  static define_unary_function_eval (__COS,&giac::cos,_COS_s);
  define_unary_function_ptr5( at_COS ,alias_at_COS,&__COS,0,T_UNARY_OP_38);

  static const char _TAN_s[]="TAN";
  static define_unary_function_eval (__TAN,&giac::tan,_TAN_s);
  define_unary_function_ptr5( at_TAN ,alias_at_TAN,&__TAN,0,T_UNARY_OP_38);

  static const char _ASIN_s[]="ASIN";
  static define_unary_function_eval (__ASIN,&giac::asin,_ASIN_s);
  define_unary_function_ptr5( at_ASIN ,alias_at_ASIN,&__ASIN,0,T_UNARY_OP_38);

  static const char _ACOS_s[]="ACOS";
  static define_unary_function_eval (__ACOS,&giac::acos,_ACOS_s);
  define_unary_function_ptr5( at_ACOS ,alias_at_ACOS,&__ACOS,0,T_UNARY_OP_38);

  static const char _ATAN_s[]="ATAN";
  static define_unary_function_eval (__ATAN,&giac::atan,_ATAN_s);
  define_unary_function_ptr5( at_ATAN ,alias_at_ATAN,&__ATAN,0,T_UNARY_OP_38);

  static const char _SINH_s[]="SINH";
  static define_unary_function_eval (__SINH,&giac::sinh,_SINH_s);
  define_unary_function_ptr5( at_SINH ,alias_at_SINH,&__SINH,0,T_UNARY_OP_38);

  static const char _COSH_s[]="COSH";
  static define_unary_function_eval (__COSH,&giac::cosh,_COSH_s);
  define_unary_function_ptr5( at_COSH ,alias_at_COSH,&__COSH,0,T_UNARY_OP_38);

  static const char _TANH_s[]="TANH";
  static define_unary_function_eval (__TANH,&giac::tanh,_TANH_s);
  define_unary_function_ptr5( at_TANH ,alias_at_TANH,&__TANH,0,T_UNARY_OP_38);

  static const char _ASINH_s[]="ASINH";
  static define_unary_function_eval (__ASINH,&giac::asinh,_ASINH_s);
  define_unary_function_ptr5( at_ASINH ,alias_at_ASINH,&__ASINH,0,T_UNARY_OP_38);

  static const char _ACOSH_s[]="ACOSH";
  static define_unary_function_eval (__ACOSH,&giac::acosh,_ACOSH_s);
  define_unary_function_ptr5( at_ACOSH ,alias_at_ACOSH,&__ACOSH,0,T_UNARY_OP_38);

  static const char _ATANH_s[]="ATANH";
  static define_unary_function_eval (__ATANH,&giac::atanh,_ATANH_s);
  define_unary_function_ptr5( at_ATANH ,alias_at_ATANH,&__ATANH,0,T_UNARY_OP_38);

  bool is_Ans(const gen & g){
    if (g.type==_FUNC && *g._FUNCptr==at_Ans)
      return true;
    if (g.type==_SYMB && g._SYMBptr->sommet==at_Ans)
      return true;
    return false;
  }
  /* matrices */
  gen _ADDROW(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    vecteur v(gen2vecteur(args));
    if (!v.empty() && is_Ans(v[0]))
      v[0]=eval(v[0],1,contextptr);
    if (!v.empty() && v[0].type==_IDNT){
      gen v0=v[0];
      gen g=eval(args,eval_level(contextptr),contextptr);
      if (ckmatrix(g[0])){
	gen tmp=_ADDROW(g,contextptr);
	return is_undef(tmp)?tmp:sto(tmp,v0,contextptr);
      }
    }
    if (v.size()!=3)
      return gentypeerr(contextptr);
    v[1]=eval(v[1],1,contextptr);
    v[2]=eval(v[2],1,contextptr);
    v[2]=_floor(v[2],contextptr);
    if (!ckmatrix(v[0]) || v[1].type!=_VECT || v[2].type!=_INT_)
      return gentypeerr(contextptr);
    vecteur & w = *v[0]._VECTptr;
    if (w.front()._VECTptr->size()!=v[1]._VECTptr->size())
      return gendimerr(contextptr);
    int s=int(w.size());
    int shift = xcas_mode(contextptr)!=0 || abs_calc_mode(contextptr)==38;
    int l2=v[2].val-shift;
    if (l2<0 || l2>s)
      return gendimerr(contextptr);
    matrice res(w.begin(),w.begin()+l2);
    res.push_back(v[1]);
    for (int i=l2;i<s;++i)
      res.push_back(w[i]);
    return res;
  }
  static const char _ADDROW_s[]="ADDROW";
  static define_unary_function_eval_quoted (__ADDROW,&giac::_ADDROW,_ADDROW_s);
  define_unary_function_ptr5( at_ADDROW ,alias_at_ADDROW,&__ADDROW,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _ADDCOL(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    vecteur v(gen2vecteur(args));
    if (!v.empty() && is_Ans(v[0]))
      v[0]=eval(v[0],1,contextptr);
    if (!v.empty() && v[0].type==_IDNT){
      gen v0=v[0];
      gen g=eval(args,eval_level(contextptr),contextptr);
      if (ckmatrix(g[0])){
	gen tmp=_ADDCOL(g,contextptr);
	return is_undef(tmp)?tmp:sto(tmp,v0,contextptr);
      }
    }
    if (v.size()!=3 || !ckmatrix(v[0]))
      return gensizeerr(contextptr);
    matrice m;
    mtran(*v[0]._VECTptr,m);
    gen res=_ADDROW(makesequence(m,v[1],v[2]),contextptr);
    if (res.type==_VECT){
      mtran(*res._VECTptr,m);
      res=m;
    }
    return res;
  }
  static const char _ADDCOL_s[]="ADDCOL";
  static define_unary_function_eval_quoted (__ADDCOL,&giac::_ADDCOL,_ADDCOL_s);
  define_unary_function_ptr5( at_ADDCOL ,alias_at_ADDCOL,&__ADDCOL,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _SCALE(const gen & g,GIAC_CONTEXT){
    if ( g.type==_STRNG && g.subtype==-1) return  g;
    if (g.type!=_VECT || g._VECTptr->size()!=3)
      return gensizeerr(contextptr);
    vecteur v =*g._VECTptr;
    v[1]=eval(v[1],1,contextptr);
    v[2]=eval(v[2],1,contextptr);
    swapgen(v[0],v[1]);
    return _mRow(gen(v,_SEQ__VECT),contextptr);
  }
  static const char _SCALE_s[]="SCALE";
  static define_unary_function_eval_quoted (__SCALE,&giac::_SCALE,_SCALE_s);
  define_unary_function_ptr5( at_SCALE ,alias_at_SCALE,&__SCALE,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  static const char _scale_s[]="scale";
  static define_unary_function_eval_quoted (__scale,&giac::_SCALE,_scale_s);
  define_unary_function_ptr5( at_scale ,alias_at_scale,&__scale,_QUOTE_ARGUMENTS,T_UNARY_OP);

  gen _SCALEADD(const gen & g,GIAC_CONTEXT){
    if ( g.type==_STRNG && g.subtype==-1) return  g;
    if (g.type!=_VECT || g._VECTptr->size()!=4)
      return gensizeerr(contextptr);
    vecteur v =*g._VECTptr;
    v[1]=eval(v[1],1,contextptr);
    v[2]=eval(v[2],1,contextptr);
    v[3]=eval(v[3],1,contextptr);
    swapgen(v[0],v[1]);
    return _mRowAdd(gen(v,_SEQ__VECT),contextptr);
  }
  static const char _SCALEADD_s[]="SCALEADD";
  static define_unary_function_eval_quoted (__SCALEADD,&giac::_SCALEADD,_SCALEADD_s);
  define_unary_function_ptr5( at_SCALEADD ,alias_at_SCALEADD,&__SCALEADD,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  static const char _scaleadd_s[]="scaleadd";
  static define_unary_function_eval_quoted (__scaleadd,&giac::_SCALEADD,_scaleadd_s);
  define_unary_function_ptr5( at_scaleadd ,alias_at_scaleadd,&__scaleadd,_QUOTE_ARGUMENTS,T_UNARY_OP);

  gen _SWAPCOL(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    vecteur v(gen2vecteur(args));
    if (!v.empty() && is_Ans(v[0]))
      v[0]=eval(v[0],1,contextptr);
    if (!v.empty() && v[0].type==_IDNT){
      gen v0=v[0];
      gen g=eval(args,eval_level(contextptr),contextptr);
      if (ckmatrix(g[0]))
	return sto(_SWAPCOL(g,contextptr),v0,contextptr);
    }
    if (v.size()!=3 || !ckmatrix(v[0]))
      return gensizeerr(contextptr);
    v[1]=eval(v[1],1,contextptr);
    v[2]=eval(v[2],1,contextptr);
    matrice m;
    mtran(*v[0]._VECTptr,m);
    gen res=_rowSwap(makesequence(m,v[1],v[2]),contextptr);
    if (res.type==_VECT){
      mtran(*res._VECTptr,m);
      res=m;
    }
    return res;
  }
  static const char _SWAPCOL_s[]="SWAPCOL";
  static define_unary_function_eval_quoted (__SWAPCOL,&giac::_SWAPCOL,_SWAPCOL_s);
  define_unary_function_ptr5( at_SWAPCOL ,alias_at_SWAPCOL,&__SWAPCOL,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  static const char _colswap_s[]="colswap";
  static define_unary_function_eval (__colswap,&_SWAPCOL,_colswap_s);
  define_unary_function_ptr5( at_colswap ,alias_at_colswap,&__colswap,0,true);

  static const char _swapcol_s[]="swapcol";
  static define_unary_function_eval (__swapcol,&_SWAPCOL,_swapcol_s);
  define_unary_function_ptr5( at_swapcol ,alias_at_swapcol,&__swapcol,0,true);

  static const char _colSwap_s[]="colSwap";
  static define_unary_function_eval (__colSwap,&_SWAPCOL,_colSwap_s);
  define_unary_function_ptr5( at_colSwap ,alias_at_colSwap,&__colSwap,0,true);

  static const char _DELCOL_s[]="DELCOL";
  static define_unary_function_eval_quoted (__DELCOL,&giac::_delcols,_DELCOL_s);
  define_unary_function_ptr5( at_DELCOL ,alias_at_DELCOL,&__DELCOL,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  static const char _DELROW_s[]="DELROW";
  static define_unary_function_eval_quoted (__DELROW,&giac::_delrows,_DELROW_s);
  define_unary_function_ptr5( at_DELROW ,alias_at_DELROW,&__DELROW,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  static const char _SWAPROW_s[]="SWAPROW";
  static define_unary_function_eval_quoted (__SWAPROW,&giac::_rowSwap,_SWAPROW_s);
  define_unary_function_ptr5( at_SWAPROW ,alias_at_SWAPROW,&__SWAPROW,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _SUB(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    vecteur v(gen2vecteur(args));
    gen v0=v[0];
    v=*eval(v,eval_level(contextptr),contextptr)._VECTptr;
    if (v0.type!=_IDNT){
      if (v.size()<3)
	return gendimerr(contextptr);
      if (ckmatrix(v[0]))
	return _subMat(gen(makevecteur(v[0],v[1],v[2]),_SEQ__VECT),contextptr);
      int shift = xcas_mode(contextptr)!=0 || abs_calc_mode(contextptr)==38;
      if (v[0].type==_VECT && v[1].type==_INT_ && v[2].type==_INT_){
	vecteur & w =*v[0]._VECTptr;
	int v2=v[1].val-shift, v3=v[2].val-shift;
	if (v2<=v3 && v2>=0 && v3<int(w.size()))
	  return gen(vecteur(w.begin()+v2,w.begin()+v3+1),v[1].subtype);
      }
    }
    if (v.size()==3)
      v.insert(v.begin(),v0);
    if (v.size()<4)
      return gendimerr(contextptr);
    v[2]=_floor(v[2],contextptr);
    v[3]=_floor(v[3],contextptr);
    if (ckmatrix(v[1]))
      return sto(_subMat(gen(makevecteur(v[1],v[2],v[3]),_SEQ__VECT),contextptr),v0,contextptr);
    int shift = xcas_mode(contextptr)!=0 || abs_calc_mode(contextptr)==38;
    if (v[1].type==_VECT && v[2].type==_INT_ && v[3].type==_INT_){
      vecteur & w =*v[1]._VECTptr;
      int v2=v[2].val-shift, v3=v[3].val-shift;
      if (v2<=v3 && v2>=0 && v3<int(w.size()))
	return sto(gen(vecteur(w.begin()+v2,w.begin()+v3+1),v[1].subtype),v0,contextptr);
    }
    return undef;
  }
  static const char _SUB_s[]="SUB";
  static define_unary_function_eval_quoted (__SUB,&giac::_SUB,_SUB_s);
  define_unary_function_ptr5( at_SUB ,alias_at_SUB,&__SUB,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _RANDMAT(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    vecteur v(gen2vecteur(args));
    int s=int(v.size());
    if (s==1){
      v[0]=_floor(v[0],contextptr);
      if (v[0].type!=_INT_)
	return gentypeerr(contextptr);
      return vranm(v[0].val,0,contextptr);
    }
    if (s<2)
      return gensizeerr(contextptr);
    gen name=v[0];
    if (name.type!=_IDNT && !name.is_symb_of_sommet(at_double_deux_points))
      return _ranm(eval(args,eval_level(contextptr),contextptr),contextptr);
    v=*eval(v,eval_level(contextptr),contextptr)._VECTptr;
    v[1]=_floor(v[1],contextptr);
    if (v[1].type!=_INT_)
      return gentypeerr(contextptr);
    if (s==2)
      return sto(vranm(v[1].val,0,contextptr),name,contextptr);
    v[2]=_floor(v[2],contextptr);
    if (v[2].type!=_INT_)
      return gentypeerr(contextptr);
    return sto(mranm(v[1].val,v[2].val,0,contextptr),name,contextptr);    
  }
  static const char _RANDMAT_s[]="RANDMAT";
  static define_unary_function_eval_quoted (__RANDMAT,&giac::_RANDMAT,_RANDMAT_s);
  define_unary_function_ptr5( at_RANDMAT ,alias_at_RANDMAT,&__RANDMAT,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _REDIM(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    vecteur v(gen2vecteur(args));
    int s=int(v.size());
    if (s==3)
      return _REDIM(gen(makevecteur(v[0],makevecteur(v[1],v[2])),_SEQ__VECT),contextptr);
    gen name=v[0];
    if (s!=2)
      return gensizeerr(contextptr);
    bool unnamed= name.type!=_IDNT && !name.is_symb_of_sommet(at_double_deux_points);
    v=*eval(v,eval_level(contextptr),contextptr)._VECTptr;
    if (v[0].type!=_VECT)
      return gentypeerr(contextptr);
    vecteur w=*v[0]._VECTptr,argv;
    argv=gen2vecteur(v[1]);
    for (unsigned i=0;i<argv.size();++i){
      if (!is_integral(argv[i]))
	return gentypeerr(contextptr);
    }
    if (ckmatrix(v[0])){
      if (argv.size()==2){
	w.clear();
	int newl=argv[0].val,newc=argv[1].val;
	if (newl<=0 || newc<=0 || newl*newc>LIST_SIZE_LIMIT)
	  return gendimerr(contextptr);
	// create w
	vecteur & v0=*v[0]._VECTptr;
	newl=giacmin(newl,int(v0.size()));
	int nc=giacmin(newc,int(v0.front()._VECTptr->size())),j;
	for (int i=0;i<newl;++i){
	  vecteur & cur = *v0[i]._VECTptr;
	  for (j=0;j<nc;++j){
	    w.push_back(cur[j]);
	  }
	  for (;j<newc;++j)
	    w.push_back(0);
	}
      }
      else
	aplatir(*v[0]._VECTptr,w);
    }
    argv.push_back(w);
    if (unnamed)
      return _matrix(gen(argv,_SEQ__VECT),contextptr);
    return sto(_matrix(gen(argv,_SEQ__VECT),contextptr),name,contextptr);
  }
  static const char _REDIM_s[]="REDIM";
  static define_unary_function_eval_quoted (__REDIM,&giac::_REDIM,_REDIM_s);
  define_unary_function_ptr5( at_REDIM ,alias_at_REDIM,&__REDIM,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  static const char _redim_s[]="redim";
  static define_unary_function_eval_quoted (__redim,&giac::_REDIM,_redim_s);
  define_unary_function_ptr5( at_redim ,alias_at_redim,&__redim,_QUOTE_ARGUMENTS,T_UNARY_OP);

  gen _REPLACE(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    vecteur v(gen2vecteur(args));
    int s=int(v.size());
    gen name=v[0];
    if (s!=3)
      return gensizeerr(contextptr);
    bool unnamed= name.type!=_IDNT && !name.is_symb_of_sommet(at_double_deux_points);
    v=*eval(v,eval_level(contextptr),contextptr)._VECTptr;
    if (v[0].type!=_VECT || v[2].type!=_VECT)
      return gentypeerr(contextptr);
    v[1]=_floor(v[1],contextptr);
    int pos,l,c=0,shift=abs_calc_mode(contextptr)==38; //  && v[1].subtype==_LIST__VECT;
    vecteur w0=*v[0]._VECTptr,w2=*v[2]._VECTptr,argv;
    if (ckmatrix(v[0])){
      mdims(w0,l,c);
      if (ckmatrix(v[2]) && v[1].type==_VECT){
	vecteur & v1=*v[1]._VECTptr;
	if (v1.size()!=2 || v1.front().type!=_INT_ || v1.back().type!=_INT_)
	  return gentypeerr(contextptr);
	int ls,cs,pos1=v1.front().val-shift,pos2=v1.back().val-shift;
	if (pos1<0 || pos1>=l || pos2<0 || pos2>=c)
	  return gendimerr(contextptr);
	mdims(w2,ls,cs);
	std_matrix<gen> target,source;
	matrice2std_matrix_gen(w2,source);
	matrice2std_matrix_gen(w0,target);
	for (int i=0;i<ls;++i){
	  if (i+pos1>=l)
	    break;
	  vecteur & ws =source[i];
	  vecteur & wt =target[i+pos1];
	  for (int j=0;j<cs;++j){
	    if (j+pos2>=c)
	      break;
	    wt[j+pos2]=ws[j];
	  }
	}
	std_matrix_gen2matrice(target,w0);
	if (unnamed)
	  return gen(w0,_MATRIX__VECT);
	return sto(gen(w0,_MATRIX__VECT),name,contextptr);
      }
      aplatir(*v[0]._VECTptr,w0);
    }
    else
      l=int(w0.size());
    if (v[1].type==_VECT){
      vecteur & v1=*v[1]._VECTptr;
      if (v1.size()!=2 || v1.front().type!=_INT_ || v1.back().type!=_INT_)
	return gentypeerr(contextptr);
      pos=(v1.front().val-shift)*c+(v1.back().val-shift);
    }
    else {
      if (v[1].type!=_INT_)
	return gentypeerr(contextptr);
      pos=v[1].val;
      if (abs_calc_mode(contextptr)==38)
	--pos;
    }
    if (ckmatrix(v[2]))
      aplatir(*v[2]._VECTptr,w2);
    int w0s=int(w0.size()),w2s=int(w2.size()),i=giacmax(pos,0),j=0;
    for (;i<w0s && j<w2s;++j,++i){
      w0[i]=w2[j];
    }
    if (!c){
      if (unnamed)
	return gen(w0,v[0].subtype);
      return sto(gen(w0,v[0].subtype),name,contextptr);
    }
    if (unnamed)
      return _matrix(gen(makevecteur(l,c,w0),_SEQ__VECT),contextptr);
    return sto(_matrix(gen(makevecteur(l,c,w0),_SEQ__VECT),contextptr),name,contextptr);
  }
  static const char _REPLACE_s[]="REPLACE";
  static define_unary_function_eval_quoted (__REPLACE,&giac::_REPLACE,_REPLACE_s);
  define_unary_function_ptr5( at_REPLACE ,alias_at_REPLACE,&__REPLACE,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  static const char _replace_s[]="replace";
  static define_unary_function_eval_quoted (__replace,&giac::_REPLACE,_replace_s);
  define_unary_function_ptr5( at_replace ,alias_at_replace,&__replace,_QUOTE_ARGUMENTS,T_UNARY_OP);

  static const char _COLNORM_s[]="COLNORM";
  static define_unary_function_eval (__COLNORM,&giac::_colNorm,_COLNORM_s);
  define_unary_function_ptr5( at_COLNORM ,alias_at_COLNORM,&__COLNORM,0,T_UNARY_OP_38);

  static const char _ROWNORM_s[]="ROWNORM";
  static define_unary_function_eval (__ROWNORM,&giac::_rowNorm,_ROWNORM_s);
  define_unary_function_ptr5( at_ROWNORM ,alias_at_ROWNORM,&__ROWNORM,0,T_UNARY_OP_38);

  static const char _CROSS_s[]="CROSS";
  static define_unary_function_eval (__CROSS,&giac::_cross,_CROSS_s);
  define_unary_function_ptr5( at_CROSS ,alias_at_CROSS,&__CROSS,0,T_UNARY_OP_38);

  static const char _DET_s[]="DET";
  static define_unary_function_eval (__DET,&giac::_det,_DET_s);
  define_unary_function_ptr5( at_DET ,alias_at_DET,&__DET,0,T_UNARY_OP_38);

  static const char _DOT_s[]="DOT";
  static define_unary_function_eval (__DOT,&giac::_dotprod,_DOT_s);
  define_unary_function_ptr5( at_DOT ,alias_at_DOT,&__DOT,0,T_UNARY_OP_38);

  gen _EIGENVAL(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (!is_squarematrix(args))
      return gendimerr(contextptr);
    bool b=complex_mode(contextptr);
    complex_mode(true,contextptr);
    gen res=_egvl(evalf(args,1,contextptr),contextptr);
    res=_diag(res,contextptr);
    complex_mode(b,contextptr);
    return res;
  }
  static const char _EIGENVAL_s[]="EIGENVAL";
  static define_unary_function_eval (__EIGENVAL,&giac::_EIGENVAL,_EIGENVAL_s);
  define_unary_function_ptr5( at_EIGENVAL ,alias_at_EIGENVAL,&__EIGENVAL,0,T_UNARY_OP_38);

  gen _EIGENVV(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (!is_squarematrix(args))
      return gendimerr(contextptr);
    bool b=complex_mode(contextptr);
    complex_mode(true,contextptr);
    gen res=_jordan(evalf(args,1,contextptr),contextptr);
    complex_mode(b,contextptr);
    if (res.type==_VECT) 
      res.subtype=_LIST__VECT;
    return res;
  }
  static const char _EIGENVV_s[]="EIGENVV";
  static define_unary_function_eval (__EIGENVV,&giac::_EIGENVV,_EIGENVV_s);
  define_unary_function_ptr5( at_EIGENVV ,alias_at_EIGENVV,&__EIGENVV,0,T_UNARY_OP_38);

  static const char _IDENMAT_s[]="IDENMAT";
  static define_unary_function_eval (__IDENMAT,&giac::_idn,_IDENMAT_s);
  define_unary_function_ptr5( at_IDENMAT ,alias_at_IDENMAT,&__IDENMAT,0,T_UNARY_OP_38);

  static const char _INVERSE_s[]="INVERSE";
  static define_unary_function_eval (__INVERSE,&giac::inv,_INVERSE_s);
  define_unary_function_ptr5( at_INVERSE ,alias_at_INVERSE,&__INVERSE,0,T_UNARY_OP_38);

  gen _TRACE(const gen & g,GIAC_CONTEXT){
    if (!is_squarematrix(g))
      return gensizeerr(contextptr);
    return mtrace(*g._VECTptr);
  }
  static const char _TRACE_s[]="TRACE";
  static define_unary_function_eval (__TRACE,&giac::_TRACE,_TRACE_s);
  define_unary_function_ptr5( at_TRACE ,alias_at_TRACE,&__TRACE,0,T_UNARY_OP_38);

  static const char _TRN_s[]="TRN";
  static define_unary_function_eval (__TRN,&giac::_trn,_TRN_s);
  define_unary_function_ptr5( at_TRN ,alias_at_TRN,&__TRN,0,T_UNARY_OP_38);

  static const char _RANK_s[]="RANK";
  static define_unary_function_eval (__RANK,&giac::_rank,_RANK_s);
  define_unary_function_ptr5( at_RANK ,alias_at_RANK,&__RANK,0,T_UNARY_OP_38);

  gen _SIZE(const gen& args,GIAC_CONTEXT){
    if (ckmatrix(args))
      return _dim(args,contextptr);
    else
      return _size(args,contextptr);
  }
  static const char _SIZE_s[]="SIZE";
  static define_unary_function_eval (__SIZE,&giac::_SIZE,_SIZE_s);
  define_unary_function_ptr5( at_SIZE ,alias_at_SIZE,&__SIZE,0,T_UNARY_OP_38);

  static const char _SORT_s[]="SORT";
  static define_unary_function_eval (__SORT,&giac::_sort,_SORT_s);
  define_unary_function_ptr5( at_SORT ,alias_at_SORT,&__SORT,0,T_UNARY_OP_38);

  static const char _DELTALIST_s[]="ΔLIST";
  static define_unary_function_eval (__DELTALIST,&giac::_deltalist,_DELTALIST_s);
  define_unary_function_ptr5( at_DELTALIST ,alias_at_DELTALIST,&__DELTALIST,0,T_UNARY_OP_38);

  static const char _CONCAT_s[]="CONCAT";
  static define_unary_function_eval (__CCONCAT,&giac::_concat,_CONCAT_s);
  define_unary_function_ptr5( at_CONCAT ,alias_at_CONCAT,&__CCONCAT,0,T_UNARY_OP_38);

  gen _PILIST(const gen & args,GIAC_CONTEXT){
    if (args.type==_VECT)
      return _product(change_subtype(args,0),contextptr);
    return _product(args,contextptr);
  }
  static const char _PILIST_s[]="ΠLIST";
  static define_unary_function_eval (__PILIST,&giac::_PILIST,_PILIST_s);
  define_unary_function_ptr5( at_PILIST ,alias_at_PILIST,&__PILIST,0,T_UNARY_OP_38);

  gen _SIGMALIST(const gen & args,GIAC_CONTEXT){
    if (args.type==_VECT)
      return _sum(change_subtype(args,0),contextptr);
    return _sum(args,contextptr);
  }
  static const char _SIGMALIST_s[]="ΣLIST";
  static define_unary_function_eval (__SIGMALIST,&giac::_SIGMALIST,_SIGMALIST_s);
  define_unary_function_ptr5( at_SIGMALIST ,alias_at_SIGMALIST,&__SIGMALIST,0,T_UNARY_OP_38);

  static const char _REVERSE_s[]="REVERSE";
  static define_unary_function_eval (__REVERSE,&giac::_revlist,_REVERSE_s);
  define_unary_function_ptr5( at_REVERSE ,alias_at_REVERSE,&__REVERSE,0,T_UNARY_OP_38);

  gen _POS(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG &&  args.subtype==-1) return  args;
    if ( (args.type!=_VECT) || (args._VECTptr->size()!=2) || (args._VECTptr->front().type!=_VECT) )
      return gensizeerr(contextptr);
    return equalposcomp(*args._VECTptr->front()._VECTptr,evalf2bcd(args._VECTptr->back(),1,contextptr));    
  }
  static const char _POS_s[]="POS";
  static define_unary_function_eval (__POS,&giac::_POS,_POS_s);
  define_unary_function_ptr5( at_POS ,alias_at_POS,&__POS,0,T_UNARY_OP_38);

  gen _MAKELIST(const gen & args,GIAC_CONTEXT){
    if (args.type!=_VECT || (args._VECTptr->size()!=4 && args._VECTptr->size()!=5))
      return gensizeerr(contextptr);
    vecteur & v = *args._VECTptr;
    if (v.size()==5 && is_positive(-v[4]*(v[3]-v[2]),contextptr))
      return gensizeerr(gettext("Invalid step value"));
    gen res=giac::_seq(args,contextptr);
    if (res.type==_VECT)
      res.subtype=_LIST__VECT;
    return res;
  }
  static const char _MAKELIST_s[]="MAKELIST";
  static define_unary_function_eval (__MAKELIST,&giac::_MAKELIST,_MAKELIST_s);
  define_unary_function_ptr5( at_MAKELIST ,alias_at_MAKELIST,&__MAKELIST,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _INT(const gen & g,GIAC_CONTEXT){
    if ( g.type==_STRNG && g.subtype==-1) return  g;
    if (g.type==_VECT)
      return apply(g,_INT,contextptr);
    if (g.type==_CPLX)
      return _INT(*g._CPLXptr,contextptr)+cst_i*_INT(*(g._CPLXptr+1),contextptr);
    if (is_positive(g,contextptr))
      return _floor(g,contextptr);
    else {
      if (is_positive(-g,contextptr))
	return _ceil(g,contextptr);
      gen sg=sign(g,contextptr);
      return sg*_floor(g*sg,contextptr);//symbolic(at_when,makesequence(symbolic(at_superieur_egal,makesequence(g,0)),symbolic(at_floor,g),symbolic(at_ceil,g)));
    }
  }
  static const char _INT_s[]="IP";
  static define_unary_function_eval (__INT,&giac::_INT,_INT_s);
  define_unary_function_ptr5( at_INT ,alias_at_INT,&__INT,0,T_UNARY_OP_38);

  static int taylorxn=0;
  static void hp38_eval(vecteur & v,gen & x,gen& newx,GIAC_CONTEXT){
    x=v[1];
    if (is_equal(x))
      x=x._SYMBptr->feuille[0];
    identificateur idx("taylorx"+print_INT_(taylorxn));
    ++taylorxn;
    newx=idx;
    gen tmp=subst(v[0],x,newx,false,contextptr);
    gen tmp1=eval(tmp,eval_level(contextptr),contextptr);
    if (!is_undef(tmp1))
      tmp=tmp1;
    tmp1=subst(tmp,x,newx,false,contextptr);
    if (!is_undef(tmp1))
      tmp=tmp1;
    v[0]=tmp;
    v[1]=newx;
    int s=int(v.size());
    for (int i=2;i<s;++i)
      v[i]=eval(v[i],eval_level(contextptr),contextptr);
  }

  gen _HPDIFF(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    gen tmp;
    if (args.type==_VECT && args.subtype==_SEQ__VECT && args._VECTptr->size()>=2){
      gen value=(*args._VECTptr)[1],var=value;
      if (is_equal(value)){
	var=value._SYMBptr->feuille[0];
	value=value._SYMBptr->feuille[1];
      }
      if (var.type!=_IDNT && abs_calc_mode(contextptr)==38)
	return gensizeerr(gettext("∂(expression,variable=value)"));
      int ndiff=1;
      if (args._VECTptr->size()>=3 && (*args._VECTptr)[2].type==_INT_ ){
	ndiff=(*args._VECTptr)[2].val;
	if (ndiff<0)
	  return gensizeerr(gettext("Order of derivation must be positive"));
      }
      if (args._VECTptr->size()>=4 && abs_calc_mode(contextptr)!=38)
	value=(*args._VECTptr)[3];
      static int count=0;
      gen newx("hpdiffx"+print_INT_(count),contextptr);
      ++count;
      gen arg0=eval(subst(args._VECTptr->front(),var,newx,false,contextptr),eval_level(contextptr),contextptr);
      arg0=subst(arg0,var,newx,false,contextptr);
      if (ndiff==0){
	value=eval(value,1,contextptr);
	tmp=gen(makevecteur(arg0,newx,value),_SEQ__VECT);
	return _limit(tmp,contextptr);
      }
      else {
	if (ndiff==1)
	  tmp=gen(makesequence(arg0,newx));
	else
	  tmp=gen(makevecteur(arg0,newx,ndiff),_SEQ__VECT);
	tmp=_derive(tmp,contextptr);
	// return _limit(makesequence(tmp,newx,value),contextptr);
	tmp=subst(tmp,newx,value,false,contextptr);
	tmp=eval(tmp,1,contextptr);
	return tmp;
      }
    }
    else {
      gen a(args);
      if (guess_program(a,contextptr))
	return _derive(a,contextptr);
      return _HPDIFF(gen(makevecteur(args,vx_var),_SEQ__VECT),contextptr);
    }
  }
  static const char _HPDIFF_s[]="∂";
  static define_unary_function_eval_quoted (__HPDIFF,&giac::_HPDIFF,_HPDIFF_s);
  define_unary_function_ptr5( at_HPDIFF ,alias_at_HPDIFF,&__HPDIFF,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _HPINT(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args.type==_VECT && args.subtype==_SEQ__VECT){
      vecteur v = *args._VECTptr;
      if (v.size()==3){
	if (is_equal(v.front())){
	  gen var=v.front()._SYMBptr->feuille[0];
	  gen lower=v.front()._SYMBptr->feuille[1];
	  v=makevecteur(v[2],var,lower,v[1]);
	}
	if (is_equal(v[1])){
	  gen var=v[1]._SYMBptr->feuille[0];
	  gen lower=v[1]._SYMBptr->feuille[1];
	  v=makevecteur(v.front(),var,lower,v[2]);
	}
	if (v.size()==3)
	  return _integrate(args,contextptr);
      }
      if (v.size()>=4){
	if (v[1].type!=_IDNT){
	  return gensizeerr(gettext("∫(expression,var,lower,upper)"));
	  // swapgen(v[0],v[2]);
	  // swapgen(v[1],v[3]);
	}
	gen x,newx;
	hp38_eval(v,x,newx,contextptr);
	gen tmp=_integrate(gen(v,_SEQ__VECT),contextptr);
	if (eval(x,1,contextptr)!=x)
	  return tmp; 
	else
	  return subst(tmp,newx,x,false,contextptr);
	// if we subst then the value of x may alter tmp even with subst
      }
    }
#ifndef CAS38_DISABLED
    return _integrate(args,contextptr);
#else
    return gensizeerr(contextptr);
#endif
  }
  static const char _HPINT_s[]="∫";
  static define_unary_function_eval_quoted (__HPINT,&giac::_HPINT,_HPINT_s);
  define_unary_function_ptr5( at_HPINT ,alias_at_HPINT,&__HPINT,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _HPSUM(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args.type==_VECT && args.subtype==_SEQ__VECT && args._VECTptr->size()<=3){
      if (args._VECTptr->size()!=3)
	return gensizeerr(contextptr);
      const vecteur & v = *args._VECTptr;
      if (is_equal(v[0])){
	gen var=v[0]._SYMBptr->feuille[0];
	if (var.type!=_IDNT)
	  return gensizeerr(contextptr);
	gen inf=v[0]._SYMBptr->feuille[1];
	gen sup=v[1];
	gen expr=v[2];
	return _sum(gen(makevecteur(expr,var,inf,sup),_SEQ__VECT),contextptr);
      }
      if (is_equal(v[1])){
	gen var=v[1]._SYMBptr->feuille[0];
	if (var.type!=_IDNT)
	  return gensizeerr(contextptr);
	gen inf=v[1]._SYMBptr->feuille[1];
	gen sup=v[2];
	gen expr=v[0];
	return _sum(gen(makevecteur(expr,var,inf,sup),_SEQ__VECT),contextptr);
      }
    }
    return _sum(args,contextptr);
  }
  static const char _HPSUM_s[]="Σ"; // "∑";
  // static const char _HPSUM_s[]="∑"; // "Σ";
  static define_unary_function_eval_quoted (__HPSUM,&giac::_HPSUM,_HPSUM_s);
  define_unary_function_ptr5( at_HPSUM ,alias_at_HPSUM,&__HPSUM,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _TAYLOR(const gen & args,GIAC_CONTEXT){
#ifdef CAS38_DISABLED
    return gensizeerr(contextptr);
#endif
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args.type!=_VECT)
      return gentypeerr(contextptr);
    vecteur v = *args._VECTptr;
    if (v.size()<2)
      v.push_back(x__IDNT_e);
    gen x,newx;
    hp38_eval(v,x,newx,contextptr);
    gen res=subst(_taylor(gen(v,_SEQ__VECT),contextptr),newx,x,false,contextptr);
    v=lop(res,at_order_size);
    res=subst(res,v,vecteur(v.size()),false,contextptr);
    return res;
  }
  static const char _TAYLOR_s[]="TAYLOR";
  static define_unary_function_eval_quoted (__TAYLOR,&_TAYLOR,_TAYLOR_s);
  define_unary_function_ptr5( at_TAYLOR ,alias_at_TAYLOR,&__TAYLOR,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _POLYCOEFF(const gen &args0,GIAC_CONTEXT){
    gen args=eval(args0,1,contextptr);
    if (args.type==_VECT && args.subtype!=_SEQ__VECT)
      return _pcoeff(args,contextptr);
    return _symb2poly(args0,contextptr);
  }
  static const char _POLYCOEF_s[]="POLYCOEF";
  static define_unary_function_eval (__POLYCOEF,&giac::_POLYCOEFF,_POLYCOEF_s);
  define_unary_function_ptr5( at_POLYCOEF ,alias_at_POLYCOEF,&__POLYCOEF,_QUOTE_ARGUMENTS,T_UNARY_OP);

  gen _horner(const gen & args,GIAC_CONTEXT);
  gen _POLYEVAL(const gen & args,GIAC_CONTEXT){
    if (args.type!=_VECT)
      return gentypeerr(contextptr);
    if (args.subtype!=_SEQ__VECT)
      return _POLYFORM(_horner(gen(makevecteur(args,vx_var),_SEQ__VECT),contextptr),contextptr);
    return _horner(args,contextptr);
  }
  static const char _POLYEVAL_s[]="POLYEVAL";
  static define_unary_function_eval (__POLYEVAL,&giac::_POLYEVAL,_POLYEVAL_s);
  define_unary_function_ptr5( at_POLYEVAL ,alias_at_POLYEVAL,&__POLYEVAL,0,T_UNARY_OP_38);

  gen evalfunc(const gen & args,GIAC_CONTEXT){
#ifdef GIAC_HAS_STO_38
    vecteur v(lidnt(args));
    vecteur lf,lfval;
    for (unsigned i=0;i<v.size();++i){
      if (v[i].type!=_IDNT)
	continue;
      const char * ch=v[i]._IDNTptr->id_name;
      if (strlen(ch)==2 && (ch[0]=='F' || ch[0]=='X' || ch[0]=='Y' || ch[0]=='R')){
	lf.push_back(v[i]);
	lfval.push_back(eval(v[i],1,contextptr));
      }
    }
    if (lf.empty())
      return args;
    return subst(args,lf,lfval,false,contextptr);
#else
    return args;
#endif
  }
  static string printasPOLYFORM(const gen &feuille,const char * sommetstr,GIAC_CONTEXT){
    if (feuille.type==_VECT && feuille._VECTptr->size()==2 && feuille._VECTptr->back().type==_FUNC){
      const char * s=feuille._VECTptr->back()._FUNCptr->ptr()->s;
      return feuille._VECTptr->front().print(contextptr)+"\xe2\x96\xba"+((strcmp(s,"eval")==0)?"\xe2\x96\xba":s);
    }
    return string(sommetstr)+('('+feuille.print(contextptr)+')');
  }
  gen _POLYFORM(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return args;
    gen tmp;
    if (args.type==_VECT && !args._VECTptr->empty()){
      const vecteur & v = *args._VECTptr;
      tmp=v[0];
      tmp=eval(tmp,1,context0);
      tmp=evalfunc(tmp,contextptr);
      int vs=int(v.size());
#ifdef CAS38_DISABLED
      if (vs==2 && v.back()==at_prod && is_integral(tmp))
	return _ifactor(tmp,context0);
#else
      if (vs==2){
	if (v.back()==at_eval) return tmp;
	if (v.back()==at_prod){
	  if (is_integral(tmp))
	    return _ifactor(tmp,context0);
	  return _factor(tmp,context0);
	}
	if (v.back()==at_plus)
	  return _partfrac(tmp,context0); 
	if (v.back().type==_FUNC)
	  return _convert(gen(makevecteur(tmp,v.back()),_SEQ__VECT),context0);
      }
#endif
      if (v.back().type==_FUNC) // additional check for STO> +/-/etc. if CAS38_DISABLED is set
	return gensizeerr(contextptr);
      if (vs>1)
	return _reorder(makesequence(tmp,vecteur(v.begin()+1,v.end())),context0);
    }
    tmp=eval(args,1,context0);
    tmp=evalfunc(tmp,contextptr);
    return _recursive_normal(tmp,context0); // return symb_quote(_partfrac(args,contextptr)); // return symb_quote(recursive_normal(args,1,contextptr)); // symb_quote(simplify(eval(args,1,context0),context0));
  }
  static const char _POLYFORM_s[]="POLYFORM";
  static define_unary_function_eval2_quoted (__POLYFORM,&giac::_POLYFORM,_POLYFORM_s,&printasPOLYFORM);
  define_unary_function_ptr5( at_POLYFORM ,alias_at_POLYFORM,&__POLYFORM,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _POLYROOT(const gen & args0,GIAC_CONTEXT){
    gen args=eval(args0,1,contextptr);
    if (args.type==_VECT && args.subtype!=_SEQ__VECT)
      ;
    else
      args=args0;
    gen res;
    if (complex_mode(contextptr))
      res=_proot(args,contextptr);
    else {
#if 0 // set to 1 : POLYROOT returns only real roots without multiplicities, SLOW on aspen
      vecteur vas_res;
      if (vas(symb2poly_num(args,contextptr),0,0,1e-14,vas_res,false,contextptr))
	res=vas_res;
      else
	res=_proot(args,contextptr);
#else
      res=_proot(args,contextptr);
#endif
    }
#ifdef GIAC_HAS_STO_38
    if (res.type==_VECT)
      res.subtype=_LIST__VECT;
#endif
    return res;
  }
  static const char _POLYROOT_s[]="POLYROOT";
  static define_unary_function_eval (__POLYROOT,&giac::_POLYROOT,_POLYROOT_s);
  define_unary_function_ptr5( at_POLYROOT ,alias_at_POLYROOT,&__POLYROOT,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _ISOLATE(const gen & args0,GIAC_CONTEXT){
#ifdef CAS38_DISABLED
    return gensizeerr(contextptr);
#endif
    return symb_quote(_solve(args0,contextptr));
  }
  static const char _ISOLATE_s[]="ISOLATE";
  static define_unary_function_eval_quoted (__ISOLATE,&giac::_ISOLATE,_ISOLATE_s);
  define_unary_function_ptr5( at_ISOLATE ,alias_at_ISOLATE,&__ISOLATE,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  static const char _QUAD_s[]="QUAD";
  static define_unary_function_eval_quoted (__QUAD,&giac::_ISOLATE,_QUAD_s);
  define_unary_function_ptr5( at_QUAD ,alias_at_QUAD,&__QUAD,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _IS_LINEAR(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args.type==_VECT && args._VECTptr->size()==2){
      vecteur & v = *args._VECTptr;
      gen a,b;
      if (v[1].type==_IDNT && is_linear_wrt(v[0],v[1],a,b,contextptr))
	return makevecteur(eval(a,eval_level(contextptr),contextptr),eval(b, eval_level(contextptr),contextptr));
      else
	return 0;
    }
    return gentypeerr(contextptr);
    // return 0;
  }
  static const char _IS_LINEAR_s[]="LINEAR?";
  static define_unary_function_eval_quoted (__IS_LINEAR,&giac::_IS_LINEAR,_IS_LINEAR_s);
  define_unary_function_ptr5( at_IS_LINEAR ,alias_at_IS_LINEAR,&__IS_LINEAR,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  static const char _FNROOT_s[]="FNROOT";
  static define_unary_function_eval (__FNROOT,&giac::_fsolve,_FNROOT_s);
  define_unary_function_ptr5( at_FNROOT ,alias_at_FNROOT,&__FNROOT,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  gen _SVD(const gen & args0,GIAC_CONTEXT){
    if ( args0.type==_STRNG && args0.subtype==-1) return  args0;
    if (!ckmatrix(args0))
      return gentypeerr(contextptr);
    if (!has_num_coeff(args0))
      *logptr(contextptr) << gettext("SVD is implemented for numeric matrices, running evalf first") << endl;
    gen args=evalf(args0,1,contextptr);
    gen res= _svd(gen(makevecteur(args,-1),_SEQ__VECT),contextptr);
    if (res.type==_VECT) res.subtype=_LIST__VECT;
    return res;    
  }
  static const char _SVD_s[]="SVD";
  static define_unary_function_eval (__SVD,&giac::_SVD,_SVD_s); // FIXME
  define_unary_function_ptr5( at_SVD ,alias_at_SVD,&__SVD,0,T_UNARY_OP_38);

  gen _SVL(const gen & args0,GIAC_CONTEXT){
    if ( args0.type==_STRNG && args0.subtype==-1) return  args0;
    if (!ckmatrix(args0))
      return gentypeerr(contextptr);
    gen args=evalf(args0,1,contextptr);
    return _svd(gen(makevecteur(args,-2),_SEQ__VECT),contextptr);
  }
  static const char _SVL_s[]="SVL";
  static define_unary_function_eval (__SVL,&giac::_SVL,_SVL_s); 
  define_unary_function_ptr5( at_SVL ,alias_at_SVL,&__SVL,0,T_UNARY_OP_38);

  static const char _svl_s[]="svl";
  static define_unary_function_eval (__svl,&giac::_SVL,_svl_s); 
  define_unary_function_ptr5( at_svl ,alias_at_svl,&__svl,0,T_UNARY_OP);

  gen _SPECRAD(const gen & args0,GIAC_CONTEXT){
    if ( args0.type==_STRNG && args0.subtype==-1) return  args0;
    gen args=evalf(args0,1,contextptr);
    if (!is_squarematrix(args))
      return gentypeerr(contextptr);
    vecteur v=megvl(*args._VECTptr,contextptr);
    if (is_undef(v)) return v;
    gen res,tmp;
    int s=int(v.size());
    for (int i=0;i<s;++i){
      tmp=abs(v[i],contextptr);
      if (ck_is_strictly_greater(tmp,res,contextptr))
	res=tmp;
    }
    return res;
  }
  static const char _SPECRAD_s[]="SPECRAD";
  static define_unary_function_eval (__SPECRAD,&giac::_SPECRAD,_SPECRAD_s); // FIXME
  define_unary_function_ptr5( at_SPECRAD ,alias_at_SPECRAD,&__SPECRAD,0,T_UNARY_OP_38);

  gen _SPECNORM(const gen & args0,GIAC_CONTEXT){
    if ( args0.type==_STRNG && args0.subtype==-1) return  args0;
    gen args=evalf(args0,1,contextptr);
    if (!ckmatrix(args)){
      if (args.type==_VECT)
	return _l2norm(args,contextptr);
      return gentypeerr(contextptr);
    }
    return _max(_SVL(*args._VECTptr,contextptr),contextptr);
  }
  static const char _SPECNORM_s[]="SPECNORM";
  static define_unary_function_eval (__SPECNORM,&giac::_SPECNORM,_SPECNORM_s); // FIXME
  define_unary_function_ptr5( at_SPECNORM ,alias_at_SPECNORM,&__SPECNORM,0,T_UNARY_OP_38);

  gen _COND(const gen & args0,GIAC_CONTEXT){
    if ( args0.type==_STRNG && args0.subtype==-1) return  args0;
    // COND(matrix,2) L2norm condition number
    // otherwise COLNORM(args0)*COLNORM(inv(args0))
    if (args0.type==_VECT && args0._VECTptr->size()==2){ 
      if (args0._VECTptr->back()==1)
	return _COND(args0._VECTptr->front(),contextptr);
      if (args0._VECTptr->back()==2){
	gen args=args0._VECTptr->front();
	if (!ckmatrix(args))
	  return gentypeerr(contextptr);
	double save_eps=epsilon(contextptr);
	epsilon(0.0,contextptr); // otherwise small singular values are cancelled and condition is infinity
	gen g=_SVL(args,contextptr);
	epsilon(save_eps,contextptr);
	if (is_undef(g)) return g;
	if (g.type!=_VECT)
	  return undef;
	vecteur & v =*g._VECTptr;
	int s=int(v.size());
	gen mina(plus_inf),maxa(0);
	for (int i=0;i<s;++i){
	  gen tmp=abs(v[i],contextptr);
	  if (ck_is_strictly_greater(mina,tmp,contextptr))
	    mina=tmp;
	  if (ck_is_strictly_greater(tmp,maxa,contextptr))
	    maxa=tmp;
	}
	return maxa/mina;
      }
      if (is_inf(args0._VECTptr->back())){
	gen args=evalf(args0._VECTptr->front(),1,contextptr);
	if (!is_squarematrix(args))
	  return gensizeerr(contextptr);
	gen invargs=inv(args,contextptr);
	if (is_undef(invargs))
	  return undef;
	return _rowNorm(args,contextptr)*_rowNorm(invargs,contextptr);
      }
    }
    gen args=evalf(args0,1,contextptr);
    if (!is_squarematrix(args))
      return gensizeerr(contextptr);
    gen invargs=inv(args,contextptr);
    if (is_undef(invargs))
      return undef;
    return _colNorm(args,contextptr)*_colNorm(invargs,contextptr);
    // return _colNorm(args,contextptr)*_rowNorm(args,contextptr)/abs(_det(args,contextptr),contextptr);
  }
  static const char _COND_s[]="COND";
  static define_unary_function_eval (__COND,&giac::_COND,_COND_s); // FIXME
  define_unary_function_ptr5( at_COND ,alias_at_COND,&__COND,0,T_UNARY_OP_38);

  static const char _cond_s[]="cond";
  static define_unary_function_eval (__cond,&giac::_COND,_cond_s); // FIXME
  define_unary_function_ptr5( at_cond ,alias_at_cond,&__cond,0,T_UNARY_OP);

  gen _SCHUR(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    gen res;
    if (ckmatrix(args)){
      if (!is_squarematrix(args))
	return gendimerr(contextptr);
#ifdef HAVE_LIBMPFR
      res= _hessenberg(gen(makevecteur(args,epsilon(contextptr)),_SEQ__VECT),contextptr); 
#else
      res= _hessenberg(gen(makevecteur(args,1e-12),_SEQ__VECT),contextptr); 
#endif
    }
    else
      res= _hessenberg(args,contextptr);
    if (res.type==_VECT) res.subtype=_LIST__VECT;
    return res;
  }
  static const char _SCHUR_s[]="SCHUR";
  static define_unary_function_eval (__SCHUR,&giac::_SCHUR,_SCHUR_s); // FIXME
  define_unary_function_ptr5( at_SCHUR ,alias_at_SCHUR,&__SCHUR,0,T_UNARY_OP_38);

  static const char _schur_s[]="schur";
  static define_unary_function_eval (__schur,&giac::_SCHUR,_schur_s); // FIXME
  define_unary_function_ptr5( at_schur ,alias_at_schur,&__schur,0,T_UNARY_OP);

  gen _LQ(const gen & args0,GIAC_CONTEXT){
    if ( args0.type==_STRNG && args0.subtype==-1) return  args0;
    gen args=evalf(args0,1,contextptr);
    if (!ckmatrix(args))
      return gentypeerr(contextptr);
    gen res=qr(makevecteur(_trn(args,contextptr),-1),contextptr);
    if (is_undef(res) || res.type!=_VECT || res._VECTptr->size()<3)
      return gensizeerr(contextptr);
    vecteur v(*res._VECTptr);
    v[0]=_trn(v[0],contextptr);
    v[1]=_trn(v[1],contextptr);
    swapgen(v[0],v[1]);
    // v[2]=midn(v[0]._VECTptr->size());
    return gen(v,_LIST__VECT);
  }
  static const char _LQ_s[]="LQ";
  static define_unary_function_eval (__LQ,&giac::_LQ,_LQ_s); 
  define_unary_function_ptr5( at_LQ ,alias_at_LQ,&__LQ,0,T_UNARY_OP_38);

  static const char _RREF_s[]="RREF";
  static define_unary_function_eval (__RREF,&giac::_rref,_RREF_s); // FIXME
  define_unary_function_ptr5( at_RREF ,alias_at_RREF,&__RREF,0,T_UNARY_OP_38);

  gen _XPON(const gen & g0,GIAC_CONTEXT){
    if (g0.type==_STRNG && g0.subtype==-1) return g0;
    if (is_equal(g0))
      return apply_to_equal(g0,_XPON,contextptr);
    if (g0.type==_VECT)
      return apply(g0,_XPON,contextptr);
#if 0 // def BCD
    gen g=evalf2bcd(g0,1,contextptr);
#else
    gen g=evalf_double(g0,1,contextptr);
#endif
    if (is_exactly_zero(g))
      return undef;
    gen gf=_floor(log10(abs(g,contextptr),contextptr),contextptr); 
    if (gf.type!=_INT_ && gf.type!=_FLOAT_)
      return gensizeerr(contextptr);
    return gf;
  }
  static const char _XPON_s[]="XPON";
  static define_unary_function_eval (__XPON,&giac::_XPON,_XPON_s); // FIXME
  define_unary_function_ptr5( at_XPON ,alias_at_XPON,&__XPON,0,T_UNARY_OP_38);

  gen mantissa(const gen & g0,bool includesign,GIAC_CONTEXT){
#if 0 // def BCD
    gen g=evalf2bcd(g0,1,contextptr);
#else
    gen g=evalf_double(g0,1,contextptr);
#endif
    if (is_exactly_zero(g))
      return g;
    gen gabs=abs(g,contextptr);
    gen gf=_floor(log10(gabs,contextptr),contextptr); 
    if (abs_calc_mode(contextptr)!=38 && gf.type!=_INT_)
      return gensizeerr(contextptr);
    // FIXME number of digits
    return (includesign?sign(g,contextptr):1)*evalf(gabs*alog10(-gf,contextptr),1,contextptr);
  }
  gen _MANT(const gen & g0,GIAC_CONTEXT){
    if (g0.type==_STRNG && g0.subtype==-1) return g0;
    if (is_equal(g0))
      return apply_to_equal(g0,_MANT,contextptr);
    if (g0.type==_VECT)
      return apply(g0,_MANT,contextptr);
    return mantissa(g0,true,contextptr);
  }
  static const char _MANT_s[]="MANT";
  static define_unary_function_eval (__MANT,&giac::_MANT,_MANT_s); 
  define_unary_function_ptr5( at_MANT ,alias_at_MANT,&__MANT,0,T_UNARY_OP_38);

  gen _mantissa(const gen & g0,GIAC_CONTEXT){
    if (g0.type==_STRNG && g0.subtype==-1) return g0;
    if (is_equal(g0))
      return apply_to_equal(g0,_mantissa,contextptr);
    if (g0.type==_VECT)
      return apply(g0,_mantissa,contextptr);
    return mantissa(g0,false,contextptr);
  }
  static const char _mantissa_s[]="mantissa";
  static define_unary_function_eval (__mantissa,&giac::_mantissa,_mantissa_s); 
  define_unary_function_ptr5( at_mantissa ,alias_at_mantissa,&__mantissa,0,T_UNARY_OP);

  gen _HMSX(const gen & g0,GIAC_CONTEXT){
    if ( g0.type==_STRNG && g0.subtype==-1) return  g0;
    if (g0.type==_VECT)
      return apply(g0,_HMSX,contextptr);
    gen g(evalf(g0,1,contextptr));
    if (g.type==_DOUBLE_)
      g = g+1e-12;
    if (g.type==_FLOAT_)
      g = g+plus_one/20000;
    if (g.type!=_DOUBLE_ && g.type!=_FLOAT_)
      return gentypeerr(contextptr);
    gen h=_floor(g,contextptr);
    gen m=_floor(100*(g-h),contextptr);
    gen s=_floor(100*(100*(g-h)-m),contextptr);
    return h+m/giac_float(60.)+s/giac_float(3600.);
  }
  static const char _HMSX_s[]="HMSX";
  static define_unary_function_eval (__HMSX,&giac::_HMSX,_HMSX_s); 
  define_unary_function_ptr5( at_HMSX ,alias_at_HMSX,&__HMSX,0,T_UNARY_OP_38);

  gen _XHMS(const gen & g0,GIAC_CONTEXT){
    if ( g0.type==_STRNG && g0.subtype==-1) return  g0;
    if (g0.type==_VECT)
      return apply(g0,_XHMS,contextptr);
    gen g(evalf(g0,1,contextptr));
    if (g.type==_DOUBLE_)
      g = g+1e-12;
    if (g.type==_FLOAT_)
      g=g+plus_one/7200;
    if (g.type!=_DOUBLE_ && g.type!=_FLOAT_)
      return gentypeerr(contextptr);
    gen h=_floor(g,contextptr);
    gen m=_floor(60*(g-h),contextptr);
    gen s=_floor(60*(60*(g-h)-m),contextptr);
    return h+m/giac_float(100.)+s/giac_float(10000.);
  }
  static const char _XHMS_s[]="XHMS";
  static define_unary_function_eval (__XHMS,&giac::_XHMS,_XHMS_s); 
  define_unary_function_ptr5( at_XHMS ,alias_at_XHMS,&__XHMS,0,T_UNARY_OP_38);

  gen _DEGXRAD(const gen & g,GIAC_CONTEXT){
    if ( g.type==_STRNG && g.subtype==-1) return  g;
    if (g.type==_VECT)
      return apply(g,_DEGXRAD,contextptr);
    return deg2rad_d*g;
  }
  static const char _DEGXRAD_s[]="DEGXRAD";
  static define_unary_function_eval (__DEGXRAD,&giac::_DEGXRAD,_DEGXRAD_s); 
  define_unary_function_ptr5( at_DEGXRAD ,alias_at_DEGXRAD,&__DEGXRAD,0,T_UNARY_OP_38);

  gen _RADXDEG(const gen & g,GIAC_CONTEXT){
    if ( g.type==_STRNG && g.subtype==-1) return  g;
    if (g.type==_VECT)
      return apply(g,_RADXDEG,contextptr);
    return rad2deg_d*g;
  }
  static const char _RADXDEG_s[]="RADXDEG";
  static define_unary_function_eval (__RADXDEG,&giac::_RADXDEG,_RADXDEG_s); 
  define_unary_function_ptr5( at_RADXDEG ,alias_at_RADXDEG,&__RADXDEG,0,T_UNARY_OP_38);

  gen _PERCENT(const gen & g,GIAC_CONTEXT){
    if ( g.type==_STRNG && g.subtype==-1) return  g;
    if (g.type!=_VECT || g._VECTptr->size()!=2)
      return gentypeerr(contextptr);
    return g._VECTptr->front()*g._VECTptr->back()/giac_float(100.);
  }
  static const char _PERCENT_s[]="%"; // FIXE
  static define_unary_function_eval (__PERCENT,&giac::_PERCENT,_PERCENT_s); 
  define_unary_function_ptr5( at_PERCENT ,alias_at_PERCENT,&__PERCENT,0,T_UNARY_OP_38);

  gen _PERCENTCHANGE(const gen & g,GIAC_CONTEXT){
    if ( g.type==_STRNG && g.subtype==-1) return  g;
    if (g.type!=_VECT || g._VECTptr->size()!=2)
      return gentypeerr(contextptr);
    return giac_float(100.)*(g._VECTptr->back()-g._VECTptr->front())/g._VECTptr->front();
  }
  static const char _PERCENTCHANGE_s[]="%CHANGE"; 
  static define_unary_function_eval (__PERCENTCHANGE,&giac::_PERCENTCHANGE,_PERCENTCHANGE_s); 
  define_unary_function_ptr5( at_PERCENTCHANGE ,alias_at_PERCENTCHANGE,&__PERCENTCHANGE,0,T_UNARY_OP_38);

  gen _PERCENTTOTAL(const gen & g,GIAC_CONTEXT){
    if ( g.type==_STRNG && g.subtype==-1) return  g;
    if (g.type!=_VECT || g._VECTptr->size()!=2)
      return gentypeerr(contextptr);
    return giac_float(100.)*g._VECTptr->back()/g._VECTptr->front();
  }
  static const char _PERCENTTOTAL_s[]="%TOTAL";
  static define_unary_function_eval (__PERCENTTOTAL,&giac::_PERCENTTOTAL,_PERCENTTOTAL_s); 
  define_unary_function_ptr5( at_PERCENTTOTAL ,alias_at_PERCENTTOTAL,&__PERCENTTOTAL,0,T_UNARY_OP_38);

  gen _DISP(const gen & g,GIAC_CONTEXT){
    if (g.type!=_VECT || g._VECTptr->size()!=2)
      return gensizeerr(contextptr);
    gen a=g._VECTptr->front();
    if (a.type!=_INT_ || a.val <0 || a.val>10)
      setdimerr(contextptr);
    gen b=g._VECTptr->back();
    return _legende(gen(makevecteur(makevecteur(0,a*gen(12)),b),_SEQ__VECT),contextptr);
  }
  static const char _DISP_s []="DISP";
  static define_unary_function_eval_quoted (__DISP,&giac::_DISP,_DISP_s);
  define_unary_function_ptr5( at_DISP ,alias_at_DISP,&__DISP,0,T_UNARY_OP_38);

  static const char _WAIT_s []="WAIT";
  static define_unary_function_eval (__WAIT,&giac::_Pause,_WAIT_s);
  define_unary_function_ptr5( at_WAIT ,alias_at_WAIT,&__WAIT,0,T_UNARY_OP_38);

#if 0 // def GIAC_HAS_STO_38
  gen aspen_input(const vecteur & v,GIAC_CONTEXT);
  gen aspen_msgbox(const vecteur & v,GIAC_CONTEXT);
#endif

  // INPUT(A) or INPUT(A,"title") or INPUT(A,"title","label") or INPUT(A,"title","label","help")
  // or INPUT(A,"title","label","help",default_value)
  gen _INPUT(const gen & args,GIAC_CONTEXT){
    vecteur v=gen2vecteur(args);
    int s=int(v.size());
    if (s==1){
      v.push_back(string2gen("Input"));
      ++s;
    }
    if (s==2){
      v.push_back(string2gen(v[0].print(contextptr),false));
      ++s;
    }
    if (s==3){
      v.push_back(string2gen("Enter value for "+v[0].print(contextptr),false));
      ++s;
    }
    // check types
    if (v[0].is_symb_of_sommet(at_double_deux_points) && v[0]._SYMBptr->feuille.type==_VECT && v[0]._SYMBptr->feuille._VECTptr->size()==2)
      v[0]=v[0]._SYMBptr->feuille._VECTptr->back();
    for (int i=1; i<=3; i++) { if (v[i].type!=_STRNG) v[i]= eval(v[i], 1, contextptr); if (v[i].type!=_STRNG) v[i]=  string2gen(v[i].print(contextptr)); }
    if (v[0].type!=_IDNT || s>5)
      return gentypeerr(contextptr);
    // set default value in v[0]
    if (s==5){
      gen tmpsto=sto(v[4],v[0],contextptr);
      if (is_undef(tmpsto)) return tmpsto;
      v.pop_back();
      s=4;
    }
#if 0 // def GIAC_HAS_STO_38
    return aspen_input(v,contextptr);
#else
    // now make a dialog
    v[1]=symbolic(at_Title,v[1]);
    v[2]=symbolic(at_Request,makesequence(v[2],v[0]));
    v[3]=symbolic(at_Text,v[3]);
    v.erase(v.begin());
    return _Dialog(gen(v,_SEQ__VECT),contextptr);
#endif
  }
  static const char _INPUT_s []="INPUT";
  static define_unary_function_eval_quoted (__INPUT,giac::_INPUT,_INPUT_s);
  define_unary_function_ptr5( at_INPUT ,alias_at_INPUT,&__INPUT,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

#if 0 // def GIAC_HAS_STO_38
  // MSGBOX(txt) or MSGBOX(txt, true/false) to have OK/Cancel or just OK menus
  gen _MSGBOX(const gen & args,GIAC_CONTEXT){
    vecteur v=gen2vecteur(args);
    int s=int(v.size());
    if (s==1) { v.push_back(gen(0)); ++s; }
    return aspen_msgbox(v,contextptr);
  }
#else
  gen _MSGBOX(const gen & args,GIAC_CONTEXT){
    return _output(args,contextptr);
  }
#endif
  static const char _MSGBOX_s []="MSGBOX";
  static define_unary_function_eval (__MSGBOX,giac::_MSGBOX,_MSGBOX_s);
  define_unary_function_ptr5( at_MSGBOX ,alias_at_MSGBOX,&__MSGBOX,0,T_UNARY_OP_38);

  static const char _GETKEY_s[]="GETKEY";
#if 0 // def GIAC_HAS_STO_38
  static define_unary_function_eval(__GETKEY,&at_GETKEYAspen,_GETKEY_s);
  // unary_function_eval __GETKEY(0,&at_GETKEYAspen,_GETKEY_s);
#else
  unary_function_eval __GETKEY(0,&_getKey,_GETKEY_s);
#endif
  define_unary_function_ptr5( at_GETKEY ,alias_at_GETKEY,&__GETKEY,0,T_UNARY_OP_38);

  gen _ITERATE(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args.type!=_VECT || args._VECTptr->size()!=4)
      return gentypeerr(contextptr);
    vecteur v = plotpreprocess(args,contextptr);
    gen v0=v[0];
    gen v1=v[1];
    // v[2]=eval(v[2],eval_level(contextptr),contextptr);
    // v[3]=eval(v[3],eval_level(contextptr),contextptr);
    if (v[3].type!=_INT_)
      return gentypeerr(contextptr);
    int n=v[3].val;
    bool all=n<0;
    if (all){
      n=-n;
      if (n>LIST_SIZE_LIMIT)
	return gendimerr(contextptr);
    }
    gen value=v[2];
    vecteur res;
    if (all)
      res=vecteur(n+1,value);
    for (int i=0;!ctrl_c && !interrupted && i<n;++i){
#ifdef TIMEOUT
      control_c();
#endif
      value=evalf(subst(v0,v1,value,false,contextptr),eval_level(contextptr),contextptr);
      if (is_undef(value))
	return value;
      if (all)
	res[i+1]=value;
    }
    return all?res:value;
  }
  static const char _ITERATE_s[]="ITERATE";
  static define_unary_function_eval_quoted (__ITERATE,&_ITERATE,_ITERATE_s);
  define_unary_function_ptr5( at_ITERATE ,alias_at_ITERATE,&__ITERATE,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

#ifndef GIAC_HAS_STO_38
  gen _RECURSE(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args.type!=_VECT || args._VECTptr->size()<2)
      return gentypeerr(contextptr);
    vecteur v = *args._VECTptr;
    gen v0=v[0];
    gen v1=v[1];
    int s=int(v.size());
    for (int i=2;i<s;++i)
      v[i]=eval(v[i],eval_level(contextptr),contextptr);
    if (v[0].type!=_IDNT)
      return _rsolve(gen(v,args.subtype),contextptr);
    // HP38 syntax, define recurrent sequence
    // idnt, expression, first term, second term
    // e.g. RECURSE(U,U(N-1)*N,1,2) STO> U1(N)
    return gentypeerr(contextptr);
    return undef;
  }  
  static const char _RECURSE_s[]="RECURSE";
  static define_unary_function_eval_quoted (__RECURSE,&_RECURSE,_RECURSE_s);
  define_unary_function_ptr5( at_RECURSE ,alias_at_RECURSE,&__RECURSE,_QUOTE_ARGUMENTS,T_UNARY_OP_38);
#endif

  gen _MAKEMAT(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args.type!=_VECT || args._VECTptr->size()!=3)
      return gentypeerr(contextptr);
    vecteur v = *args._VECTptr;
    gen v0=v[0];
    gen v1=eval(v[1],eval_level(contextptr),contextptr);
    gen v2=eval(v[2],eval_level(contextptr),contextptr);
    is_integral(v1);
    is_integral(v2);
    if (v1.type!=_INT_ || v2.type!=_INT_ || v1.val<1 || v2.val<1)
      return gensizeerr(contextptr);
    int l=giacmax(v1.val,1),c=giacmax(v2.val,1);
    if (longlong(l)*c>LIST_SIZE_LIMIT)
      return gendimerr(contextptr);
    identificateur idI("I"),idJ("J");
    vecteur IJ=makevecteur(idI,idJ);
    vecteur IJval(2),res;
    for (int i=1;i<=l;++i){
      vecteur ligne(c);
      IJval[0]=i;
      for (int j=1;j<=c;++j){
	IJval[1]=j;
	ligne[j-1]=eval(subst(v0,IJ,IJval,false,contextptr),eval_level(contextptr),contextptr);
      }
      res.push_back(ligne);
    }
    return res;
  }
  static const char _MAKEMAT_s[]="MAKEMAT";
  static define_unary_function_eval_quoted (__MAKEMAT,&_MAKEMAT,_MAKEMAT_s);
  define_unary_function_ptr5( at_MAKEMAT ,alias_at_MAKEMAT,&__MAKEMAT,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

  // For over-determined system, find the solution such that || A*X-B || (L2) is min
  // for under-determined system, find a solution X of A*X=B such that ||X|| is min
  gen _LSQ(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args.type!=_VECT || args._VECTptr->size()<2)
      return gentypeerr(contextptr);
    vecteur v = *args._VECTptr;
    gen v0=v[0]; // evalf(v[0],1,contextptr)
    gen v1=v[1];
    int vs=int(v.size());
    if (vs==3){
      v.push_back(vecteur(0));
      ++vs;
    }
    if (vs==4){
      gen v2=v[2],v3=v[3];
      if (v0.type==_VECT && v1.type==_VECT && !v0._VECTptr->empty() && v0._VECTptr->size()==v1._VECTptr->size() && v2.type==_VECT && v3.type==_VECT){
	// v0=list of values of x or of [x,y,...], v1= observed value at x, 
	// v2=v[vs-2]=list of expressions f_i(x) or f_i(x,y) or [f_i(vars)],[vars]  
	// v3=v.back()=list of constraints = list of 
	// [X_k,n_k (number of derivatives), Y_k=value of n_k-th diff at X_k]
	// or [[X_k,Y_k,...],[n_k],value]
	// minimize sum_j=1..N (y_j-sum_i=1..M(a_i*f_i(x_j),i))^2
	// under sum_i=1..M a_i*diff(f_i,n_k)(X_k) = 0 for k=1..K
	vecteur expr(*v2._VECTptr),constraints(*v3._VECTptr);
	if (!constraints.empty() && constraints.front().type!=_VECT)
	  constraints=vecteur(1,constraints);
	if (!constraints.empty() && (!ckmatrix(constraints) || constraints.front()._VECTptr->size()!=3))
	  return gensizeerr(contextptr);
	vecteur & x=*v0._VECTptr;
	vecteur & y=*v1._VECTptr;
	unsigned M=unsigned(expr.size()), K=unsigned(constraints.size()),N=unsigned(v0._VECTptr->size());
	vecteur vars(1,x__IDNT_e);
	int dim=2;
	if (x.front().type==_VECT){
	  if (!ckmatrix(x))
	    return gensizeerr(contextptr);
	  dim=int(x.front()._VECTptr->size())+1;
	  if (dim<2)
	    return gendimerr(contextptr);
	}
	if (dim==3)
	  vars.push_back(y__IDNT_e);
	if (expr.front().type==_VECT){
	  if (M!=2 || expr.back().type!=_VECT)
	    return gensizeerr(contextptr);
	  vars=*expr.back()._VECTptr;
	  if (int(vars.size())!=dim-1)
	    return gendimerr(contextptr);
	  expr=*expr.front()._VECTptr;
	  M=unsigned(expr.size());
	}
	else {
	  if (dim>3)
	    return gendimerr(contextptr);
	}
	// F_{i,j}=f_i(x_j)
	matrice F; // M rows, N cols
	for (unsigned i=0;i<M;++i){
	  gen fi=expr[i];
	  vecteur ligne;
	  for (unsigned j=0;j<N;++j){
	    ligne.push_back(subst(fi,vars,gen2vecteur(x[j]),false,contextptr));
	  }
	  F.push_back(ligne);
	}
	// dF_{i,k}=diff(f_i,n_k)(X_k)
	matrice dF; // M rows, K cols
	for (unsigned i=0;i<M;++i){
	  gen fi=expr[i];
	  vecteur ligne;
	  for (unsigned k=0;k<K;++k){
	    gen nk=constraints[k][1];
	    gen tmp=derive(fi,vars,gen2vecteur(nk),contextptr);
	    ligne.push_back(subst(tmp,vars,gen2vecteur(constraints[k][0]),false,contextptr));
	  }
	  dF.push_back(ligne);
	}
	matrice mat; // M+K rows, M+K+1 cols
	// first M equations of linear system: for l=1..M
	// sum_i=1..M a_i*sum_j=1..N f_l(x_j)*f_i(x_j) + sum_k=1..K lagrange_k*diff(f_l,n_k)(X_k) = sum_j=1..N f_l(x_j)*y_j
	for (unsigned l=0;l<M;++l){
	  vecteur ligne;
	  for (unsigned i=0;i<M;++i){
	    gen tmp=0;
	    for (unsigned j=0;j<N;++j)
	      tmp += F[l][j]*F[i][j];
	    ligne.push_back(tmp);
	  }
	  for (unsigned k=0;k<K;++k){
	    ligne.push_back(dF[l][k]);
	  }
	  gen tmp=0;
	  for (unsigned j=0;j<N;++j){
	    tmp += F[l][j]*y[j];
	  }
	  ligne.push_back(tmp);
	  mat.push_back(ligne);
	}
	// last K equations
	// sum_i=1..M a_i*diff(f_i,n_k)(X_k)=Y_k
	// giving a (M+K,M+K) matrix -> linsolve, first M coordinates 
	// -> sum_i=1..M a_i f_i(x)
	for (unsigned k=0;k<K;++k){
	  vecteur ligne(M+K+1);
	  ligne[M+K]=constraints[k][2];
	  for (unsigned i=0;i<M;++i){
	    ligne[i]=dF[i][k];
	  }
	  mat.push_back(ligne);
	}
	// now solve linear system
	vecteur res=mker(mat,contextptr);
	if (res.size()!=1 || res.front().type!=_VECT || res.front()._VECTptr->size()!=M+K+1)
	  return gensizeerr("Singular linear system");
	vecteur Res=*res.front()._VECTptr;
	res=vecteur(Res.begin(),Res.begin()+M);
	return gen(res);
      }
      else
	return gensizeerr(contextptr);
    }
    if (!ckmatrix(v0) || v1.type!=_VECT)
      return gentypeerr(contextptr);
    int neq=int(v0._VECTptr->size()); // neq equations
    v0=_trn(v0,contextptr);
    matrice A=*v0._VECTptr,B;
    if (ckmatrix(v1))
      B=gen2vecteur(_trn(v1,contextptr));
    else
      B=vecteur(1,v1);
    if (int(B[0]._VECTptr->size())!=neq)
      return gendimerr(contextptr);
    int as=int(A.size()),bs=int(B.size()); 
    // bs system to solve, each with neq equations and as variables
    if (as>neq){ // under-determined system, find the smallest solution
      if (has_num_coeff(A)){
	// QR factorization of A=trn(system matrix) 
	// R_1=neq first rows of R
	// Q_1=neq first cols of Q
	// solve R_1^* c = B[i] then output Q_1*c
	gen qrdec=qr(A,contextptr);
	if (qrdec.type==_VECT && qrdec._VECTptr->size()==2){
	  gen q=qrdec._VECTptr->front(),r=qrdec._VECTptr->back();
	  if (ckmatrix(q) && ckmatrix(r)){ 
	    if (!is_zero(r[neq-1])){
	      vecteur R(r._VECTptr->begin(),r._VECTptr->begin()+neq);
	      r=mtran(R);
	      R=*r._VECTptr;
	      vecteur qt=mtran(*q._VECTptr);
	      matrice res;
	      qt=vecteur(qt.begin(),qt.begin()+neq);
	      qt=mtran(qt);
	      for (int i=0;i<bs;++i){
		gen Bi=B[i];
		vecteur v,w;
		linsolve_l(R,*Bi._VECTptr,v);
		multmatvecteur(qt,v,w);
		res.push_back(w);
	      }
	      return mtran(res);
	    }
	  }
	}
      }
      // not optimal since we solve the system for each Bi
      A.push_back(0);
      matrice res;
      for (int i=0;i<bs;++i){
	gen Bi=B[i];
	A[as]=Bi;
	matrice At=gen2vecteur(_trn(A,contextptr));
	vecteur B=mker(At,contextptr);
	if (is_undef(B) || B.empty())
	  return undef;
	// The last element of B must have a non-zero last component
	vecteur Bend=*B.back()._VECTptr;
	gen last=-Bend.back();
	if (is_zero(last))
	  return vecteur(0);
	vecteur R=divvecteur(Bend,last);
	R.pop_back();
	B.pop_back();
	int Bs=int(B.size());
	for (int j=0;j<Bs;j++)
	  B[j]._VECTptr->pop_back();
	// The solution is R+Vect(B[0],..,B[Bs-1])
	// the smallest solution is the orthogonal projection of 0 on R+Vect(B)
	// i.e. R + projection of -R on Vect(B)
	matrice r,Bg=gramschmidt(B,r,false,contextptr);
	gen Rtmp(R);
	for (int j=0;j<Bs;++j){
	  Rtmp -= dotvecteur(Bg[j],R)/dotvecteur(Bg[j],Bg[j])*Bg[j];
	}
	res.push_back(Rtmp);
      }
      res=gen2vecteur(_trn(res,contextptr));
      return res;
    }
    matrice res;
    if (has_num_coeff(v)){
      // <Ax-b|Ax-b> minimal, i.e. A* Ax=A* b or 
      // A=QR, if A has m rows and n cols and m>=n, then Q is m*m and R is m*n
      // first n cols of Q are Q1, first n rows of R are R1
      // solve R1*x=Q1^t*b
      gen qrdec=qr(v[0],contextptr);
      if (qrdec.type==_VECT && qrdec._VECTptr->size()==2){
	gen q=qrdec._VECTptr->front(),r=qrdec._VECTptr->back();
	if (ckmatrix(q) && ckmatrix(r)){ 
	  if (!is_zero(r[int(A.size())-1])){
	    gen qt=_trn(q,contextptr);
	    vecteur R(r._VECTptr->begin(),r._VECTptr->begin()+A.size());
	    for (int i=0;i<bs;++i){
	      gen Bi=B[i];
	      vecteur v;
	      linsolve_u(R,multmatvecteur(*qt._VECTptr,*Bi._VECTptr),v);
	      res.push_back(v);
	    }
	    return mtran(res);
	  }
	  // A* Ax=A* b => R* Rx=R* Qb
	  gen rstar=_trn(r,contextptr);
	  gen rr=rstar*r;
	  gen rq=rstar*q*B;
	  return _linsolve(makesequence(rr,rq),contextptr);
	}
      }
    }
    // orthogonal projection of each vector of B on image of A
    if (A.size()>20)
      *logptr(contextptr) << "LSQ: exact data, running Gramschmidt instead of qr, this is much slower for large matrices" << endl;
    matrice r,Ag=gramschmidt(A,r,false,contextptr);
    for (int i=0;i<bs;++i){
      gen Bi=B[i];
      vecteur tmp(as);
      for (int j=0;j<as;++j){
	tmp[j] = scalar_product(Ag[j],Bi,contextptr)/scalar_product(Ag[j],Ag[j],contextptr);
      }
      res.push_back(tmp);
    }
    res=gen2vecteur(_trn(res,contextptr));
    return mmult(*inv(r,contextptr)._VECTptr,res);
  }
  static const char _LSQ_s[]="LSQ";
  static define_unary_function_eval (__LSQ,&_LSQ,_LSQ_s);
  define_unary_function_ptr5( at_LSQ ,alias_at_LSQ,&__LSQ,0,T_UNARY_OP_38);
  
  static const char _lsq_s []="lsq";
  static define_unary_function_eval (__lsq,&_LSQ,_lsq_s);
  define_unary_function_ptr5( at_lsq ,alias_at_lsq,&__lsq,0,true);

  static string printasNTHROOT(const gen & feuille,const char * sommetstr,GIAC_CONTEXT){
    if (feuille.type==_VECT && feuille._VECTptr->size()==2 && abs_calc_mode(contextptr)!=38)
      return "surd("+feuille[1].print(contextptr)+","+feuille[0].print(contextptr)+")";
    // return '('+(printsommetasoperator(feuille," NTHROOT ",contextptr))+')';
    return printsommetasoperator(feuille," NTHROOT ",contextptr);
  }
  static string texprintasNTHROOT(const gen & g,const char * s,GIAC_CONTEXT){
    return texprintsommetasoperator(g,"\\mbox{ NTHROOT }",contextptr);
  }
  gen _NTHROOT(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG && args.subtype==-1) return  args;
    if (args.type!=_VECT || args._VECTptr->size()!=2)
      return gensizeerr(contextptr);
    return _surd(gen(makevecteur(args._VECTptr->back(),args._VECTptr->front()),_SEQ__VECT),contextptr);
  }
  static const char _NTHROOT_s[]="NTHROOT";
  static define_unary_function_eval4 (__NTHROOT,&_NTHROOT,_NTHROOT_s,&printasNTHROOT,&texprintasNTHROOT);
  define_unary_function_ptr5( at_NTHROOT ,alias_at_NTHROOT,&__NTHROOT,0,T_POW);

#ifndef GIAC_HAS_STO_38
  gen * rpn_ans(){
    return 0;
  }
#endif
  gen _Ans(const gen & args,GIAC_CONTEXT){
    if (rpn_ans())
      return *rpn_ans();
    return _ans(0,contextptr);
  }
  static const char _Ans_s[]="Ans";
  static string printasAns(const gen & feuille,const char * sommetstr,GIAC_CONTEXT){
    return _Ans_s;
  }
  static define_unary_function_eval2 (__Ans,&_Ans,_Ans_s,&printasAns);
  define_unary_function_ptr5( at_Ans ,alias_at_Ans,&__Ans,0,T_LITERAL);
  
  gen _EXPORT_(const gen & args,GIAC_CONTEXT){
    // eval sto only
    vecteur v =gen2vecteur(args);
    int nsto=0,s=int(v.size());
    for (int i=0;i<s;++i){
      if (v[i].is_symb_of_sommet(at_sto)){
	++nsto;
	eval(v[i],1,contextptr);
      }
    }
    return nsto;
  }
  static const char _EXPORT__s[]="EXPORT";
  static define_unary_function_eval (__EXPORT_,&_EXPORT_,_EXPORT__s);
  define_unary_function_ptr5( at_EXPORT ,alias_at_EXPORT_,&__EXPORT_,_QUOTE_ARGUMENTS,T_RETURN);
  
  gen _VIEWS(const gen & args,GIAC_CONTEXT){
    return _EXPORT_(args,contextptr);
  }
  static const char _VIEWS_s[]="VIEWS";
  static define_unary_function_eval (__VIEWS,&_VIEWS,_VIEWS_s);
  define_unary_function_ptr5( at_VIEWS ,alias_at_VIEWS,&__VIEWS,_QUOTE_ARGUMENTS,T_RETURN);
  
#ifdef USE_GMP_REPLACEMENTS
  unsigned long long mpz_get_ull(mpz_t n){
    return 0; // FIXME!!!!
  }
#else
  unsigned long long mpz_get_ull(mpz_t n){
    unsigned int lo, hi;
    mpz_t tmp;
    
    mpz_init( tmp );
    mpz_mod_2exp( tmp, n, 64 );   /* tmp = (lower 64 bits of n) */
    
    lo = mpz_get_ui( tmp );       /* lo = tmp & 0xffffffff */ 
    mpz_div_2exp( tmp, tmp, 32 ); /* tmp >>= 32 */
    hi = mpz_get_ui( tmp );       /* hi = tmp & 0xffffffff */

    mpz_clear( tmp );

    return (((unsigned long long)hi) << 32) + lo;
  }
#endif

  gen _pointer(const gen & args,GIAC_CONTEXT){
    if (args.type!=_VECT || args._VECTptr->size()!=2)
      return gensizeerr(contextptr);
    if (args._VECTptr->back().type!=_INT_)
      return gentypeerr(contextptr);
    if (args._VECTptr->front().type==_INT_)
      return gen((void *)(unsigned long)args._VECTptr->front().val, args._VECTptr->back().val);
    if (args._VECTptr->front().type==_ZINT){
      unsigned long u=mpz_get_ull(*args._ZINTptr);
      return gen((void *)u,args._VECTptr->back().val);
    }
    return gentypeerr(contextptr);
  }
  static const char _pointer_s[]="pointer";
  static define_unary_function_eval (__pointer,&_pointer,_pointer_s);
  define_unary_function_ptr5( at_pointer ,alias_at_pointer,&__pointer,0,T_UNARY_OP);
  
  int is_known_name_home_38(const char * idname){
    int s=int(strlen(idname));
    if (s==1 && idname[0]>='A' && idname[0]<='Z')
      return 3;
    if (s==2 && !strcmp(idname,"θ"))
      return 3;
    if (s==2 && (idname[0]=='Z' || idname[0]=='L' || idname[0]=='M') && idname[1]>='0' && idname[1]<='9')
      return 3;
    return is_known_name_38?is_known_name_38(0,idname):0;
  }

  // 1 and 2 app or program variable, 3 home variable
  int is_known_name_home_38(const char * name_space,const char * idname){
    if (name_space)
      return is_known_name_38?is_known_name_38(name_space,idname):0;
    return is_known_name_home_38(idname);
  }

  static gen qualifysubst(const gen & g,const vecteur & vin,const vecteur & vout,GIAC_CONTEXT){
    if (vin.empty()) return g;
    if (g.type!=_VECT){
      if (g.is_symb_of_sommet(at_sto)){
	gen & f = g._SYMBptr->feuille;
	if (f.type==_VECT && f._VECTptr->size()==2){
	  return symbolic(at_sto,gen(makevecteur(subst(f._VECTptr->front(),vin,vout,true,contextptr),f._VECTptr->back()),_SEQ__VECT));
	}
      }
      return subst(g,vin,vout,true,contextptr);
    }
    const_iterateur it=g._VECTptr->begin(),itend=g._VECTptr->end();
    vecteur res;
    res.reserve(itend-it);
    for (;it!=itend;++it)
      res.push_back(qualifysubst(*it,vin,vout,contextptr));
    return gen(res,g.subtype);
  }

  void qualify(gen & g,const vecteur & v,const gen & prog,GIAC_CONTEXT){
    if (v.empty()) return;
    vecteur w(v);
    unsigned s=unsigned(v.size());
    for (unsigned i=0;i<s;++i){
      w[i]=symbolic(at_double_deux_points,gen(makevecteur(prog,w[i]),_SEQ__VECT));
    }   
    g=subst(g,v,w,true,contextptr);
    //g=qualifysubst(g,v,w,contextptr);
  }

#if 0
  // 0: ok, -1: invalid views, -2: invalid VIEWS/EXPORT declaration in a program
  static int parse_program_decl(vecteur & assignation_by_equal,vecteur & undeclared_global_vars,vecteur & declared_global_vars,vecteur & declared_functions,vecteur & exported_function_names,vecteur & exported_variable_names,vecteur & unknown_exported,vecteur & unexported,vecteur & unexported_declared_global_vars,vecteur & views,vecteur & errors,const gen & prog,gen & parsed,GIAC_CONTEXT){
    check_local_assign(parsed,vecteur(0),assignation_by_equal,undeclared_global_vars,declared_global_vars,declared_functions,true,contextptr);
    vecteur vprog=lop(parsed,at_program);
    if (!lop(vprog,at_VIEWS).empty() || !lop(vprog,at_EXPORT).empty())
      return -2;
    // views
    vecteur vviews=lop(parsed,at_VIEWS);
    iterateur vt=vviews.begin(),vtend=vviews.end();
    for (;vt!=vtend;++vt){
      gen & f = vt->_SYMBptr->feuille;
      if (f.type==_VECT){
	vecteur v=*f._VECTptr;
	if (v.size()==2){
	  if (v.front().type==_STRNG)
	    reverse(v.begin(),v.end());
	  if (v.front().is_symb_of_sommet(at_sto))
	    v.front()=v.front()._SYMBptr->feuille[1];
	  views=mergevecteur(views,v);
	}
	else return -1;
      }
    }
    // exported/unexported: declaration like export f,"help for f";
    vecteur exported=lop(parsed,at_EXPORT),exported_names;
    if (exported.empty()){
      unexported=declared_functions;
    }
    else {
      iterateur it=exported.begin(),itend=exported.end();
      for (;it!=itend;++it){
	gen & f = it->_SYMBptr->feuille;
	if (f.type==_VECT){
	  vecteur v=*f._VECTptr;
	  if (!v.empty()){
	    if (v.front().type==_STRNG)
	      reverse(v.begin(),v.end());
	    if (v.front().is_symb_of_sommet(at_sto))
	      v.front()=v.front()._SYMBptr->feuille[1];
	    exported_names=mergevecteur(exported_names,v);
	  }
	}
	else {
	  exported_names.push_back(f.is_symb_of_sommet(at_sto)?f._SYMBptr->feuille[1]:f);
	}
      }
      // check if exported functions are defined or exported variables declared
      // check also that we do not redefine regular home variables
      itend=exported_names.end();
      // first replace function definition by function name
      for (it=exported_names.begin();it!=itend;++it){
	if (it->is_symb_of_sommet(at_sto)){
	  *it=it->_SYMBptr->feuille;
	  if (it->type==_VECT && it->_VECTptr->size()==2)
	    *it=it->_VECTptr->back();
	}
      }
      for (it=exported_names.begin();it!=itend;++it){
	if (it->type!=_STRNG){
	  if (equalposcomp(declared_functions,*it) && !equalposcomp(declared_global_vars,*it) && !equalposcomp(undeclared_global_vars,*it))
	    unknown_exported.push_back(*it);
	  if (it->type==_IDNT && is_known_name_home_38(it->_IDNTptr->id_name))
	    errors.push_back(*it);
	}
      }
      it=declared_functions.begin(),itend=declared_functions.end();
      for (;it!=itend;++it){
	if (!equalposcomp(exported_names,*it))
	  unexported.push_back(*it);
      }
    }
    // remove exported functions/views and variables from undeclared global vars
    // check other: either home variables or put in errors
    vecteur tmp;
    tmp=undeclared_global_vars;
    undeclared_global_vars.clear();
    const_iterateur jt=tmp.begin(),jtend=tmp.end();
    for (;jt!=jtend;++jt){
      if (jt->type!=_IDNT)
	continue;
      if (!equalposcomp(declared_functions,*jt) && !equalposcomp(exported_names,*jt)){
	if (is_known_name_home_38(0,jt->_IDNTptr->id_name))
	  undeclared_global_vars.push_back(*jt);
	else
	  errors.push_back(*jt);
      }
    }
    // keep only home and app variables in declared global vars
    tmp=declared_global_vars;
    declared_global_vars.clear();
    jt=tmp.begin(); jtend=tmp.end();
    for (;jt!=jtend;++jt){
      if (jt->type==_IDNT && !equalposcomp(exported_names,*jt)){
	if (is_known_name_home_38(0,jt->_IDNTptr->id_name))
	  declared_global_vars.push_back(*jt);
	else
	  unexported_declared_global_vars.push_back(*jt);
      }
    }
    // split exported_names into function/variables
    exported_function_names.clear();
    exported_variable_names.clear();
    if (!exported_names.empty()){
      vecteur sto_var=lop(parsed,at_sto);
      int s=int(exported_names.size());
      int is_var=-1;
      for (int i=0;i<s;++i){
	gen & var=exported_names[i];
	if (var.type==_IDNT){
	  const_iterateur it=sto_var.begin(),itend=sto_var.end();
	  for (;it!=itend;++it){
	    if (it->type!=_SYMB) continue;
	    gen & f =it->_SYMBptr->feuille;
	    if (f.type==_VECT && f._VECTptr->size()==2 && f._VECTptr->back()==var){
	      if (f._VECTptr->front().is_symb_of_sommet(at_program))
		is_var=0;
	      else
		is_var=1;
	      break;
	    }
	  }
	  if (it==itend)
	    is_var=1;
	}
	if (is_var>=0){
	  if (is_var)
	    exported_variable_names.push_back(var);
	  else
	    exported_function_names.push_back(var);
	}
      }
    }
    // qualify unexported functions and declared unexported variables
    qualify(parsed,unexported,prog,contextptr);
    qualify(parsed,unexported_declared_global_vars,prog,contextptr);
    qualify(parsed,exported_variable_names,prog,contextptr);
#if !defined RTOS_THREADX && !defined NSPIRE
    ofstream of("c:\\log"); of << "=" << assignation_by_equal << endl << "undecl vars:" << undeclared_global_vars << endl << "decl vars:" << declared_global_vars << endl << "decl func.:" << declared_functions << endl << "exported func:" << exported_function_names << endl << "exported vars:"<<exported_variable_names << endl << "unknown exported:"<<unknown_exported << endl << "unexported:" << unexported << endl << "unexported declared global vars:"<<unexported_declared_global_vars << endl << "views:" << views << endl << "errors:" << errors << endl << "prog:"<<prog << endl << "parsed:" << parsed; of.close();   
#endif
    return int(errors.size());
  }

  // 0: ok, -1: invalid view, >0: #errors
  int parse_program(const wchar_t * source,const wchar_t * progname,vecteur & assignation_by_equal,vecteur & undeclared_global_vars,vecteur & declared_global_vars,vecteur & exported_function_names,vecteur & exported_variable_names,vecteur & unknown_exported,vecteur & unexported,vecteur & unexported_declared_global_vars,vecteur & views,vecteur & errors,gen & parsed,GIAC_CONTEXT){
    unsigned utfs = giacmax(utf8length(source),utf8length(progname)); 
    char * utf8source = new char[utfs+1];
    unicode2utf8(source,utf8source,wstrlen(source));
    string s(utf8source);
    unicode2utf8(progname,utf8source,wstrlen(progname));
    string utf8progname(utf8source);
    gen prog=identificateur(utf8progname);
    delete [] utf8source;
    int c=calc_mode(contextptr);
    calc_mode(contextptr)=-38;
    parsed=gen(s,contextptr);
    calc_mode(contextptr)=c;
    vecteur declared_functions;
    int err=parse_program_decl(assignation_by_equal,undeclared_global_vars,declared_global_vars,declared_functions,exported_function_names,exported_variable_names,unknown_exported,unexported,unexported_declared_global_vars,views,errors,prog,parsed,contextptr);
    return err;
  }

  gen _testfunc(const gen & g0,GIAC_CONTEXT){
    if (g0.type==_STRNG){
      int c=calc_mode(contextptr);
      calc_mode(contextptr)=-38;
      gen parsed(*g0._STRNGptr,contextptr);
      calc_mode(contextptr)=c;
      gen prog("abc",contextptr);
      vecteur assignation_by_equal,undeclared_global_vars,declared_global_vars,declared_functions,exported_function_names,exported_variable_names,unknown_exported,unexported,unexported_declared_global_vars,views,errors;
      parse_program_decl(assignation_by_equal,undeclared_global_vars,declared_global_vars,declared_functions,exported_function_names,exported_variable_names,unknown_exported,unexported,unexported_declared_global_vars,views,errors,prog,parsed,contextptr);
      // eval 
      gen res=eval(parsed,1,contextptr);
      vecteur resv=makevecteur(assignation_by_equal,undeclared_global_vars,declared_global_vars,exported_function_names,exported_variable_names,unknown_exported,unexported,unexported_declared_global_vars,errors);
      resv.push_back(res);
      return resv;
    }
    return undef;
  }
  static const char _testfunc_s[]="testfunc";
  static define_unary_function_eval(__testfunc,&_testfunc,_testfunc_s);
  define_unary_function_ptr5( at_testfunc ,alias_at_testfunc,&__testfunc,0,true);
#else

  gen _testfunc(const gen & g0,GIAC_CONTEXT){
    return g0;
  }
  static const char _testfunc_s[]="testfunc";
  static define_unary_function_eval(__testfunc,&_testfunc,_testfunc_s);
  define_unary_function_ptr5( at_testfunc ,alias_at_testfunc,&__testfunc,0,true);
#endif // old code not used anymore

#ifdef DOUBLEVAL
  const identificateur nsymbolic__IDNT("nsymbolic");
  const gen nsymbolic(nsymbolic__IDNT);

  const identificateur u0_nm1__IDNT("u0_nm1");
  const gen u0_nm1(u0_nm1__IDNT);
  const identificateur v0_nm2__IDNT("v0_nm2");
  const gen v0_nm2(v0_nm2__IDNT);
  const identificateur U0__IDNT("U0");
  const gen U0_idnt(U0__IDNT);

  const identificateur u1_nm1__IDNT("u1_nm1");
  const gen u1_nm1(u1_nm1__IDNT);
  const identificateur v1_nm2__IDNT("v1_nm2");
  const gen v1_nm2(v1_nm2__IDNT);
  const identificateur U1__IDNT("U1");
  const gen U1_idnt(U1__IDNT);

  const identificateur u2_nm1__IDNT("u2_nm1");
  const gen u2_nm1(u2_nm1__IDNT);
  const identificateur v2_nm2__IDNT("v2_nm2");
  const gen v2_nm2(v2_nm2__IDNT);
  const identificateur U2__IDNT("U2");
  const gen U2_idnt(U2__IDNT);

  const identificateur u3_nm1__IDNT("u3_nm1");
  const gen u3_nm1(u3_nm1__IDNT);
  const identificateur v3_nm2__IDNT("v3_nm2");
  const gen v3_nm2(v3_nm2__IDNT);
  const identificateur U3__IDNT("U3");
  const gen U3_idnt(U3__IDNT);

  const identificateur u4_nm1__IDNT("u4_nm1");
  const gen u4_nm1(u4_nm1__IDNT);
  const identificateur v4_nm2__IDNT("v4_nm2");
  const gen v4_nm2(v4_nm2__IDNT);
  const identificateur U4__IDNT("U4");
  const gen U4_idnt(U4__IDNT);

  const identificateur u5_nm1__IDNT("u5_nm1");
  const gen u5_nm1(u5_nm1__IDNT);
  const identificateur v5_nm2__IDNT("v5_nm2");
  const gen v5_nm2(v5_nm2__IDNT);
  const identificateur U5__IDNT("U5");
  const gen U5_idnt(U5__IDNT);

  const identificateur u6_nm1__IDNT("u6_nm1");
  const gen u6_nm1(u6_nm1__IDNT);
  const identificateur v6_nm2__IDNT("v6_nm2");
  const gen v6_nm2(v6_nm2__IDNT);
  const identificateur U6__IDNT("U6");
  const gen U6_idnt(U6__IDNT);

  const identificateur u7_nm1__IDNT("u7_nm1");
  const gen u7_nm1(u7_nm1__IDNT);
  const identificateur v7_nm2__IDNT("v7_nm2");
  const gen v7_nm2(v7_nm2__IDNT);
  const identificateur U7__IDNT("U7");
  const gen U7_idnt(U7__IDNT);

  const identificateur u8_nm1__IDNT("u8_nm1");
  const gen u8_nm1(u8_nm1__IDNT);
  const identificateur v8_nm2__IDNT("v8_nm2");
  const gen v8_nm2(v8_nm2__IDNT);
  const identificateur U8__IDNT("U8");
  const gen U8_idnt(U8__IDNT);

  const identificateur u9_nm1__IDNT("u9_nm1");
  const gen u9_nm1(u9_nm1__IDNT);
  const identificateur v9_nm2__IDNT("v9_nm2");
  const gen v9_nm2(v9_nm2__IDNT);
  const identificateur U9__IDNT("U9");
  const gen U9_idnt(U9__IDNT);

#else // GIAC_HAS_STO_38
  const alias_ref_identificateur ref_nsymbolic={-1,0,0,"nsymbolic",0,0};
  const define_alias_gen(alias_nsymbolic,_IDNT,0,&ref_nsymbolic);
  const gen & nsymbolic = * (gen *) & alias_nsymbolic;

  const alias_ref_identificateur ref_u0_nm1={-1,0,0,"u0_nm1",0,0};
  const define_alias_gen(alias_u0_nm1,_IDNT,0,&ref_u0_nm1);
  const gen & u0_nm1 = * (gen *) & alias_u0_nm1;
  const alias_ref_identificateur ref_v0_nm2={-1,0,0,"v0_nm2",0,0};
  const define_alias_gen(alias_v0_nm2,_IDNT,0,&ref_v0_nm2);
  const gen & v0_nm2 = * (gen *) & alias_v0_nm2;
  const alias_ref_identificateur ref_U0_idnt={-1,0,0,"U0",0,0};
  const define_alias_gen(alias_U0_idnt,_IDNT,0,&ref_U0_idnt);
  const gen & U0_idnt = * (gen *) & alias_U0_idnt;

  const alias_ref_identificateur ref_u1_nm1={-1,0,0,"u1_nm1",0,0};
  const define_alias_gen(alias_u1_nm1,_IDNT,0,&ref_u1_nm1);
  const gen & u1_nm1 = * (gen *) & alias_u1_nm1;
  const alias_ref_identificateur ref_v1_nm2={-1,0,0,"v1_nm2",0,0};
  const define_alias_gen(alias_v1_nm2,_IDNT,0,&ref_v1_nm2);
  const gen & v1_nm2 = * (gen *) & alias_v1_nm2;
  const alias_ref_identificateur ref_U1_idnt={-1,0,0,"U1",0,0};
  const define_alias_gen(alias_U1_idnt,_IDNT,0,&ref_U1_idnt);
  const gen & U1_idnt = * (gen *) & alias_U1_idnt;

  const alias_ref_identificateur ref_u2_nm1={-1,0,0,"u2_nm1",0,0};
  const define_alias_gen(alias_u2_nm1,_IDNT,0,&ref_u2_nm1);
  const gen & u2_nm1 = * (gen *) & alias_u2_nm1;
  const alias_ref_identificateur ref_v2_nm2={-1,0,0,"v2_nm2",0,0};
  const define_alias_gen(alias_v2_nm2,_IDNT,0,&ref_v2_nm2);
  const gen & v2_nm2 = * (gen *) & alias_v2_nm2;
  const alias_ref_identificateur ref_U2_idnt={-1,0,0,"U2",0,0};
  const define_alias_gen(alias_U2_idnt,_IDNT,0,&ref_U2_idnt);
  const gen & U2_idnt = * (gen *) & alias_U2_idnt;

  const alias_ref_identificateur ref_u3_nm1={-1,0,0,"u3_nm1",0,0};
  const define_alias_gen(alias_u3_nm1,_IDNT,0,&ref_u3_nm1);
  const gen & u3_nm1 = * (gen *) & alias_u3_nm1;
  const alias_ref_identificateur ref_v3_nm2={-1,0,0,"v3_nm2",0,0};
  const define_alias_gen(alias_v3_nm2,_IDNT,0,&ref_v3_nm2);
  const gen & v3_nm2 = * (gen *) & alias_v3_nm2;
  const alias_ref_identificateur ref_U3_idnt={-1,0,0,"U3",0,0};
  const define_alias_gen(alias_U3_idnt,_IDNT,0,&ref_U3_idnt);
  const gen & U3_idnt = * (gen *) & alias_U3_idnt;

  const alias_ref_identificateur ref_u4_nm1={-1,0,0,"u4_nm1",0,0};
  const define_alias_gen(alias_u4_nm1,_IDNT,0,&ref_u4_nm1);
  const gen & u4_nm1 = * (gen *) & alias_u4_nm1;
  const alias_ref_identificateur ref_v4_nm2={-1,0,0,"v4_nm2",0,0};
  const define_alias_gen(alias_v4_nm2,_IDNT,0,&ref_v4_nm2);
  const gen & v4_nm2 = * (gen *) & alias_v4_nm2;
  const alias_ref_identificateur ref_U4_idnt={-1,0,0,"U4",0,0};
  const define_alias_gen(alias_U4_idnt,_IDNT,0,&ref_U4_idnt);
  const gen & U4_idnt = * (gen *) & alias_U4_idnt;

  const alias_ref_identificateur ref_u5_nm1={-1,0,0,"u5_nm1",0,0};
  const define_alias_gen(alias_u5_nm1,_IDNT,0,&ref_u5_nm1);
  const gen & u5_nm1 = * (gen *) & alias_u5_nm1;
  const alias_ref_identificateur ref_v5_nm2={-1,0,0,"v5_nm2",0,0};
  const define_alias_gen(alias_v5_nm2,_IDNT,0,&ref_v5_nm2);
  const gen & v5_nm2 = * (gen *) & alias_v5_nm2;
  const alias_ref_identificateur ref_U5_idnt={-1,0,0,"U5",0,0};
  const define_alias_gen(alias_U5_idnt,_IDNT,0,&ref_U5_idnt);
  const gen & U5_idnt = * (gen *) & alias_U5_idnt;

  const alias_ref_identificateur ref_u6_nm1={-1,0,0,"u6_nm1",0,0};
  const define_alias_gen(alias_u6_nm1,_IDNT,0,&ref_u6_nm1);
  const gen & u6_nm1 = * (gen *) & alias_u6_nm1;
  const alias_ref_identificateur ref_v6_nm2={-1,0,0,"v6_nm2",0,0};
  const define_alias_gen(alias_v6_nm2,_IDNT,0,&ref_v6_nm2);
  const gen & v6_nm2 = * (gen *) & alias_v6_nm2;
  const alias_ref_identificateur ref_U6_idnt={-1,0,0,"U6",0,0};
  const define_alias_gen(alias_U6_idnt,_IDNT,0,&ref_U6_idnt);
  const gen & U6_idnt = * (gen *) & alias_U6_idnt;

  const alias_ref_identificateur ref_u7_nm1={-1,0,0,"u7_nm1",0,0};
  const define_alias_gen(alias_u7_nm1,_IDNT,0,&ref_u7_nm1);
  const gen & u7_nm1 = * (gen *) & alias_u7_nm1;
  const alias_ref_identificateur ref_v7_nm2={-1,0,0,"v7_nm2",0,0};
  const define_alias_gen(alias_v7_nm2,_IDNT,0,&ref_v7_nm2);
  const gen & v7_nm2 = * (gen *) & alias_v7_nm2;
  const alias_ref_identificateur ref_U7_idnt={-1,0,0,"U7",0,0};
  const define_alias_gen(alias_U7_idnt,_IDNT,0,&ref_U7_idnt);
  const gen & U7_idnt = * (gen *) & alias_U7_idnt;

  const alias_ref_identificateur ref_u8_nm1={-1,0,0,"u8_nm1",0,0};
  const define_alias_gen(alias_u8_nm1,_IDNT,0,&ref_u8_nm1);
  const gen & u8_nm1 = * (gen *) & alias_u8_nm1;
  const alias_ref_identificateur ref_v8_nm2={-1,0,0,"v8_nm2",0,0};
  const define_alias_gen(alias_v8_nm2,_IDNT,0,&ref_v8_nm2);
  const gen & v8_nm2 = * (gen *) & alias_v8_nm2;
  const alias_ref_identificateur ref_U8_idnt={-1,0,0,"U8",0,0};
  const define_alias_gen(alias_U8_idnt,_IDNT,0,&ref_U8_idnt);
  const gen & U8_idnt = * (gen *) & alias_U8_idnt;

  const alias_ref_identificateur ref_u9_nm1={-1,0,0,"u9_nm1",0,0};
  const define_alias_gen(alias_u9_nm1,_IDNT,0,&ref_u9_nm1);
  const gen & u9_nm1 = * (gen *) & alias_u9_nm1;
  const alias_ref_identificateur ref_v9_nm2={-1,0,0,"v9_nm2",0,0};
  const define_alias_gen(alias_v9_nm2,_IDNT,0,&ref_v9_nm2);
  const gen & v9_nm2 = * (gen *) & alias_v9_nm2;
  const alias_ref_identificateur ref_U9_idnt={-1,0,0,"U9",0,0};
  const define_alias_gen(alias_U9_idnt,_IDNT,0,&ref_U9_idnt);
  const gen & U9_idnt = * (gen *) & alias_U9_idnt;

#endif

  int has_Un(const gen & g){
    vecteur l(lvar(g));
    for (unsigned i=0;i<l.size();++i){
      if (l[i].type==_IDNT){
	const char * s=l[i]._IDNTptr->id_name;
	if (strlen(s)==2 && s[0]=='U' && s[1]>='0' && s[1]<='9')
	  return s[1]-'0';
      }
    }
    return -1;
  }
  
  static void seqapp_lop_of(const gen & g,vecteur & res){
    vecteur vof(lop(g,at_of));
    const_iterateur it=vof.begin(),itend=vof.end();
    for (;it!=itend;++it){
      gen & f=it->_SYMBptr->feuille;
      if (f.type!=_VECT || f._VECTptr->size()!=2 || f._VECTptr->front().type!=_IDNT)
	continue;
      if (f._VECTptr->back().type==_SYMB)
	seqapp_lop_of(f._VECTptr->back(),res); 
      res.push_back(*it);
    }
  }

  int is_n_minus_one_or_two(const gen & arg){
    if (arg.type!=_SYMB)
      return 0;
    if (arg._SYMBptr->feuille.type==_VECT && arg._SYMBptr->feuille._VECTptr->size()==2){
      gen a1=arg._SYMBptr->feuille._VECTptr->front();
      gen a2=arg._SYMBptr->feuille._VECTptr->back();
      if (a1.type==_IDNT && !strcmp(a1._IDNTptr->id_name,"N")){
	if (arg._SYMBptr->sommet==at_plus){
	  if (a2==-1) return 1;
	  if (a2==-2) return 2;
	}
	if (arg._SYMBptr->sommet==at_binary_minus){
	  if (a2==1) return 1;
	  if (a2==2) return 2;
	}	  
      }
    }
    return 0;
  }
  
  // Prepares app sequence for computing a recurrence relation
  // Valid if 1 sequence is checked and does not depend on other sequences
  // Given expr_un, the expression of UK(N) in terms of UK(N-1) and UK(N-2)
  // write the recurrence relation as UK(N)=subst(expr,vars,[N,UK(N-1),UK(N-2)])
  // Return 0 or -10-val if expr_un is invalid or depends on Uval, 
  // 1 if it does not depend on UK(N-2)
  // 3 if not recurrent
  // 2 otherwise
  int seqapp_prepare(const gen & expr_un,gen & expr,vecteur & vars,GIAC_CONTEXT,int seqno){
    if (has_Un(expr_un)!=-1)
      return 0;
    vecteur vof; seqapp_lop_of(expr_un,vof); // (lop(expr_un,at_of));
    // check functions with names in U0-U9
    int s=int(vof.size()),retval=1;
    gen uk(vx_var);
    bool notrecurrent=true;
    for (int i=0;i<s;++i){
      gen & f=vof[i]._SYMBptr->feuille;
      if (f.type!=_VECT || f._VECTptr->size()!=2 || f._VECTptr->front().type!=_IDNT)
	continue;
      gen & id=f._VECTptr->front();
      const char * idname=id._IDNTptr->id_name;
      if (strlen(idname)!=2 || idname[0]!='U' || idname[1]<'0' || idname[1]>'9')
	continue;
      notrecurrent=false;
      uk=id;
      if (seqno==-1){
	seqno=idname[1]-'0';
      }
      else {
	if (seqno!=idname[1]-'0')
	  return -10-(idname[1]-'0');
      }
      gen & arg=f._VECTptr->back();
#if 1
      int test=is_n_minus_one_or_two(arg);
      if (!test)
	return 0;
      if (test==2)
	retval=2;
#else
      if (arg!=n__IDNT_e-1 && arg!=n__IDNT_e-2)
	return 0;
      if (arg==n__IDNT_e-2)
	retval=2;
#endif
    }
    identificateur uk_nm1_("uk_nm1"),uk_nm2_("uk_nm2");
    gen uk_nm1(uk_nm1_),uk_nm2(uk_nm2_);
    vecteur vars0(makevecteur(n__IDNT_e,symb_of(uk,n__IDNT_e-1),symb_of(uk,n__IDNT_e-2)));
    vars=makevecteur(nsymbolic,uk_nm1,uk_nm2);
    expr=subst(expr_un,vars0,vars,true,contextptr);
    /* additional checking disabled
    vecteur lv(makevecteur(uk_nm1,uk_nm2));
    lidnt(expr,lv);
    s=lv.size();
    for (int i=2;i<s;++i){
      gen & g =lv[i];
      if (g.type!=_IDNT)
	return 0;
      if (strlen(g._IDNTptr->id_name)>1)
	return 0;
      if (g._IDNTptr->id_name[0]<'A' || g._IDNTptr->id_name[0]>'Z')
	return 0;
    }
    */
    return notrecurrent?3:retval;
  }

  // Compute UK(N) for K=k to m, where UK(k) and UK(k+1) are given
  // If the recurrence relation does not depend on UK(N-2), set UK(k+1) to undef
  vecteur seqapp_compute(const gen & expr0,const vecteur & vars,const gen & UK_k,const gen &UK_kp1,int k,int m,GIAC_CONTEXT){
    gen f1f9(lidnt_function38(expr0));
    gen f1f9value=eval(f1f9,1,contextptr);
    gen expr(expr0);
    if (f1f9.type==_VECT && !f1f9._VECTptr->empty())
      expr=subst(expr0,f1f9,f1f9value,true,contextptr);
    gen UK_nm2(UK_k),UK_nm1(UK_kp1),tmp;
    if (is_undef(UK_k))// also compute UK_n
      UK_nm2=subst(expr,vars,makevecteur(k,UK_k,undef),false,contextptr);
    if (is_undef(UK_kp1))// compute UK_np1
      UK_nm1=subst(expr,vars,makevecteur(k+1,UK_k,undef),false,contextptr);
    UK_nm1=evalf(UK_nm1,1,contextptr);
    if (UK_nm1.type>_REAL && UK_nm1.type!=_FLOAT_)
      UK_nm1=undef;
    UK_nm2=evalf(UK_nm2,1,contextptr);
    if (UK_nm2.type>_REAL && UK_nm2.type!=_FLOAT_)
      UK_nm2=undef;    
    vecteur res(makevecteur(UK_nm2,UK_nm1));
    for (int n=k+2;n<=m;++n){
      tmp=subst(expr,vars,makevecteur(n,UK_nm1,UK_nm2),false,contextptr);
      tmp=evalf(tmp,1,contextptr);
      if (tmp.type>_REAL && tmp.type!=_FLOAT_)
	res.push_back(undef);
      else
	res.push_back(tmp);
      UK_nm2=UK_nm1;
      UK_nm1=tmp;
    }
    return res;
  }



  // Prepares app sequence for computing all recurrences relations
  // expr_un should contain the expression for U0(N) to UK(N) for K<=9
  // undef may be used if the sequence is not checked
  // Rewrite the recurrence relation as [U0(N),...,UK(N)]=subst(expr,vars,[N,U0(N-1),U0(N-2),...])
  // Return 0 if expr_un is invalid, -10-val if Uval should be checked
  // Return 1 if it does not depend on UK(N-2), 3 if not recurrent, 2 otherwise
  int seqapp_prepare(const vecteur & expr_un,vecteur & expr,vecteur & vars,GIAC_CONTEXT){
    int dim=int(expr_un.size());
    if (has_Un(expr_un)!=-1)
      return 0;
    vecteur vof; seqapp_lop_of(expr_un,vof); // (lop(expr_un,at_of));
    vector<int> defined_seqs;
    for (unsigned i=0;i<expr_un.size();++i){
      if (!is_undef(expr_un[i]))
	defined_seqs.push_back(i); // allowed sequences numbers (starts with U0, not U1)
    }
    // check functions with names in U0-U9
    int s=int(vof.size()),retval=3;
    gen uk;
    for (int i=0;i<s;++i){
      gen & f=vof[i]._SYMBptr->feuille;
      if (f.type!=_VECT || f._VECTptr->size()!=2 || f._VECTptr->front().type!=_IDNT)
	continue;
      gen & id=f._VECTptr->front();
      const char * idname=id._IDNTptr->id_name;
      if (strlen(idname)!=2 || idname[0]!='U' || idname[1]<'0' || idname[1]>'9')
	continue;
      int val=idname[1]-'0';
      if (!equalposcomp(defined_seqs,val))
	return -val-10;
      gen & arg=f._VECTptr->back();
#if 1
      int test=is_n_minus_one_or_two(arg);
      if (!test)
	return 0;
      if (test==2)
	retval=2;
      else {
	if (retval!=2)
	  retval=1;
      }
#else
      if (arg!=n__IDNT_e-1 && arg!=n__IDNT_e-2)
	return 0;
      if (arg==n__IDNT_e-2)
	retval=2;
      else {
	if (retval!=2)
	  retval=1;
      }
#endif
    }
    vecteur vars0(1,n__IDNT_e); vars=vecteur(1,nsymbolic);
    vecteur tab_uk(30);
    tab_uk[0]=u0_nm1; // (identificateur("u0_nm1"));
    tab_uk[1]=v0_nm2; // (identificateur("v0_nm2"));
    tab_uk[2]=U0_idnt; // (identificateur("U0"));
    tab_uk[3]=u1_nm1; // (identificateur("u1_nm1"));
    tab_uk[4]=v1_nm2; // (identificateur("v1_nm2"));
    tab_uk[5]=U1_idnt; // (identificateur("U1"));
    tab_uk[6]=u2_nm1; // (identificateur("u2_nm1"));
    tab_uk[7]=v2_nm2; // (identificateur("v2_nm2"));
    tab_uk[8]=U2_idnt; // (identificateur("U2"));
    tab_uk[9]=u3_nm1; // (identificateur("u3_nm1"));
    tab_uk[10]=v3_nm2; // (identificateur("v3_nm2"));
    tab_uk[11]=U3_idnt; // (identificateur("U3"));
    tab_uk[12]=u4_nm1; // (identificateur("u4_nm1"));
    tab_uk[13]=v4_nm2; // (identificateur("v4_nm2"));
    tab_uk[14]=U4_idnt; // (identificateur("U4"));
    tab_uk[15]=u5_nm1; // (identificateur("u5_nm1"));
    tab_uk[16]=v5_nm2; // (identificateur("v5_nm2"));
    tab_uk[17]=U5_idnt; // (identificateur("U5"));
    tab_uk[18]=u6_nm1; // (identificateur("u6_nm1"));
    tab_uk[19]=v6_nm2; // (identificateur("v6_nm2"));
    tab_uk[20]=U6_idnt; // (identificateur("U6"));
    tab_uk[21]=u7_nm1; // (identificateur("u7_nm1"));
    tab_uk[22]=v7_nm2; // (identificateur("v7_nm2"));
    tab_uk[23]=U7_idnt; // (identificateur("U7"));
    tab_uk[24]=u8_nm1; // (identificateur("u8_nm1"));
    tab_uk[25]=v8_nm2; // (identificateur("v8_nm2"));
    tab_uk[26]=U8_idnt; // (identificateur("U8"));
    tab_uk[27]=u9_nm1; // (identificateur("u9_nm1"));
    tab_uk[28]=v9_nm2; // (identificateur("v9_nm2"));
    tab_uk[29]=U9_idnt; // (identificateur("U9"));
    gen n_minus_1=n__IDNT_e-1;
    for (int i=0;i<dim;++i){
      gen uk=tab_uk[3*i+2];
      vars0.push_back(new_ref_symbolic(symbolic(at_of,makenewvecteur(uk,n_minus_1))));
      vars.push_back(tab_uk[3*i]);
    }
    gen n_minus_2=n__IDNT_e-2;
    for (int i=0;i<dim;++i){
      gen uk=tab_uk[3*i+2];
      vars0.push_back(new_ref_symbolic(symbolic(at_of,makenewvecteur(uk,n_minus_2))));
      vars.push_back(tab_uk[3*i+1]);
    }
    expr=subst(expr_un,vars0,vars,true,contextptr);
    /* additional checking disabled
    vecteur lv(vars);
    lidnt(expr,lv);
    s=lv.size();
    for (int i=vars.size();i<s;++i){
      gen & g =lv[i];
      if (is_undef(g)) continue;
      if (g.type!=_IDNT)
	return 0;
      if (strlen(g._IDNTptr->id_name)>1)
	return 0;
      if (g._IDNTptr->id_name[0]<'A' || g._IDNTptr->id_name[0]>'Z')
	return 0;
    }
    */
    return retval;
  }


  // Compute UK(N) for K=k to m, where UK(k) and UK(k+1) are given
  // If the recurrence relation does not depend on UK(N-2), set UK_kp1 to vecteur(0)
  vecteur seqapp_compute(const vecteur & expr0,const vecteur & vars,const vecteur & UK_k,const vecteur &UK_kp1,int k,int m,GIAC_CONTEXT){
    gen f1f9(lidnt_function38(expr0));
    gen f1f9value=eval(f1f9,1,contextptr);
    vecteur expr(expr0);
    if (f1f9.type==_VECT && !f1f9._VECTptr->empty()){
      iterateur it=expr.begin(),itend=expr.end();
      for (;it!=itend;++it){
	*it = subst(*it,f1f9,f1f9value,true,contextptr);
      }
    }
    int dim=int(expr.size());
    vecteur UK_nm2(UK_k),UK_nm1(UK_kp1),tmp(dim);
    vecteur vals(2*dim+1);
    if (UK_k.empty()){// compute UK_n
      vals[0]=k;
      for (int i=0;i<dim;++i){
	vals[i+1]=undef;
      }      
      for (int i=0;i<dim;++i)
	vals[dim+i+1]=undef;
      UK_nm2=gen2vecteur(subst(expr,vars,vals,false,contextptr));
    }
    if (dim!=int(UK_nm2.size()))
      return vecteur(dim,gendimerr(contextptr));
    if (UK_kp1.empty()){// compute UK_np1
      vals[0]=k+1;
      for (int i=0;i<dim;++i){
	vals[i+1]=UK_nm2[i];
      }      
      for (int i=0;i<dim;++i)
	vals[dim+i+1]=undef;
      UK_nm1=subst(expr,vars,vals,false,contextptr);
    }
    gen tmpU=evalf(UK_nm2,1,contextptr);
    if (tmpU.type!=_VECT)
      return vecteur(dim,gendimerr(contextptr));
    UK_nm2=*tmpU._VECTptr;
    tmpU=evalf(UK_nm1,1,contextptr);
    if (tmpU.type!=_VECT)
      return vecteur(dim,gendimerr(contextptr));
    UK_nm1=*tmpU._VECTptr;
    vecteur res(makevecteur(UK_nm2,UK_nm1));
    res.reserve(m-k+1);
    for (int n=k+2;n<=m;++n){
      vals[0]=n;
      for (int i=0;i<dim;++i){
	vals[i+1]=UK_nm1[i];
      }
      for (int i=0;i<dim;++i){
	vals[dim+i+1]=UK_nm2[i];
      }
      vecteur::const_iterator it=expr.begin(),itend=expr.end();
      for (int i=0;it!=itend;++it,++i)
	tmp[i]=is_undef(*it)?*it:evalf(sortsubst(*it,vars,vals,false,contextptr),1,contextptr);
      res.push_back(tmp);
      UK_nm2=UK_nm1;
      UK_nm1=tmp;
    }
    return res;
  }

  gen _tests(const gen & g0,GIAC_CONTEXT){
    // return eval_before_diff(g0,vx_var,contextptr);
    if (g0.type==_VECT){
      vecteur expr,vars;
      if (g0.subtype==_SEQ__VECT && g0._VECTptr->front().type==_VECT && g0._VECTptr->size()==3){
	int i=seqapp_prepare(*g0._VECTptr->front()._VECTptr,expr,vars,contextptr);
	if (i<0)
	  return gensizeerr(contextptr);
	gen g01=(*g0._VECTptr)[1];
	gen g02=(*g0._VECTptr)[2];
	vecteur v2;
	if (i==2 && g02.type==_VECT)
	  v2=*g02._VECTptr;
	if (g01.type==_VECT)
	  return seqapp_compute(expr,vars,*g01._VECTptr,v2,0,20,contextptr);
      }
      int i=seqapp_prepare(*g0._VECTptr,expr,vars,contextptr);
      if (i<0)
	return gensizeerr(contextptr);
      return seqapp_compute(expr,vars,vecteur(expr.size(),1.0),i==1?vecteur(0):vecteur(expr.size(),2.0),0,20,contextptr);
    }
    gen expr; vecteur vars;
    int i=seqapp_prepare(g0,expr,vars,contextptr);
    if (!i)
      return undef;
    return seqapp_compute(expr,vars,1.0,i==1?undef:2.0,0,20,contextptr);
  }
  static const char _tests_s[]="tests";
  static define_unary_function_eval(__tests,&_tests,_tests_s);
  define_unary_function_ptr5( at_tests ,alias_at_tests,&__tests,0,T_UNARY_OP);

  gen _CHOOSE(const gen & args,GIAC_CONTEXT){
    if ( args.type==_STRNG &&  args.subtype==-1) return  args;
    if (args.type!=_VECT || args._VECTptr->size()<3)
      return gentypeerr(contextptr);
    vecteur v = *args._VECTptr; 
    if (v[0].is_symb_of_sommet(at_double_deux_points) && v[0]._SYMBptr->feuille.type==_VECT && v[0]._SYMBptr->feuille._VECTptr->size()==2)
      v[0]=v[0]._SYMBptr->feuille._VECTptr->back();
    for (int i=1; i<=1; i++) { if (v[i].type!=_STRNG) v[i]= eval(v[i], 1, contextptr); if (v[i].type!=_STRNG) v[i]=  string2gen(v[i].print(contextptr)); }
    if (v.front().type!=_IDNT || v[1].type!=_STRNG)
      return gentypeerr(contextptr);
#ifdef NSPIRE
    return undef;
#else
#ifndef GIAC_HAS_STO_38
    vecteur res(3);
    res[2]=v[0];
    res[0]=v[1];
    vecteur tmp;
    for (unsigned i=2;i<v.size();i++)
      tmp.push_back(eval(v[i],1,contextptr));
    res[1]=tmp;
    return __inputform.op(symbolic(at_choosebox,gen(res,_SEQ__VECT)),contextptr);
#endif
#endif
    return undef;
  }
  static const char _CHOOSE_s []="CHOOSE";
  static define_unary_function_eval_quoted (__CHOOSE,&giac::_CHOOSE,_CHOOSE_s);
  define_unary_function_ptr5( at_CHOOSE ,alias_at_CHOOSE,&__CHOOSE,_QUOTE_ARGUMENTS,T_UNARY_OP_38);



#if 0 // def GIAC_HAS_STO_38
  // encoding is up to 8 nibbles with various values...
  // 1 optional graphic name
  // 2 graphic name
  // 3 coordinate pair
  // 4 optional coordinate pair
  // 5 color
  // 6 optional color
  // 7 integer
  // 8 boolean
  // 9 graphic name, return the adresses'adress and does not allow G0!!!
  // a: angle
  // b: optional integer
  // c: w/h based on 0/0
  // 0x631 means : optional graphic name, coordinate pair, optional color

#define CyrilleFnc(n)   static const char _##n##_s []= #n;  static define_unary_function_eval_quoted (__##n,&giac::_##n,_##n##_s); define_unary_function_ptr5( at_##n ,alias_at_##n,&__##n,0,T_UNARY_OP_38);
  gen _FREEZE(const gen & args,GIAC_CONTEXT)
  {
    dofreeze();
    return 1;
  }
  CyrilleFnc(FREEZE);

  gen _GETPIX(const gen & args,GIAC_CONTEXT)
  {
    void *g=0; int xy[2];
    if (!GraphicVerifInputs(args, &g, xy, 0x31, NULL, contextptr)) return gensizeerr(contextptr);
    return gen(dogetpix(g, xy[0], xy[1]));
  }
  CyrilleFnc(GETPIX);

  gen _LINE(const gen & args,GIAC_CONTEXT)
  {
    void *g=0; int xy[4], c= 0;
    if (!GraphicVerifInputs(args, &g, xy, 0x6331, &c, contextptr)) return gensizeerr(contextptr);
    doline(g, xy[0], xy[1], xy[2], xy[3], c);
    return 1;
  }
  CyrilleFnc(LINE);

  gen _RECT(const gen & args,GIAC_CONTEXT)
  {
    void *g=0; int xy[4]= {0, 0, 0x0fffffff,0x0fffffff}, c[2]= { 3, -1};
    if (!GraphicVerifInputs(args, &g, xy, 0x66441, c, contextptr)) return gensizeerr(contextptr);
    if (c[1]==-1) c[1]= c[0];
    dorect(g, xy[0], xy[1], xy[2]-xy[0]+1, xy[3]-xy[1]+1, c[0], c[1]);
    return 1;
  }
  CyrilleFnc(RECT);

  gen _INVERT(const gen & args,GIAC_CONTEXT)
  {
    void *g=0; int xy[4]= {0, 0, 0x0fffffff, 0x0fffffff };
    if (!GraphicVerifInputs(args, &g, xy, 0x441, NULL, contextptr)) return gensizeerr(contextptr);
    doinvert(g, xy[0], xy[1], xy[2]-xy[0]+1, xy[3]-xy[1]+1);
    return 1;
  }
  CyrilleFnc(INVERT);

  gen _BLIT(const gen & args,GIAC_CONTEXT)
  {
    void *g[2]={0,0}; int xy[8]= { 0, 0, 0xfffffff, 0xfffffff, 0, 0, 0xfffffff, 0xfffffff }, c= -1;
    if (!GraphicVerifInputs(args, g, xy, 0x6442431, NULL, contextptr)) return gensizeerr(contextptr);
    xy[3]+= -xy[1]+1; if (xy[3]<0) xy[3]= -2-xy[3];
    xy[7]+= -xy[5]+1; if (xy[7]<0) xy[7]= -2-xy[7];
    doblit(g[0], xy[0], xy[1], xy[2]-xy[0]+1, xy[3], g[1], xy[4], xy[5], xy[6]-xy[4]+1, xy[7], c);
    return 1;
  }
  CyrilleFnc(BLIT);
  gen _TEXTOUT(const gen &args, GIAC_CONTEXT)
  {
    if (args.type!=_VECT) return gensizeerr(contextptr);
    int s= args._VECTptr->size(); 
    if (s<3) return gensizeerr(contextptr);
    gen t= *args._VECTptr->begin();
    gen v(*args._VECTptr); v._VECTptr->erase(v._VECTptr->begin());
    void *g=0; int xy[2]={0, 0}, c[4]= {0, 0, 1023, -1};
    //TEXTOUT("text", [G?], x, y, [font, [color, [width, [color]]]])
    if (!GraphicVerifInputs(v, &g, xy, 0x6b6b31, c, contextptr)) return gensizeerr(contextptr);
    return gen(dotextout(&t, g, xy, c, contextptr));
  }
  CyrilleFnc(TEXTOUT);

  gen _PIXON(const gen & args,GIAC_CONTEXT){
    void *g=0; int xy[2], c= 0;
    if (!GraphicVerifInputs(args, &g, xy, 0x631, &c, contextptr)) return gensizeerr(contextptr);
    dopixon(g, xy[0], xy[1], c);
    return 1;
  }

  gen _PIXOFF(const gen & args,GIAC_CONTEXT){
    void *g=0; int xy[2];
    if (!GraphicVerifInputs(args, &g, xy, 0x31, NULL, contextptr)) return gensizeerr(contextptr);
    dopixon(g, xy[0], xy[1], 3);
    return 1;
  }
  gen _DIMGROB(const gen &args,GIAC_CONTEXT)
  {
    void *g=0; int xy[2], c= 3;
    if (!GraphicVerifInputs(args, &g, xy, 0x6c9, &c, contextptr)) return gensizeerr(contextptr);
    dodimgrob((void**)g, xy[0], xy[1], c, gen());
    return 1;
  }
  CyrilleFnc(DIMGROB);
  gen _SUBGROB(const gen &args,GIAC_CONTEXT)
  {
    void *g[2]={0,0}; int xy[4]= {0, 0, 0xfffffff, 0xfffffff};
    if (!GraphicVerifInputs(args, g, xy, 0x9441, NULL, contextptr)) return gensizeerr(contextptr);
    dosubgrob(g, xy);
    return 1;
  }
  CyrilleFnc(SUBGROB);
  gen _ARC(const gen & args,GIAC_CONTEXT)
  {
    ///< draws a circle, or an arc between a1 and a2. full circle is 4096... 
    // if OldColor is !=-1 and indiate the background color of the screen BEFORE the arc is drawn, the arc is filled...
    //int Arc(int x, int y, int r, int color, int a1=0, int a2=4096, int OldColor=-1); 
    // ARC(x, y, r, [c, [a1, a2]])
    void *g=0; int xy[2], c[4]= { 0, 0, 0, 4096};
    if (!GraphicVerifInputs(args, &g, xy, 0xaab731, c, contextptr)) return gensizeerr(contextptr);
    doarc(g, true, xy, c);
    return 1;
  }

  gen _GETPIX_P(const gen & args,GIAC_CONTEXT)
  {
    void *g=0; int xy[2];
    if (!GraphicVerifInputs2(args, &g, xy, 0x31, NULL, true, contextptr)) return gensizeerr(contextptr);
    return gen(dogetpix(g, xy[0], xy[1]));
  }
  CyrilleFnc(GETPIX_P);

  gen _LINE_P(const gen & args,GIAC_CONTEXT)
  {
    void *g=0; int xy[4], c= 0;
    if (!GraphicVerifInputs2(args, &g, xy, 0x6331, &c, true, contextptr)) return gensizeerr(contextptr);
    doline(g, xy[0], xy[1], xy[2], xy[3], c);
    return 1;
  }
  CyrilleFnc(LINE_P);

  gen _RECT_P(const gen & args,GIAC_CONTEXT)
  {
    void *g=0; int xy[4]= {0, 0, 0x0fffffff,0x0fffffff}, c[2]= { 3, -1};
    if (!GraphicVerifInputs2(args, &g, xy, 0x66441, c, true, contextptr)) return gensizeerr(contextptr);
    if (c[1]==-1) c[1]= c[0];
    if (xy[0]>xy[2]) swap(xy[0], xy[2]);
    if (xy[1]>xy[3]) swap(xy[1], xy[3]);
    dorect(g, xy[0], xy[1], xy[2]-xy[0]+1, xy[3]-xy[1]+1, c[0], c[1]);
    return 1;
  }
  CyrilleFnc(RECT_P);

  gen _INVERT_P(const gen & args,GIAC_CONTEXT)
  {
    void *g=0; int xy[4]= {0, 0, 0x0fffffff, 0x0fffffff };
    if (!GraphicVerifInputs2(args, &g, xy, 0x441, NULL, true, contextptr)) return gensizeerr(contextptr);
    doinvert(g, xy[0], xy[1], xy[2]-xy[0]+1, xy[3]-xy[1]+1);
    return 1;
  }
  CyrilleFnc(INVERT_P);

  gen _BLIT_P(const gen & args,GIAC_CONTEXT)
  {
    void *g[2]={0,0}; int xy[8]= { 0, 0, 0xfffffff, 0xfffffff, 0, 0, 0xfffffff, 0xfffffff }, c= -1;
    if (!GraphicVerifInputs2(args, g, xy, 0x6442431, NULL, true, contextptr)) return gensizeerr(contextptr);
    xy[3]+= -xy[1]+1; if (xy[3]<0) xy[3]= -2-xy[3];
    xy[7]+= -xy[5]+1; if (xy[7]<0) xy[7]= -2-xy[7];
    doblit(g[0], xy[0], xy[1], xy[2]-xy[0]+1, xy[3], g[1], xy[4], xy[5], xy[6]-xy[4]+1, xy[7], c);
    return 1;
  }
  CyrilleFnc(BLIT_P);
  gen _TEXTOUT_P(const gen &args, GIAC_CONTEXT)
  {
    if (args.type!=_VECT) return gensizeerr(contextptr);
    int s= args._VECTptr->size(); 
    if (s<3) return gensizeerr(contextptr);
    gen t= *args._VECTptr->begin();
    gen v(*args._VECTptr); v._VECTptr->erase(v._VECTptr->begin());
    void *g=0; int xy[2]={0, 0}, c[4]= {0, 0, 1023, -1};
    //TEXTOUT("text", [G?], x, y, [font, [color, [width, [color]]]])
    if (!GraphicVerifInputs2(v, &g, xy, 0x6b6b31, c, true, contextptr)) return gensizeerr(contextptr);
    return gen(dotextout(&t, g, xy, c, contextptr));
  }
  CyrilleFnc(TEXTOUT_P);
  gen _PIXON_P(const gen & args,GIAC_CONTEXT)
  {
    void *g=0; int xy[2], c= 0;
    if (!GraphicVerifInputs2(args, &g, xy, 0x631, &c, true, contextptr)) return gensizeerr(contextptr);
    dopixon(g, xy[0], xy[1], c);
    return 1;
  }
  CyrilleFnc(PIXON_P);
  gen _PIXOFF_P(const gen & args,GIAC_CONTEXT)
  {
    void *g=0; int xy[2];
    if (!GraphicVerifInputs2(args, &g, xy, 0x31, NULL, true, contextptr)) return gensizeerr(contextptr);
    dopixon(g, xy[0], xy[1], 3);
    return 1;
  }
  CyrilleFnc(PIXOFF_P);
  gen _DIMGROB_P(const gen &args,GIAC_CONTEXT)
  {
    void *g=0; int xy[2], c= 3;
    if (!GraphicVerifInputs2(args, &g, xy, 0x6c9, &c, false, contextptr)) return gensizeerr(contextptr);
    dodimgrob((void**)g, xy[0], xy[1], c, args._VECTptr->end()[-1]);
    return 1;
  }
  CyrilleFnc(DIMGROB_P);
  gen _SUBGROB_P(const gen &args,GIAC_CONTEXT)
  {
    void *g[2]={0,0}; int xy[4]= {0, 0, 0xfffffff, 0xfffffff};
    if (!GraphicVerifInputs2(args, g, xy, 0x9441, NULL, true, contextptr)) return gensizeerr(contextptr);
    dosubgrob(g, xy);
    return 1;
  }
  CyrilleFnc(SUBGROB_P);
  gen _ARC_P(const gen & args,GIAC_CONTEXT)
  {
    ///< draws a circle, or an arc between a1 and a2. full circle is 4096... 
    // if OldColor is !=-1 and indiate the background color of the screen BEFORE the arc is drawn, the arc is filled...
    //int Arc(int x, int y, int r, int color, int a1=0, int a2=4096, int OldColor=-1); 
    // ARC(x, y, r, [c, [a1, a2]])
    void *g=0; int xy[2], c[4]= { 0, 0, 0, 4096};
    if (!GraphicVerifInputs2(args, &g, xy, 0xaab731, c, true, contextptr)) return gensizeerr(contextptr);
    doarc(g, false, xy, c);
    return 1;
  }
  CyrilleFnc(ARC_P);
  gen _GROBW_P(const gen & args, GIAC_CONTEXT)
  {
    void *g=0; if (!GraphicVerifInputs(args, &g, NULL, 1, NULL, contextptr)) return gensizeerr(contextptr);
    return gen(dogrobw(g));
  }
  CyrilleFnc(GROBW_P);
  gen _GROBH_P(const gen & args, GIAC_CONTEXT)
  {
    void *g=0; if (!GraphicVerifInputs(args, &g, NULL, 1, NULL, contextptr)) return gensizeerr(contextptr);
    return gen(dogrobh(g, false));
  }
  CyrilleFnc(GROBH_P);
  gen _GROBW(const gen & args, GIAC_CONTEXT)
  {
    void *g=0; if (!GraphicVerifInputs(args, &g, NULL, 1, NULL, contextptr)) return gensizeerr(contextptr);
    int w= dogrobw(g);
    return w*getxrangeperpixel();
  }
  CyrilleFnc(GROBW);
  gen _GROBH(const gen & args, GIAC_CONTEXT)
  {
    void *g=0; if (!GraphicVerifInputs(args, &g, NULL, 1, NULL, contextptr)) return gensizeerr(contextptr);
    int h= dogrobh(g, true);
    return h*getyrangeperpixel();
  }
  CyrilleFnc(GROBH);

  CyrilleFnc(ISKEYDOWN);

#else
  gen _ARC(const gen & args,GIAC_CONTEXT){
    if (args.type!=_VECT || args._VECTptr->size()!=5)
      return gensizeerr(contextptr);
    vecteur & v =*args._VECTptr;
    return _cercle(gen(makevecteur(v[0]+cst_i*v[1],v[2],v[3],v[4]),_SEQ__VECT),contextptr);
  }
  gen _PIXON(const gen & args,GIAC_CONTEXT){
    if (args.type!=_VECT || args._VECTptr->size()!=2)
      return gensizeerr(contextptr);
    vecteur & v =*args._VECTptr;
    return symb_pnt(v.front()+cst_i*v.back(),int(FL_BLACK),contextptr);
  }
  gen _PIXOFF(const gen & args,GIAC_CONTEXT){
    if (args.type!=_VECT || args._VECTptr->size()!=2)
      return gensizeerr(contextptr);
    vecteur & v =*args._VECTptr;
    return symb_pnt(v.front()+cst_i*v.back(),int(FL_WHITE),contextptr);
  }
  gen _LINE(const gen & args,GIAC_CONTEXT){
    if (args.type!=_VECT || args._VECTptr->size()!=4)
      return _droite(args,contextptr);
    vecteur & v =*args._VECTptr;
    return _droite(gen(makevecteur(v[0]+cst_i*v[1],v[2]+cst_i*v[3]),_SEQ__VECT),contextptr);
  }
  static const char _LINE_s []="LINE";
  static define_unary_function_eval (__LINE,&giac::_LINE,_LINE_s);
  define_unary_function_ptr5( at_LINE ,alias_at_LINE,&__LINE,0,T_UNARY_OP_38);

  gen _RECT(const gen & args,GIAC_CONTEXT){
    if (args.type!=_VECT || args._VECTptr->size()!=4)
      return _droite(args,contextptr);
    vecteur & v =*args._VECTptr;
    gen a=v[0],b=v[1],c=v[2],d=v[3];
    if (is_greater(a,c,contextptr)) 
      swapgen(a,c);
    if (is_greater(b,d,contextptr)) 
      swapgen(b,d);
    gen e=a+b*cst_i,f=c+b*cst_i,g=a+d*cst_i,h=c+d*cst_i;
    gen res=pnt_attrib(gen(makevecteur(e,f,h,g,e),_GROUP__VECT),vecteur(1,int(FL_BLACK)),contextptr);
    return res;
  }
  static const char _RECT_s []="RECT";
  static define_unary_function_eval (__RECT,&giac::_RECT,_RECT_s);
  define_unary_function_ptr5( at_RECT ,alias_at_RECT,&__RECT,0,T_UNARY_OP_38);

#endif
  static const char _PIXON_s []="PIXON";
  static define_unary_function_eval (__PIXON,&giac::_PIXON,_PIXON_s);
  define_unary_function_ptr5( at_PIXON ,alias_at_PIXON,&__PIXON,0,T_UNARY_OP_38);
  static const char _PIXOFF_s []="PIXOFF";
  static define_unary_function_eval (__PIXOFF,&giac::_PIXOFF,_PIXOFF_s);
  define_unary_function_ptr5( at_PIXOFF ,alias_at_PIXOFF,&__PIXOFF,0,T_UNARY_OP_38);
  static const char _ARC_s []="ARC";
  static define_unary_function_eval (__ARC,&giac::_ARC,_ARC_s);
  define_unary_function_ptr5( at_ARC ,alias_at_ARC,&__ARC,0,T_UNARY_OP_38);

  static const char _PRINT_s []="PRINT";
  static define_unary_function_eval_quoted (__PRINT,&giac::_print,_PRINT_s);
  define_unary_function_ptr5( at_PRINT ,alias_at_PRINT,&__PRINT,0,T_UNARY_OP_38);

  static const char _SEC_s []="SEC";
  static define_unary_function_eval (__SEC,&giac::_sec,_SEC_s);
  define_unary_function_ptr5( at_SEC ,alias_at_SEC,&__SEC,0,T_UNARY_OP_38);

  static const char _CSC_s []="CSC";
  static define_unary_function_eval (__CSC,&giac::_csc,_CSC_s);
  define_unary_function_ptr5( at_CSC ,alias_at_CSC,&__CSC,0,T_UNARY_OP_38);

  static const char _COT_s []="COT";
  static define_unary_function_eval (__COT,&giac::_cot,_COT_s);
  define_unary_function_ptr5( at_COT ,alias_at_COT,&__COT,0,T_UNARY_OP_38);

  static const char _ASEC_s []="ASEC";
  static define_unary_function_eval (__ASEC,&giac::_asec,_ASEC_s);
  define_unary_function_ptr5( at_ASEC ,alias_at_ASEC,&__ASEC,0,T_UNARY_OP_38);

  static const char _ACSC_s []="ACSC";
  static define_unary_function_eval (__ACSC,&giac::_acsc,_ACSC_s);
  define_unary_function_ptr5( at_ACSC ,alias_at_ACSC,&__ACSC,0,T_UNARY_OP_38);

  static const char _ACOT_s []="ACOT";
  static define_unary_function_eval (__ACOT,&giac::_acot,_ACOT_s);
  define_unary_function_ptr5( at_ACOT ,alias_at_ACOT,&__ACOT,0,T_UNARY_OP_38);

  gen _Celsius2Fahrenheit(const gen & g,GIAC_CONTEXT){
    if (g.type==_VECT)
      return apply(g,_Celsius2Fahrenheit,contextptr);
    return (g*gen(9))/5+32;
  }
  static const char _Celsius2Fahrenheit_s []="Celsius2Fahrenheit";
  static define_unary_function_eval (__Celsius2Fahrenheit,&giac::_Celsius2Fahrenheit,_Celsius2Fahrenheit_s);
  define_unary_function_ptr5( at_Celsius2Fahrenheit ,alias_at_Celsius2Fahrenheit,&__Celsius2Fahrenheit,0,T_UNARY_OP);

  gen _Fahrenheit2Celsius(const gen & g,GIAC_CONTEXT){
    if (g.type==_VECT)
      return apply(g,_Fahrenheit2Celsius,contextptr);
    return (g-32)*gen(5)/9;
  }
  static const char _Fahrenheit2Celsius_s []="Fahrenheit2Celsius";
  static define_unary_function_eval (__Fahrenheit2Celsius,&giac::_Fahrenheit2Celsius,_Fahrenheit2Celsius_s);
  define_unary_function_ptr5( at_Fahrenheit2Celsius ,alias_at_Fahrenheit2Celsius,&__Fahrenheit2Celsius,0,T_UNARY_OP);

  // put here function names that are in lowercase in giac and should be printed uppercase
  // on HP
  static const char * const display_in_maj[] ={
    "ABS",
    "ACOS",
    "ACOSH",
    "ACOT",
    "ACSC",
    //    "ADDCOL",
    // "ADDROW",
    // "ALOG",
    "AND",
    // "ARC",
    "ARG",
    "ASEC",
    "ASIN",
    "ASINH",
    "ATAN",
    "ATANH",
    "BINOMIAL",
    "BINOMIAL_CDF",
    "BINOMIAL_ICDF",
    "BITAND",
    // "BITNOT",
    "BITOR",
    "BITXOR",
    //"BREAK",
    "CEILING",
    "CFACTOR",
    "CHAR",
    "CHISQUARE",
    "CHISQUARE_CDF",
    "CHISQUARE_ICDF",
    //"CHOOSE",
    "COLNORM",
    "COMB",
    "CONCAT",
    // "COND",
    "CONJ",
    "COS",
    "COSH",
    "COT",
    "CROSS",
    "CSC",
    "CSOLVE",
    // "DEGXRAD",
    // "DELCOL",
    // "DELROW",
    "DET",
    "DIM",
    //"DISP",
    "DOT",
    // "EIGENVAL",
    // "EIGENVV",
    "EXP",
    // "EXPM1",
    // "EXPORT",
    "EXPR",
    "FLOOR",
    "FISHER",
    "FISHER_CDF",
    "FISHER_ICDF",
    "FLOOR",
    //"FNROOT",
    "FP",
    // "FREEZE",
    // "GETKEY",
    // "GF",
    //"HMSX",
    //"IDENMAT",
    "IM",
    // "INPUT",
    "IP",
    "INVERSE",
    // "ISOLATE",
    "ISPRIME",
    // "ITERATE",
    "LINE",
    // "LINEAR?",
    "LN",
    // "LNP1",
    "LOG",
    // "LQ",
    // "LSQ",
    "LU",
    //"MAKELIST",
    "MAKEMAT",
    // "MANT",
    "MAX",
    // "MAXREAL",
    "MID",
    "MIN",
    // "MINREAL",
    "MKSA",
//    "MOD", // removed as cas has MOD and mod (operator and function)
    // "MSGBOX",
    "NEG",
    "NORMALD",
    "NORMALD_CDF",
    "NORMALD_ICDF",
    "NOT",
    // "NTHROOT",
    "OR",
    "PERM",
    "PI",
    "PIECEWISE",
    // "PIXOFF",
    // "PIXON",
    "POISSON",
    "POISSON_CDF",
    "POISSON_ICDF",
    // "POLYCOEF",
    // "POLYEVAL",
    // "POLYFORM",
    // "POLYROOT",
    // "POS",
    "PRINT",
    "QR",
    // "QUAD",
    "QUOTE",
    // "RADXDEG",
    //"RANDMAT",
    "RANDNORM",
    // "RANDOM",
    "RANDSEED",
    "RANK",
    "RE",
    // "RECURSE",
    // "REDIM",
    // "REPLACE",
    "RETURN",
    //"REVERSE",
    "RIGHT",
    "ROTATE",
    "ROUND",
    "ROWNORM",
    "RREF",
    // "SCALE",
    // "SCALEADD",
    // "SCHUR",
    "SEC",
    "SIGN",
    "SIN",
    "SINH",
    "SIZE",
    "SORT",
    // "SPECNORM",
    // "SPECRAD",
    "STRING",
    "STUDENT",
    "STUDENT_CDF",
    "STUDENT_ICDF",
    //"SUB",
    // "SVD",
    // "SVL",
    // "SWAPCOL",
    // "SWAPROW",
    "TAN",
    "TANH",
    "TAYLOR",
    "TCOLLECT",
    "TEXPAND",
    //"TRACE",
    "TRN",
    //"TRUNCATE",
    //"UTPC",
    //"UTPF",
    //"UTPN",
    //"UTPT",
    // "VIEWS",
    //"WAIT",
    // "XHMS",
    "XOR",
    // "XPON",
  };

  static const int display_in_maj_size=sizeof(display_in_maj)/sizeof(const char *);

  // check if a lowercase commandname should be uppercased
  static char maj_converted[16];
  
  char * hp38_display_in_maj(const char * s){
    int l=int(strlen(s));
    if (l>15)
      return 0;
    maj_converted[l]=0;
    for (int i=0;i<l;++i){
      maj_converted[i]=toupper(s[i]);
    }
    int beg=0,end=display_in_maj_size,cur,test;
    // string index is always >= begin and < end
    for (;;){
      cur=(beg+end)/2;
      test=strcmp(maj_converted,display_in_maj[cur]);
      if (!test)
	return maj_converted;
      if (cur==beg){
	return 0;
      }
      if (test>0)
	beg=cur;
      else
	end=cur;
    }
    return 0;
  }

  gen _polar_complex(const gen & g,GIAC_CONTEXT){
    if (g.type==_STRNG && g.subtype==-1) return  g;
    if (g.type!=_VECT || g._VECTptr->size()!=2)
      return gensizeerr(contextptr);
    gen res= g._VECTptr->front();
    gen angle=g._VECTptr->back();
    if (angle.is_symb_of_sommet(at_unit)){
      gen f=angle._SYMBptr->feuille;
      gen f0=f[0],f1=f[1];
      if (f1==(gen("_deg",contextptr)._SYMBptr->feuille)[1])
	return res*exp(cst_i*f0*cst_pi/gen(180),contextptr);
      if (f1==(gen("_grad",contextptr)._SYMBptr->feuille)[1])
	return res*exp(cst_i*f0*cst_pi/gen(200),contextptr);
      if (f1==(gen("_rad",contextptr)._SYMBptr->feuille)[1])
	return res*exp(cst_i*f0,contextptr);
    }
#ifdef GIAC_HAS_STO_38
    angle=evalf(angle,1,contextptr);
    res= evalf(res,1,contextptr);
    if (angle.type==_FLOAT_ && res.type==_FLOAT_)
      {
	HP_Real a, r, s, c;
	fExpand(gen2HP(angle), &a); fExpand(gen2HP(res), &r);
	fisin(&a, &s, angle_radian(contextptr)?AMRad:(angle_degree(contextptr)?AMDeg:AMGrad)); ficos(&a, &c, angle_radian(contextptr)?AMRad:(angle_degree(contextptr)?AMDeg:AMGrad)); //grad
	fimul_L(&s, &r, &s); fimul_L(&c, &r, &c);
	HP_gen C= fUnExpand(&c), S= fUnExpand(&s);
	gen gC, gS; gC= HP2gen(C); gS= HP2gen(S);
	res= gC+gS*cst_i;
      } else {
      if(!angle_radian(contextptr))
      {
        //grad
        if(angle_degree(contextptr))
          angle = angle * m_pi(contextptr) / 180;
        else
          angle = angle * m_pi(contextptr) / 200;
      }
      res=res*exp(cst_i*angle,contextptr);
    }
#else
    res=res*(cos(angle,contextptr)+cst_i*sin(angle,contextptr));
#endif
    if (res.type==_CPLX){
      int * ptr = complex_display_ptr(res);
      if (ptr)
	*ptr=1;
      return res;
    }
    else
      return calc_mode(contextptr)==1?symbolic(at_ggb_ang,g):symbolic(at_polar_complex,g);
  }
#ifdef BCD
  static const char _polar_complex_s[]="\xe2\x88\xa1";
#else
  static const char _polar_complex_s[]="∡"; // " polar_complex ";
#endif
  static define_unary_function_eval4 (__polar_complex,&giac::_polar_complex,_polar_complex_s,&printsommetasoperator,&texprintsommetasoperator); 
  define_unary_function_ptr5( at_polar_complex ,alias_at_polar_complex,&__polar_complex,0,T_MOD);  

  static const char _ggb_ang_s []="ggb_ang"; // prefixed version of polar complex
  static define_unary_function_eval (__ggb_ang,&_polar_complex,_ggb_ang_s);
  define_unary_function_ptr5( at_ggb_ang ,alias_at_ggb_ang,&__ggb_ang,0,true);

#ifdef GIAC_HAS_STO_38
  gen aspen_HDigits(int i);
  gen aspen_HFormat(int i);
  gen aspen_HAngle(int i);
  gen aspen_HComplex(int i);
  gen aspen_HLanguage(int i);
#endif

  gen _HDigits(const gen & g0,GIAC_CONTEXT){
    gen g=g0;
    if (g.type==_VECT && g._VECTptr->empty()){
      g=-1;
    }
    else {
      if (g.type==_FLOAT_)
	g=get_int(g0._FLOAT_val);
      if (g.type==_DOUBLE_)
	g=_floor(g,contextptr);
      if (g.type!=_INT_)
	return gentypeerr(contextptr);
      if (g.val<0 || g.val>12)
	return gensizeerr(contextptr);
    }
#ifdef GIAC_HAS_STO_38
    return aspen_HDigits(g.val);
#else
    return _Digits(g,contextptr);
#endif
  }
  static const char _HDigits_s []="HDigits";
  static define_unary_function_eval2 (__HDigits,&_HDigits,_HDigits_s,&printasDigits);
  define_unary_function_ptr( at_HDigits ,alias_at_HDigits ,&__HDigits);

  gen _HFormat(const gen & g0,GIAC_CONTEXT){
    gen g=g0;
    if (g.type==_VECT && g._VECTptr->empty()){
      g=-1;
    }
    else {
      if (g.type==_FLOAT_)
	g=get_int(g0._FLOAT_val);
      if (g.type==_DOUBLE_)
	g=_floor(g,contextptr);
      if (g.type!=_INT_)
	return gentypeerr(contextptr);
      if (g.val<0 || g.val>4)
	return gensizeerr(contextptr);
    }
#ifdef GIAC_HAS_STO_38
    return aspen_HFormat(g.val);
#else
    return _scientific_format(g,contextptr);
#endif
  }
  static const char _HFormat_s []="HFormat";
  static define_unary_function_eval2 (__HFormat,&_HFormat,_HFormat_s,&printasDigits);
  define_unary_function_ptr( at_HFormat ,alias_at_HFormat ,&__HFormat);

  gen _HAngle(const gen & g0,GIAC_CONTEXT){
    gen g=g0;
    if (g.type==_VECT && g._VECTptr->empty()){
      g=-1;
    }
    else {
      if (g.type==_FLOAT_)
	g=get_int(g0._FLOAT_val);
      if (g.type==_DOUBLE_)
	g=_floor(g,contextptr);
      if (g.type!=_INT_)
	return gentypeerr(contextptr);
      if (g.val<1 || g.val>2)
	return gensizeerr(contextptr);
    }
#ifdef GIAC_HAS_STO_38
    return aspen_HAngle(g.val);
#else
    return _angle_radian(g-1,contextptr);
#endif
  }
  static const char _HAngle_s []="HAngle";
  static define_unary_function_eval2 (__HAngle,&_HAngle,_HAngle_s,&printasDigits);
  define_unary_function_ptr( at_HAngle ,alias_at_HAngle ,&__HAngle);

  gen _HComplex(const gen & g0,GIAC_CONTEXT){
    gen g=g0;
    if (g.type==_VECT && g._VECTptr->empty()){
      g=-1;
    }
    else {
      if (g.type==_FLOAT_)
	g=get_int(g0._FLOAT_val);
      if (g.type==_DOUBLE_)
	g=_floor(g,contextptr);
      if (g.type!=_INT_)
	return gentypeerr(contextptr);
      if (g.val<0 || g.val>1)
	return gensizeerr(contextptr);
    }
#ifdef GIAC_HAS_STO_38
    return aspen_HComplex(g.val);
#else
    return _complex_mode(g,contextptr);
#endif
  }
  static const char _HComplex_s []="HComplex";
  static define_unary_function_eval2 (__HComplex,&_HComplex,_HComplex_s,&printasDigits);
  define_unary_function_ptr( at_HComplex ,alias_at_HComplex ,&__HComplex);

  gen _HLanguage(const gen & g0,GIAC_CONTEXT){
    gen g=g0;
    if (g.type==_VECT && g._VECTptr->empty()){
      g=-1;
    }
    else {
      if (g.type==_FLOAT_)
	g=get_int(g0._FLOAT_val);
      if (g.type==_DOUBLE_)
	g=_floor(g,contextptr);
      if (g.type!=_INT_)
	return gentypeerr(contextptr);
      if (g.val<0 || g.val>2)
	return gensizeerr(contextptr);
    }
#ifdef GIAC_HAS_STO_38
    return aspen_HLanguage(g.val);
#else
    if (g==-1)
      return language(contextptr);
    language(g.val,contextptr);
    return g.val;
#endif
  }
  static const char _HLanguage_s []="HLanguage";
  static define_unary_function_eval2 (__HLanguage,&_HLanguage,_HLanguage_s,&printasDigits);
  define_unary_function_ptr( at_HLanguage ,alias_at_HLanguage ,&__HLanguage);

  gen _EDITMAT(const gen & args,GIAC_CONTEXT){
    if (args.type==_STRNG &&  args.subtype==-1) return  args;
#ifdef GIAC_HAS_STO_38
    if (args.type!=_IDNT)
      return gensizeerr(contextptr);
    const char * id = args._IDNTptr->id_name;
    if (id[0]!='M' || id[1]<'0' || id[1]>'9')
      return gensizeerr(contextptr);
    int i=id[1]-'0';
//    EditMat(i?i-1:9);
#endif
    return eval(args,1,contextptr);
  }
  static const char _EDITMAT_s []="EDITMAT";
  static define_unary_function_eval_quoted (__EDITMAT,&giac::_EDITMAT,_EDITMAT_s);
  define_unary_function_ptr5( at_EDITMAT ,alias_at_EDITMAT,&__EDITMAT,_QUOTE_ARGUMENTS,T_UNARY_OP_38);

#ifndef NO_NAMESPACE_GIAC
} // namespace giac
#endif // ndef NO_NAMESPACE_GIAC