/usr/share/doc/maxima-doc/html/maxima_36.html is in maxima-doc 5.32.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- Created on January, 10 2014 by texi2html 1.76 -->
<!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Many creative people <dev@texi2html.cvshome.org>
Send bugs and suggestions to <users@texi2html.cvshome.org>
-->
<head>
<title>Maxima 5.32.1 Manual: 36. Function Definition</title>
<meta name="description" content="Maxima 5.32.1 Manual: 36. Function Definition">
<meta name="keywords" content="Maxima 5.32.1 Manual: 36. Function Definition">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 1.76">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.sansserif {font-family:sans-serif; font-weight:normal;}
ul.toc {list-style: none}
body
{
color: black;
background: white;
margin-left: 8%;
margin-right: 13%;
}
h1
{
margin-left: +8%;
font-size: 150%;
font-family: sans-serif
}
h2
{
font-size: 125%;
font-family: sans-serif
}
h3
{
font-size: 100%;
font-family: sans-serif
}
h2,h3,h4,h5,h6 { margin-left: +4%; }
div.textbox
{
border: solid;
border-width: thin;
/* width: 100%; */
padding-top: 1em;
padding-bottom: 1em;
padding-left: 2em;
padding-right: 2em
}
div.titlebox
{
border: none;
padding-top: 1em;
padding-bottom: 1em;
padding-left: 2em;
padding-right: 2em;
background: rgb(200,255,255);
font-family: sans-serif
}
div.synopsisbox
{
border: none;
padding-top: 1em;
padding-bottom: 1em;
padding-left: 2em;
padding-right: 2em;
background: rgb(255,220,255);
/*background: rgb(200,255,255); */
/* font-family: fixed */
}
pre.example
{
border: 1px solid gray;
padding-top: 1em;
padding-bottom: 1em;
padding-left: 1em;
padding-right: 1em;
/* background: rgb(247,242,180); */ /* kind of sandy */
/* background: rgb(200,255,255); */ /* sky blue */
background-color: #F1F5F9; /* light blue-gray */
/* font-family: "Lucida Console", monospace */
}
div.spacerbox
{
border: none;
padding-top: 2em;
padding-bottom: 2em
}
div.image
{
margin: 0;
padding: 1em;
text-align: center;
}
div.categorybox
{
border: 1px solid gray;
padding-top: 0px;
padding-bottom: 0px;
padding-left: 1em;
padding-right: 1em;
background: rgb(247,242,220);
}
-->
</style>
<link rel="icon" href="http://maxima.sourceforge.net/favicon.ico"/>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Function-Definition"></a>
<a name="SEC193"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="maxima_35.html#SEC192" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC194" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima_35.html#SEC186" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_37.html#SEC200" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h1 class="chapter"> 36. Function Definition </h1>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#SEC194">36.1 Introduction to Function Definition</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC195">36.2 Function</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC198">36.3 Macros</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC199">36.4 Functions and Variables for Function Definition</a></td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<p><a name="Item_003a-Introduction-to-Function-Definition"></a>
</p><hr size="6">
<a name="Introduction-to-Function-Definition"></a>
<a name="SEC194"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC193" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC195" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC193" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC193" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_37.html#SEC200" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 36.1 Introduction to Function Definition </h2>
<p><a name="Item_003a-Function"></a>
</p><hr size="6">
<a name="Function"></a>
<a name="SEC195"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC194" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC196" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC193" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC193" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_37.html#SEC200" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 36.2 Function </h2>
<div class=categorybox>
·
<p>@ref{Category: Function definition} ·
@ref{Category: Programming}
</div>
</p>
<hr size="6">
<a name="SEC196"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC195" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC197" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC193" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC195" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_37.html#SEC200" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection"> 36.2.1 Ordinary functions </h3>
<p>To define a function in Maxima you use the <code>:=</code> operator.
E.g.
</p>
<pre class="example">f(x) := sin(x)
</pre>
<p>defines a function <code>f</code>.
Anonymous functions may also be created using <code>lambda</code>.
For example
</p>
<pre class="example">lambda ([i, j], ...)
</pre>
<p>can be used instead of <code>f</code>
where
</p>
<pre class="example">f(i,j) := block ([], ...);
map (lambda ([i], i+1), l)
</pre>
<p>would return a list with 1 added to each term.
</p>
<p>You may also define a function with a variable number of arguments,
by having a final argument which is assigned to a list of the extra
arguments:
</p>
<pre class="example">(%i1) f ([u]) := u;
(%o1) f([u]) := u
(%i2) f (1, 2, 3, 4);
(%o2) [1, 2, 3, 4]
(%i3) f (a, b, [u]) := [a, b, u];
(%o3) f(a, b, [u]) := [a, b, u]
(%i4) f (1, 2, 3, 4, 5, 6);
(%o4) [1, 2, [3, 4, 5, 6]]
</pre>
<p>The right hand side of a function is an expression. Thus
if you want a sequence of expressions, you do
</p>
<pre class="example">f(x) := (expr1, expr2, ...., exprn);
</pre>
<p>and the value of <var>exprn</var> is what is returned by the function.
</p>
<p>If you wish to make a <code>return</code> from some expression inside the
function then you must use <code>block</code> and <code>return</code>.
</p>
<pre class="example">block ([], expr1, ..., if (a > 10) then return(a), ..., exprn)
</pre>
<p>is itself an expression, and so could take the place of the
right hand side of a function definition. Here it may happen
that the return happens earlier than the last expression.
</p>
<p>The first <code>[]</code> in the block, may contain a list of variables and
variable assignments, such as <code>[a: 3, b, c: []]</code>, which would cause the
three variables <code>a</code>,<code>b</code>,and <code>c</code> to not refer to their
global values, but rather have these special values for as long as the
code executes inside the <code>block</code>, or inside functions called from
inside the <code>block</code>. This is called <i>dynamic</i> binding, since the
variables last from the start of the block to the time it exits. Once
you return from the <code>block</code>, or throw out of it, the old values (if
any) of the variables will be restored. It is certainly a good idea
to protect your variables in this way. Note that the assignments
in the block variables, are done in parallel. This means, that if
you had used <code>c: a</code> in the above, the value of <code>c</code> would
have been the value of <code>a</code> at the time you just entered the block,
but before <code>a</code> was bound. Thus doing something like
</p>
<pre class="example">block ([a: a], expr1, ... a: a+3, ..., exprn)
</pre>
<p>will protect the external value of <code>a</code> from being altered, but
would let you access what that value was. Thus the right hand
side of the assignments, is evaluated in the entering context, before
any binding occurs.
Using just <code>block ([x], ...)</code> would cause the <code>x</code> to have itself
as value, just as if it would have if you entered a fresh Maxima
session.
</p>
<p>The actual arguments to a function are treated in exactly same way as
the variables in a block. Thus in
</p>
<pre class="example">f(x) := (expr1, ..., exprn);
</pre>
<p>and
</p>
<pre class="example">f(1);
</pre>
<p>we would have a similar context for evaluation of the expressions
as if we had done
</p>
<pre class="example">block ([x: 1], expr1, ..., exprn)
</pre>
<p>Inside functions, when the right hand side of a definition,
may be computed at runtime, it is useful to use <code>define</code> and
possibly <code>buildq</code>.
</p>
<hr size="6">
<a name="SEC197"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC196" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC198" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC193" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC195" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_37.html#SEC200" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection"> 36.2.2 Array functions </h3>
<p>An array function stores the function value the first time it is called with a
given argument, and returns the stored value, without recomputing it, when that
same argument is given. Such a function is often called a
<i>memoizing function</i>.
</p>
<p>Array function names are appended to the global list <code>arrays</code>
(not the global list <code>functions</code>). <code>arrayinfo</code> returns the list of
arguments for which there are stored values, and <code>listarray</code> returns the
stored values. <code>dispfun</code> and <code>fundef</code> return the array function
definition.
</p>
<p><code>arraymake</code> constructs an array function call,
analogous to <code>funmake</code> for ordinary functions.
<code>arrayapply</code> applies an array function to its arguments,
analogous to <code>apply</code> for ordinary functions.
There is nothing exactly analogous to <code>map</code> for array functions,
although <code>map(lambda([<var>x</var>], <var>a</var>[<var>x</var>]), <var>L</var>)</code> or
<code>makelist(<var>a</var>[<var>x</var>], <var>x</var>, <var>L</var>)</code>, where <var>L</var> is a list,
are not too far off the mark.
</p>
<p><code>remarray</code> removes an array function definition (including any stored
function values), analogous to <code>remfunction</code> for ordinary functions.
</p>
<p><code>kill(<var>a</var>[<var>x</var>])</code> removes the value of the array function <var>a</var>
stored for the argument <var>x</var>;
the next time <var>a</var> is called with argument <var>x</var>,
the function value is recomputed.
However, there is no way to remove all of the stored values at once,
except for <code>kill(<var>a</var>)</code> or <code>remarray(<var>a</var>)</code>,
which also remove the function definition.
</p>
<p><a name="Item_003a-Macros"></a>
</p><hr size="6">
<a name="Macros"></a>
<a name="SEC198"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC197" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC199" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC193" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC193" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_37.html#SEC200" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 36.3 Macros </h2>
<p><a name="buildq"></a>
<a name="Item_003a-buildq"></a>
</p><dl>
<dt><u>Function:</u> <b>buildq</b><i> (<var>L</var>, <var>expr</var>)</i>
<a name="IDX1510"></a>
</dt>
<dd><p>Substitutes variables named by the list <var>L</var> into the expression <var>expr</var>,
in parallel, without evaluating <var>expr</var>. The resulting expression is
simplified, but not evaluated, after <code>buildq</code> carries out the substitution.
</p>
<p>The elements of <var>L</var> are symbols or assignment expressions
<code><var>symbol</var>: <var>value</var></code>, evaluated in parallel. That is, the binding
of a variable on the right-hand side of an assignment is the binding of that
variable in the context from which <code>buildq</code> was called, not the binding of
that variable in the variable list <var>L</var>. If some variable in <var>L</var> is not
given an explicit assignment, its binding in <code>buildq</code> is the same as in
the context from which <code>buildq</code> was called.
</p>
<p>Then the variables named by <var>L</var> are substituted into <var>expr</var> in parallel.
That is, the substitution for every variable is determined before any
substitution is made, so the substitution for one variable has no effect on any
other.
</p>
<p>If any variable <var>x</var> appears as <code>splice (<var>x</var>)</code> in <var>expr</var>,
then <var>x</var> must be bound to a list,
and the list is spliced (interpolated) into <var>expr</var> instead of substituted.
</p>
<p>Any variables in <var>expr</var> not appearing in <var>L</var> are carried into the result
verbatim, even if they have bindings in the context from which <code>buildq</code>
was called.
</p>
<p>Examples
</p>
<p><code>a</code> is explicitly bound to <code>x</code>, while <code>b</code> has the same binding
(namely 29) as in the calling context, and <code>c</code> is carried through verbatim.
The resulting expression is not evaluated until the explicit evaluation
<code>''%</code>.
</p>
<pre class="example">(%i1) (a: 17, b: 29, c: 1729)$
(%i2) buildq ([a: x, b], a + b + c);
(%o2) x + c + 29
(%i3) ''%;
(%o3) x + 1758
</pre>
<p><code>e</code> is bound to a list, which appears as such in the arguments of
<code>foo</code>, and interpolated into the arguments of <code>bar</code>.
</p>
<pre class="example">(%i1) buildq ([e: [a, b, c]], foo (x, e, y));
(%o1) foo(x, [a, b, c], y)
(%i2) buildq ([e: [a, b, c]], bar (x, splice (e), y));
(%o2) bar(x, a, b, c, y)
</pre>
<p>The result is simplified after substitution. If simplification were applied
before substitution, these two results would be the same.
</p>
<pre class="example">(%i1) buildq ([e: [a, b, c]], splice (e) + splice (e));
(%o1) 2 c + 2 b + 2 a
(%i2) buildq ([e: [a, b, c]], 2 * splice (e));
(%o2) 2 a b c
</pre>
<p>The variables in <var>L</var> are bound in parallel; if bound sequentially,
the first result would be <code>foo (b, b)</code>.
Substitutions are carried out in parallel;
compare the second result with the result of <code>subst</code>,
which carries out substitutions sequentially.
</p>
<pre class="example">(%i1) buildq ([a: b, b: a], foo (a, b));
(%o1) foo(b, a)
(%i2) buildq ([u: v, v: w, w: x, x: y, y: z, z: u],
bar (u, v, w, x, y, z));
(%o2) bar(v, w, x, y, z, u)
(%i3) subst ([u=v, v=w, w=x, x=y, y=z, z=u],
bar (u, v, w, x, y, z));
(%o3) bar(u, u, u, u, u, u)
</pre>
<p>Construct a list of equations with some variables or expressions on the
left-hand side and their values on the right-hand side. <code>macroexpand</code>
shows the expression returned by <code>show_values</code>.
</p>
<pre class="example">(%i1) show_values ([L]) ::= buildq ([L], map ("=", 'L, L));
(%o1) show_values([L]) ::= buildq([L], map("=", 'L, L))
(%i2) (a: 17, b: 29, c: 1729)$
(%i3) show_values (a, b, c - a - b);
(%o3) [a = 17, b = 29, c - b - a = 1683]
(%i4) macroexpand (show_values (a, b, c - a - b));
(%o4) map(=, '([a, b, c - b - a]), [a, b, c - b - a])
</pre>
<p>Given a function of several arguments,
create another function for which some of the arguments are fixed.
</p>
<pre class="example">(%i1) curry (f, [a]) :=
buildq ([f, a], lambda ([[x]], apply (f, append (a, x))))$
(%i2) by3 : curry ("*", 3);
(%o2) lambda([[x]], apply(*, append([3], x)))
(%i3) by3 (a + b);
(%o3) 3 (b + a)
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function definition}
</div>
</p></dd></dl>
<p><a name="macroexpand"></a>
<a name="Item_003a-macroexpand"></a>
</p><dl>
<dt><u>Function:</u> <b>macroexpand</b><i> (<var>expr</var>)</i>
<a name="IDX1511"></a>
</dt>
<dd><p>Returns the macro expansion of <var>expr</var> without evaluating it,
when <code>expr</code> is a macro function call.
Otherwise, <code>macroexpand</code> returns <var>expr</var>.
</p>
<p>If the expansion of <var>expr</var> yields another macro function call,
that macro function call is also expanded.
</p>
<p><code>macroexpand</code> quotes its argument.
However, if the expansion of a macro function call has side effects,
those side effects are executed.
</p>
<p>See also <code>::=</code>, <code>macros</code>, and <code>macroexpand1</code>.
</p>
<p>Examples
</p>
<pre class="example">(%i1) g (x) ::= x / 99;
x
(%o1) g(x) ::= --
99
(%i2) h (x) ::= buildq ([x], g (x - a));
(%o2) h(x) ::= buildq([x], g(x - a))
(%i3) a: 1234;
(%o3) 1234
(%i4) macroexpand (h (y));
y - a
(%o4) -----
99
(%i5) h (y);
y - 1234
(%o5) --------
99
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function application}
</div>
</p></dd></dl>
<p><a name="macroexpand1"></a>
<a name="Item_003a-macroexpand1"></a>
</p><dl>
<dt><u>Function:</u> <b>macroexpand1</b><i> (<var>expr</var>)</i>
<a name="IDX1512"></a>
</dt>
<dd><p>Returns the macro expansion of <var>expr</var> without evaluating it,
when <code>expr</code> is a macro function call.
Otherwise, <code>macroexpand1</code> returns <var>expr</var>.
</p>
<p><code>macroexpand1</code> quotes its argument.
However, if the expansion of a macro function call has side effects,
those side effects are executed.
</p>
<p>If the expansion of <var>expr</var> yields another macro function call,
that macro function call is not expanded.
</p>
<p>See also <code>::=</code>, <code>macros</code>, and <code>macroexpand</code>.
</p>
<p>Examples
</p>
<pre class="example">(%i1) g (x) ::= x / 99;
x
(%o1) g(x) ::= --
99
(%i2) h (x) ::= buildq ([x], g (x - a));
(%o2) h(x) ::= buildq([x], g(x - a))
(%i3) a: 1234;
(%o3) 1234
(%i4) macroexpand1 (h (y));
(%o4) g(y - a)
(%i5) h (y);
y - 1234
(%o5) --------
99
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function application}
</div>
</p></dd></dl>
<p><a name="macros"></a>
<a name="Item_003a-macros"></a>
</p><dl>
<dt><u>Global variable:</u> <b>macros</b>
<a name="IDX1513"></a>
</dt>
<dd><p>Default value: <code>[]</code>
</p>
<p><code>macros</code> is the list of user-defined macro functions.
The macro function definition operator <code>::=</code> puts a new macro function
onto this list, and <code>kill</code>, <code>remove</code>, and <code>remfunction</code> remove
macro functions from the list.
</p>
<p>See also <code>infolists</code>.
</p>
<div class=categorybox>
·
<p>@ref{Category: Function definition} ·
@ref{Category: Global variables}
</div>
</p></dd></dl>
<p><a name="splice"></a>
<a name="Item_003a-splice"></a>
</p><dl>
<dt><u>Function:</u> <b>splice</b><i> (<var>a</var>)</i>
<a name="IDX1514"></a>
</dt>
<dd><p>Splices (interpolates) the list named by the atom <var>a</var> into an expression,
but only if <code>splice</code> appears within <code>buildq</code>;
otherwise, <code>splice</code> is treated as an undefined function.
If appearing within <code>buildq</code> as <var>a</var> alone (without <code>splice</code>),
<var>a</var> is substituted (not interpolated) as a list into the result.
The argument of <code>splice</code> can only be an atom;
it cannot be a literal list or an expression which yields a list.
</p>
<p>Typically <code>splice</code> supplies the arguments for a function or operator.
For a function <code>f</code>, the expression <code>f (splice (<var>a</var>))</code> within
<code>buildq</code> expands to <code>f (<var>a</var>[1], <var>a</var>[2], <var>a</var>[3], ...)</code>.
For an operator <code>o</code>, the expression <code>"o" (splice (<var>a</var>)</code> within
<code>buildq</code> expands to <code>"o" (<var>a</var>[1], <var>a</var>[2], <var>a</var>[3], ...)</code>,
where <code>o</code> may be any type of operator (typically one which takes multiple
arguments). Note that the operator must be enclosed in double quotes <code>"</code>.
</p>
<p>Examples
</p>
<pre class="example">(%i1) buildq ([x: [1, %pi, z - y]], foo (splice (x)) / length (x));
foo(1, %pi, z - y)
(%o1) -----------------------
length([1, %pi, z - y])
(%i2) buildq ([x: [1, %pi]], "/" (splice (x)));
1
(%o2) ---
%pi
(%i3) matchfix ("<>", "<>");
(%o3) <>
(%i4) buildq ([x: [1, %pi, z - y]], "<>" (splice (x)));
(%o4) <>1, %pi, z - y<>
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function definition}
</div>
</p></dd></dl>
<p><a name="Item_003a-Functions-and-Variables-for-Function-Definition"></a>
</p><hr size="6">
<a name="Functions-and-Variables-for-Function-Definition"></a>
<a name="SEC199"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC198" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="maxima_37.html#SEC200" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC193" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC193" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_37.html#SEC200" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section"> 36.4 Functions and Variables for Function Definition </h2>
<p><a name="apply"></a>
<a name="Item_003a-apply"></a>
</p><dl>
<dt><u>Function:</u> <b>apply</b><i> (<var>F</var>, [<var>x_1</var>, …, <var>x_n</var>])</i>
<a name="IDX1515"></a>
</dt>
<dd><p>Constructs and evaluates an expression <code><var>F</var>(<var>arg_1</var>, ...,
<var>arg_n</var>)</code>.
</p>
<p><code>apply</code> does not attempt to distinguish array functions from ordinary
functions; when <var>F</var> is the name of an array function, <code>apply</code> evaluates
<code><var>F</var>(...)</code> (that is, a function call with parentheses instead of square
brackets). <code>arrayapply</code> evaluates a function call with square brackets in
this case.
</p>
<p>Examples:
</p>
<p><code>apply</code> evaluates its arguments.
In this example, <code>min</code> is applied to the value of <code>L</code>.
</p>
<pre class="example">(%i1) L : [1, 5, -10.2, 4, 3];
(%o1) [1, 5, - 10.2, 4, 3]
(%i2) apply (min, L);
(%o2) - 10.2
</pre>
<p><code>apply</code> evaluates arguments, even if the function <var>F</var> quotes them.
</p>
<pre class="example">(%i1) F (x) := x / 1729;
x
(%o1) F(x) := ----
1729
(%i2) fname : F;
(%o2) F
(%i3) dispfun (F);
x
(%t3) F(x) := ----
1729
(%o3) [%t3]
(%i4) dispfun (fname);
fname is not the name of a user function.
-- an error. Quitting. To debug this try debugmode(true);
(%i5) apply (dispfun, [fname]);
x
(%t5) F(x) := ----
1729
(%o5) [%t5]
</pre>
<p><code>apply</code> evaluates the function name <var>F</var>.
Single quote <code>'</code> defeats evaluation.
<code>demoivre</code> is the name of a global variable and also a function.
</p>
<pre class="example">(%i1) demoivre;
(%o1) false
(%i2) demoivre (exp (%i * x));
(%o2) %i sin(x) + cos(x)
(%i3) apply (demoivre, [exp (%i * x)]);
demoivre evaluates to false
Improper name or value in functional position.
-- an error. Quitting. To debug this try debugmode(true);
(%i4) apply ('demoivre, [exp (%i * x)]);
(%o4) %i sin(x) + cos(x)
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function application}
</div>
</p></dd></dl>
<p><a name="block"></a>
<a name="Item_003a-block"></a>
</p><dl>
<dt><u>Function:</u> <b>block</b><i> ([<var>v_1</var>, …, <var>v_m</var>], <var>expr_1</var>, …, <var>expr_n</var>)</i>
<a name="IDX1516"></a>
</dt>
<dt><u>Function:</u> <b>block</b><i> (<var>expr_1</var>, …, <var>expr_n</var>)</i>
<a name="IDX1517"></a>
</dt>
<dd><p><code>block</code> evaluates <var>expr_1</var>, …, <var>expr_n</var> in sequence and
returns the value of the last expression evaluated. The sequence can be
modified by the <code>go</code>, <code>throw</code>, and <code>return</code> functions. The last
expression is <var>expr_n</var> unless <code>return</code> or an expression containing
<code>throw</code> is evaluated.
Some variables <var>v_1</var>, …, <var>v_m</var> can be declared local to the block;
these are distinguished from global variables of the same names. If no
variables are declared local then the list may be omitted. Within the block,
any variable other than <var>v_1</var>, …, <var>v_m</var> is a global variable.
</p>
<p><code>block</code> saves the current values of the variables <var>v_1</var>, …,
<var>v_m</var> (if any) upon entry to the block, then unbinds the variables so that
they evaluate to themselves. The local variables may be bound to arbitrary
values within the block but when the block is exited the saved values are
restored, and the values assigned within the block are lost.
</p>
<p>The declaration <code>local(<var>v_1</var>, ..., <var>v_m</var>)</code> within <code>block</code>
saves the properties associated with the symbols <var>v_1</var>, …, <var>v_m</var>,
removes any properties before evaluating other expressions, and restores any
saved properties on exit from the block. Some declarations are implemented as
properties of a symbol, including <code>:=</code>, <code>array</code>, <code>dependencies</code>,
<code>atvalue</code>, <code>matchdeclare</code>, <code>atomgrad</code>, <code>constant</code>,
<code>nonscalar</code>, <code>assume</code>, and some others. The effect of <code>local</code>
is to make such declarations effective only within the block; otherwise
declarations within a block are actually global declarations.
</p>
<p><code>block</code> may appear within another <code>block</code>.
Local variables are established each time a new <code>block</code> is evaluated.
Local variables appear to be global to any enclosed blocks.
If a variable is non-local in a block,
its value is the value most recently assigned by an enclosing block, if any,
otherwise, it is the value of the variable in the global environment.
This policy may coincide with the usual understanding of "dynamic scope".
</p>
<p>The value of the block is the value of the last statement or the
value of the argument to the function <code>return</code> which may be used to exit
explicitly from the block. The function <code>go</code> may be used to transfer
control to the statement of the block that is tagged with the argument
to <code>go</code>. To tag a statement, precede it by an atomic argument as
another statement in the block. For example:
<code>block ([x], x:1, loop, x: x+1, ..., go(loop), ...)</code>. The argument to
<code>go</code> must be the name of a tag appearing within the block. One cannot use
<code>go</code> to transfer to a tag in a block other than the one containing the
<code>go</code>.
</p>
<p>Blocks typically appear on the right side of a function definition
but can be used in other places as well.
</p>
<div class=categorybox>
·
<p>@ref{Category: Expressions} ·
@ref{Category: Programming}
</div>
</p></dd></dl>
<p><a name="break"></a>
<a name="Item_003a-break"></a>
</p><dl>
<dt><u>Function:</u> <b>break</b><i> (<var>expr_1</var>, …, <var>expr_n</var>)</i>
<a name="IDX1518"></a>
</dt>
<dd><p>Evaluates and prints <var>expr_1</var>, …, <var>expr_n</var> and then
causes a Maxima break at which point the user can examine and change
his environment. Upon typing <code>exit;</code> the computation resumes.
</p>
<div class=categorybox>
·
<p>@ref{Category: Debugging}
</div>
</p></dd></dl>
<p><a name="catch"></a>
<a name="Item_003a-catch"></a>
</p><dl>
<dt><u>Function:</u> <b>catch</b><i> (<var>expr_1</var>, …, <var>expr_n</var>)</i>
<a name="IDX1519"></a>
</dt>
<dd><p>Evaluates <var>expr_1</var>, …, <var>expr_n</var> one by one; if any
leads to the evaluation of an expression of the
form <code>throw (arg)</code>, then the value of the <code>catch</code> is the value of
<code>throw (arg)</code>, and no further expressions are evaluated.
This "non-local return" thus goes through any depth of
nesting to the nearest enclosing <code>catch</code>. If there is no <code>catch</code>
enclosing a <code>throw</code>, an error message is printed.
</p>
<p>If the evaluation of the arguments does not lead to the evaluation of any
<code>throw</code> then the value of <code>catch</code> is the value of <var>expr_n</var>.
</p>
<pre class="example">(%i1) lambda ([x], if x < 0 then throw(x) else f(x))$
(%i2) g(l) := catch (map (''%, l))$
(%i3) g ([1, 2, 3, 7]);
(%o3) [f(1), f(2), f(3), f(7)]
(%i4) g ([1, 2, -3, 7]);
(%o4) - 3
</pre>
<p>The function <code>g</code> returns a list of <code>f</code> of each element of <code>l</code> if
<code>l</code> consists only of non-negative numbers; otherwise, <code>g</code> "catches"
the first negative element of <code>l</code> and "throws" it up.
</p>
<div class=categorybox>
·
<p>@ref{Category: Programming}
</div>
</p></dd></dl>
<p><a name="compfile"></a>
<a name="Item_003a-compfile"></a>
</p><dl>
<dt><u>Function:</u> <b>compfile</b><i> (<var>filename</var>, <var>f_1</var>, …, <var>f_n</var>)</i>
<a name="IDX1520"></a>
</dt>
<dt><u>Function:</u> <b>compfile</b><i> (<var>filename</var>, functions)</i>
<a name="IDX1521"></a>
</dt>
<dt><u>Function:</u> <b>compfile</b><i> (<var>filename</var>, all)</i>
<a name="IDX1522"></a>
</dt>
<dd><p>Translates Maxima functions into Lisp and writes the translated code into the
file <var>filename</var>.
</p>
<p><code>compfile(<var>filename</var>, <var>f_1</var>, ..., <var>f_n</var>)</code> translates the
specified functions. <code>compfile (<var>filename</var>, functions)</code> and
<code>compfile (<var>filename</var>, all)</code> translate all user-defined functions.
</p>
<p>The Lisp translations are not evaluated, nor is the output file processed by
the Lisp compiler.
<code>translate</code> creates and evaluates Lisp translations. <code>compile_file</code>
translates Maxima into Lisp, and then executes the Lisp compiler.
</p>
<p>See also <code>translate</code>, <code>translate_file</code>, and <code>compile_file</code>.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation and compilation}
</div>
</p></dd></dl>
<p><a name="compile"></a>
<a name="Item_003a-compile"></a>
</p><dl>
<dt><u>Function:</u> <b>compile</b><i> (<var>f_1</var>, …, <var>f_n</var>)</i>
<a name="IDX1523"></a>
</dt>
<dt><u>Function:</u> <b>compile</b><i> (functions)</i>
<a name="IDX1524"></a>
</dt>
<dt><u>Function:</u> <b>compile</b><i> (all)</i>
<a name="IDX1525"></a>
</dt>
<dd><p>Translates Maxima functions <var>f_1</var>, …, <var>f_n</var> into Lisp, evaluates
the Lisp translations, and calls the Lisp function <code>COMPILE</code> on each
translated function. <code>compile</code> returns a list of the names of the
compiled functions.
</p>
<p><code>compile (all)</code> or <code>compile (functions)</code> compiles all user-defined
functions.
</p>
<p><code>compile</code> quotes its arguments;
the quote-quote operator <code>''</code> defeats quotation.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation and compilation}
</div>
</p></dd></dl>
<p><a name="define"></a>
<a name="Item_003a-define"></a>
</p><dl>
<dt><u>Function:</u> <b>define</b><i> (<var>f</var>(<var>x_1</var>, …, <var>x_n</var>), <var>expr</var>)</i>
<a name="IDX1526"></a>
</dt>
<dt><u>Function:</u> <b>define</b><i> (<var>f</var>[<var>x_1</var>, …, <var>x_n</var>], <var>expr</var>)</i>
<a name="IDX1527"></a>
</dt>
<dt><u>Function:</u> <b>define</b><i> (funmake (<var>f</var>, [<var>x_1</var>, …, <var>x_n</var>]), <var>expr</var>)</i>
<a name="IDX1528"></a>
</dt>
<dt><u>Function:</u> <b>define</b><i> (arraymake (<var>f</var>, [<var>x_1</var>, …, <var>x_n</var>]), <var>expr</var>)</i>
<a name="IDX1529"></a>
</dt>
<dt><u>Function:</u> <b>define</b><i> (ev (<var>expr_1</var>), <var>expr_2</var>)</i>
<a name="IDX1530"></a>
</dt>
<dd><p>Defines a function named <var>f</var> with arguments <var>x_1</var>, …, <var>x_n</var>
and function body <var>expr</var>. <code>define</code> always evaluates its second
argument (unless explicitly quoted). The function so defined may be an ordinary
Maxima function (with arguments enclosed in parentheses) or an array function
(with arguments enclosed in square brackets).
</p>
<p>When the last or only function argument <var>x_n</var> is a list of one element,
the function defined by <code>define</code> accepts a variable number of arguments.
Actual arguments are assigned one-to-one to formal arguments <var>x_1</var>, …,
<var>x_(n - 1)</var>, and any further actual arguments, if present, are assigned to
<var>x_n</var> as a list.
</p>
<p>When the first argument of <code>define</code> is an expression of the form
<code><var>f</var>(<var>x_1</var>, ..., <var>x_n</var>)</code> or <code><var>f</var>[<var>x_1</var>, ...,
<var>x_n</var>]</code>, the function arguments are evaluated but <var>f</var> is not evaluated,
even if there is already a function or variable by that name.
</p>
<p>When the first argument is an expression with operator <code>funmake</code>,
<code>arraymake</code>, or <code>ev</code>, the first argument is evaluated;
this allows for the function name to be computed, as well as the body.
</p>
<p>All function definitions appear in the same namespace; defining a function
<code>f</code> within another function <code>g</code> does not automatically limit the scope
of <code>f</code> to <code>g</code>. However, <code>local(f)</code> makes the definition of
function <code>f</code> effective only within the block or other compound expression
in which <code>local</code> appears.
</p>
<p>If some formal argument <var>x_k</var> is a quoted symbol (after evaluation), the
function defined by <code>define</code> does not evaluate the corresponding actual
argument. Otherwise all actual arguments are evaluated.
</p>
<p>See also <code>:=</code> and <code>::=</code>.
</p>
<p>Examples:
</p>
<p><code>define</code> always evaluates its second argument (unless explicitly quoted).
</p>
<pre class="example">(%i1) expr : cos(y) - sin(x);
(%o1) cos(y) - sin(x)
(%i2) define (F1 (x, y), expr);
(%o2) F1(x, y) := cos(y) - sin(x)
(%i3) F1 (a, b);
(%o3) cos(b) - sin(a)
(%i4) F2 (x, y) := expr;
(%o4) F2(x, y) := expr
(%i5) F2 (a, b);
(%o5) cos(y) - sin(x)
</pre>
<p>The function defined by <code>define</code> may be an ordinary Maxima function or an
array function.
</p>
<pre class="example">(%i1) define (G1 (x, y), x.y - y.x);
(%o1) G1(x, y) := x . y - y . x
(%i2) define (G2 [x, y], x.y - y.x);
(%o2) G2 := x . y - y . x
x, y
</pre>
<p>When the last or only function argument <var>x_n</var> is a list of one element,
the function defined by <code>define</code> accepts a variable number of arguments.
</p>
<pre class="example">(%i1) define (H ([L]), '(apply ("+", L)));
(%o1) H([L]) := apply("+", L)
(%i2) H (a, b, c);
(%o2) c + b + a
</pre>
<p>When the first argument is an expression with operator <code>funmake</code>,
<code>arraymake</code>, or <code>ev</code>, the first argument is evaluated.
</p>
<pre class="example">(%i1) [F : I, u : x];
(%o1) [I, x]
(%i2) funmake (F, [u]);
(%o2) I(x)
(%i3) define (funmake (F, [u]), cos(u) + 1);
(%o3) I(x) := cos(x) + 1
(%i4) define (arraymake (F, [u]), cos(u) + 1);
(%o4) I := cos(x) + 1
x
(%i5) define (foo (x, y), bar (y, x));
(%o5) foo(x, y) := bar(y, x)
(%i6) define (ev (foo (x, y)), sin(x) - cos(y));
(%o6) bar(y, x) := sin(x) - cos(y)
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function definition}
</div>
</p></dd></dl>
<p><a name="define_005fvariable"></a>
<a name="Item_003a-define_005fvariable"></a>
</p><dl>
<dt><u>Function:</u> <b>define_variable</b><i> (<var>name</var>, <var>default_value</var>, <var>mode</var>)</i>
<a name="IDX1531"></a>
</dt>
<dd><p>Introduces a global variable into the Maxima environment.
<code>define_variable</code> is useful in user-written packages, which are often
translated or compiled.
</p>
<p><code>define_variable</code> carries out the following steps:
</p>
<ol>
<li>
<code>mode_declare (<var>name</var>, <var>mode</var>)</code> declares the mode of <var>name</var> to
the translator. See <code>mode_declare</code> for a list of the possible modes.
</li><li>
If the variable is unbound, <var>default_value</var> is assigned to <var>name</var>.
</li><li>
<code>declare (<var>name</var>, special)</code> declares it special.
</li><li>
Associates <var>name</var> with a test function
to ensure that <var>name</var> is only assigned values of the declared mode.
</li></ol>
<p>The <code>value_check</code> property can be assigned to any variable which has been
defined via <code>define_variable</code> with a mode other than <code>any</code>.
The <code>value_check</code> property is a lambda expression or the name of a function
of one variable, which is called when an attempt is made to assign a value to
the variable. The argument of the <code>value_check</code> function is the would-be
assigned value.
</p>
<p><code>define_variable</code> evaluates <code>default_value</code>, and quotes <code>name</code>
and <code>mode</code>. <code>define_variable</code> returns the current value of
<code>name</code>, which is <code>default_value</code> if <code>name</code> was unbound before,
and otherwise it is the previous value of <code>name</code>.
</p>
<p>Examples:
</p>
<p><code>foo</code> is a Boolean variable, with the initial value <code>true</code>.
</p>
<pre class="example">(%i1) define_variable (foo, true, boolean);
(%o1) true
(%i2) foo;
(%o2) true
(%i3) foo: false;
(%o3) false
(%i4) foo: %pi;
Error: foo was declared mode boolean, has value: %pi
-- an error. Quitting. To debug this try debugmode(true);
(%i5) foo;
(%o5) false
</pre>
<p><code>bar</code> is an integer variable, which must be prime.
</p>
<pre class="example">(%i1) define_variable (bar, 2, integer);
(%o1) 2
(%i2) qput (bar, prime_test, value_check);
(%o2) prime_test
(%i3) prime_test (y) := if not primep(y) then
error (y, "is not prime.");
(%o3) prime_test(y) := if not primep(y)
then error(y, "is not prime.")
(%i4) bar: 1439;
(%o4) 1439
(%i5) bar: 1440;
1440 is not prime.
#0: prime_test(y=1440)
-- an error. Quitting. To debug this try debugmode(true);
(%i6) bar;
(%o6) 1439
</pre>
<p><code>baz_quux</code> is a variable which cannot be assigned a value.
The mode <code>any_check</code> is like <code>any</code>, but <code>any_check</code> enables the
<code>value_check</code> mechanism, and <code>any</code> does not.
</p>
<pre class="example">(%i1) define_variable (baz_quux, 'baz_quux, any_check);
(%o1) baz_quux
(%i2) F: lambda ([y], if y # 'baz_quux then
error ("Cannot assign to `baz_quux'."));
(%o2) lambda([y], if y # 'baz_quux
then error(Cannot assign to `baz_quux'.))
(%i3) qput (baz_quux, ''F, value_check);
(%o3) lambda([y], if y # 'baz_quux
then error(Cannot assign to `baz_quux'.))
(%i4) baz_quux: 'baz_quux;
(%o4) baz_quux
(%i5) baz_quux: sqrt(2);
Cannot assign to `baz_quux'.
#0: lambda([y],if y # 'baz_quux then
error("Cannot assign to `baz_quux'."))(y=sqrt(2))
-- an error. Quitting. To debug this try debugmode(true);
(%i6) baz_quux;
(%o6) baz_quux
</pre>
<div class=categorybox>
·
<p>@ref{Category: Translation and compilation}
</div>
</p></dd></dl>
<p><a name="dispfun"></a>
<a name="Item_003a-dispfun"></a>
</p><dl>
<dt><u>Function:</u> <b>dispfun</b><i> (<var>f_1</var>, …, <var>f_n</var>)</i>
<a name="IDX1532"></a>
</dt>
<dt><u>Function:</u> <b>dispfun</b><i> (all)</i>
<a name="IDX1533"></a>
</dt>
<dd><p>Displays the definition of the user-defined functions <var>f_1</var>, …,
<var>f_n</var>. Each argument may be the name of a macro (defined with <code>::=</code>),
an ordinary function (defined with <code>:=</code> or <code>define</code>), an array
function (defined with <code>:=</code> or <code>define</code>, but enclosing arguments in
square brackets <code>[ ]</code>), a subscripted function, (defined with <code>:=</code> or
<code>define</code>, but enclosing some arguments in square brackets and others in
parentheses <code>( )</code>) one of a family of subscripted functions selected by a
particular subscript value, or a subscripted function defined with a constant
subscript.
</p>
<p><code>dispfun (all)</code> displays all user-defined functions as
given by the <code>functions</code>, <code>arrays</code>, and <code>macros</code> lists,
omitting subscripted functions defined with constant subscripts.
</p>
<p><code>dispfun</code> creates an intermediate expression label
(<code>%t1</code>, <code>%t2</code>, etc.)
for each displayed function, and assigns the function definition to the label.
In contrast, <code>fundef</code> returns the function definition.
</p>
<p><code>dispfun</code> quotes its arguments; the quote-quote operator <code>''</code>
defeats quotation. <code>dispfun</code> returns the list of intermediate expression
labels corresponding to the displayed functions.
</p>
<p>Examples:
</p>
<pre class="example">(%i1) m(x, y) ::= x^(-y);
- y
(%o1) m(x, y) ::= x
(%i2) f(x, y) := x^(-y);
- y
(%o2) f(x, y) := x
(%i3) g[x, y] := x^(-y);
- y
(%o3) g := x
x, y
(%i4) h[x](y) := x^(-y);
- y
(%o4) h (y) := x
x
(%i5) i[8](y) := 8^(-y);
- y
(%o5) i (y) := 8
8
(%i6) dispfun (m, f, g, h, h[5], h[10], i[8]);
- y
(%t6) m(x, y) ::= x
- y
(%t7) f(x, y) := x
- y
(%t8) g := x
x, y
- y
(%t9) h (y) := x
x
1
(%t10) h (y) := --
5 y
5
1
(%t11) h (y) := ---
10 y
10
- y
(%t12) i (y) := 8
8
(%o12) [%t6, %t7, %t8, %t9, %t10, %t11, %t12]
(%i12) ''%;
- y - y - y
(%o12) [m(x, y) ::= x , f(x, y) := x , g := x ,
x, y
- y 1 1 - y
h (y) := x , h (y) := --, h (y) := ---, i (y) := 8 ]
x 5 y 10 y 8
5 10
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function definition} ·
@ref{Category: Display functions}
</div>
</p></dd></dl>
<p><a name="fullmap"></a>
<a name="Item_003a-fullmap"></a>
</p><dl>
<dt><u>Function:</u> <b>fullmap</b><i> (<var>f</var>, <var>expr_1</var>, …)</i>
<a name="IDX1534"></a>
</dt>
<dd><p>Similar to <code>map</code>, but <code>fullmap</code> keeps mapping down all subexpressions
until the main operators are no longer the same.
</p>
<p><code>fullmap</code> is used by the Maxima simplifier for certain matrix
manipulations; thus, Maxima sometimes generates an error message concerning
<code>fullmap</code> even though <code>fullmap</code> was not explicitly called by the user.
</p>
<p>Examples:
</p>
<pre class="example">(%i1) a + b * c;
(%o1) b c + a
(%i2) fullmap (g, %);
(%o2) g(b) g(c) + g(a)
(%i3) map (g, %th(2));
(%o3) g(b c) + g(a)
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function application} ·
@ref{Category: Expressions}
</div>
</p></dd></dl>
<p><a name="fullmapl"></a>
<a name="Item_003a-fullmapl"></a>
</p><dl>
<dt><u>Function:</u> <b>fullmapl</b><i> (<var>f</var>, <var>list_1</var>, …)</i>
<a name="IDX1535"></a>
</dt>
<dd><p>Similar to <code>fullmap</code>, but <code>fullmapl</code> only maps onto lists and
matrices.
</p>
<p>Example:
</p>
<pre class="example">(%i1) fullmapl ("+", [3, [4, 5]], [[a, 1], [0, -1.5]]);
(%o1) [[a + 3, 4], [4, 3.5]]
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function application} ·
@ref{Category: Expressions}
</div>
</p></dd></dl>
<p><a name="functions"></a>
<a name="Item_003a-functions"></a>
</p><dl>
<dt><u>System variable:</u> <b>functions</b>
<a name="IDX1536"></a>
</dt>
<dd><p>Default value: <code>[]</code>
</p>
<p><code>functions</code> is the list of ordinary Maxima functions
in the current session.
An ordinary function is a function constructed by
<code>define</code> or <code>:=</code> and called with parentheses <code>()</code>.
A function may be defined at the Maxima prompt
or in a Maxima file loaded by <code>load</code> or <code>batch</code>.
</p>
<p>Array functions (called with square brackets, e.g., <code>F[x]</code>) and subscripted
functions (called with square brackets and parentheses, e.g., <code>F[x](y)</code>)
are listed by the global variable <code>arrays</code>, and not by <code>functions</code>.
</p>
<p>Lisp functions are not kept on any list.
</p>
<p>Examples:
</p>
<pre class="example">(%i1) F_1 (x) := x - 100;
(%o1) F_1(x) := x - 100
(%i2) F_2 (x, y) := x / y;
x
(%o2) F_2(x, y) := -
y
(%i3) define (F_3 (x), sqrt (x));
(%o3) F_3(x) := sqrt(x)
(%i4) G_1 [x] := x - 100;
(%o4) G_1 := x - 100
x
(%i5) G_2 [x, y] := x / y;
x
(%o5) G_2 := -
x, y y
(%i6) define (G_3 [x], sqrt (x));
(%o6) G_3 := sqrt(x)
x
(%i7) H_1 [x] (y) := x^y;
y
(%o7) H_1 (y) := x
x
(%i8) functions;
(%o8) [F_1(x), F_2(x, y), F_3(x)]
(%i9) arrays;
(%o9) [G_1, G_2, G_3, H_1]
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function definition} ·
@ref{Category: Global variables}
</div>
</p></dd></dl>
<p><a name="fundef"></a>
<a name="Item_003a-fundef"></a>
</p><dl>
<dt><u>Function:</u> <b>fundef</b><i> (<var>f</var>)</i>
<a name="IDX1537"></a>
</dt>
<dd><p>Returns the definition of the function <var>f</var>.
</p>
<p>The argument may be the name of a macro (defined with <code>::=</code>), an ordinary
function (defined with <code>:=</code> or <code>define</code>), an array function (defined
with <code>:=</code> or <code>define</code>, but enclosing arguments in square brackets
<code>[ ]</code>), a subscripted function, (defined with <code>:=</code> or <code>define</code>,
but enclosing some arguments in square brackets and others in parentheses
<code>( )</code>) one of a family of subscripted functions selected by a particular
subscript value, or a subscripted function defined with a constant subscript.
</p>
<p><code>fundef</code> quotes its argument;
the quote-quote operator <code>''</code> defeats quotation.
</p>
<p><code>fundef (<var>f</var>)</code> returns the definition of <var>f</var>.
In contrast, <code>dispfun (<var>f</var>)</code> creates an intermediate expression label
and assigns the definition to the label.
</p>
<div class=categorybox>
·
<p>@ref{Category: Function definition}
</div>
</p></dd></dl>
<p><a name="funmake"></a>
<a name="Item_003a-funmake"></a>
</p><dl>
<dt><u>Function:</u> <b>funmake</b><i> (<var>F</var>, [<var>arg_1</var>, …, <var>arg_n</var>])</i>
<a name="IDX1538"></a>
</dt>
<dd><p>Returns an expression <code><var>F</var>(<var>arg_1</var>, ..., <var>arg_n</var>)</code>.
The return value is simplified, but not evaluated,
so the function <var>F</var> is not called, even if it exists.
</p>
<p><code>funmake</code> does not attempt to distinguish array functions from ordinary
functions; when <var>F</var> is the name of an array function,
<code>funmake</code> returns <code><var>F</var>(...)</code>
(that is, a function call with parentheses instead of square brackets).
<code>arraymake</code> returns a function call with square brackets in this case.
</p>
<p><code>funmake</code> evaluates its arguments.
</p>
<p>Examples:
</p>
<p><code>funmake</code> applied to an ordinary Maxima function.
</p>
<pre class="example">(%i1) F (x, y) := y^2 - x^2;
2 2
(%o1) F(x, y) := y - x
(%i2) funmake (F, [a + 1, b + 1]);
(%o2) F(a + 1, b + 1)
(%i3) ''%;
2 2
(%o3) (b + 1) - (a + 1)
</pre>
<p><code>funmake</code> applied to a macro.
</p>
<pre class="example">(%i1) G (x) ::= (x - 1)/2;
x - 1
(%o1) G(x) ::= -----
2
(%i2) funmake (G, [u]);
(%o2) G(u)
(%i3) ''%;
u - 1
(%o3) -----
2
</pre>
<p><code>funmake</code> applied to a subscripted function.
</p>
<pre class="example">(%i1) H [a] (x) := (x - 1)^a;
a
(%o1) H (x) := (x - 1)
a
(%i2) funmake (H [n], [%e]);
n
(%o2) lambda([x], (x - 1) )(%e)
(%i3) ''%;
n
(%o3) (%e - 1)
(%i4) funmake ('(H [n]), [%e]);
(%o4) H (%e)
n
(%i5) ''%;
n
(%o5) (%e - 1)
</pre>
<p><code>funmake</code> applied to a symbol which is not a defined function of any kind.
</p>
<pre class="example">(%i1) funmake (A, [u]);
(%o1) A(u)
(%i2) ''%;
(%o2) A(u)
</pre>
<p><code>funmake</code> evaluates its arguments, but not the return value.
</p>
<pre class="example">(%i1) det(a,b,c) := b^2 -4*a*c;
2
(%o1) det(a, b, c) := b - 4 a c
(%i2) (x : 8, y : 10, z : 12);
(%o2) 12
(%i3) f : det;
(%o3) det
(%i4) funmake (f, [x, y, z]);
(%o4) det(8, 10, 12)
(%i5) ''%;
(%o5) - 284
</pre>
<p>Maxima simplifies <code>funmake</code>'s return value.
</p>
<pre class="example">(%i1) funmake (sin, [%pi / 2]);
(%o1) 1
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function application} ·
@ref{Category: Expressions}
</div>
</p></dd></dl>
<p><a name="lambda"></a>
<a name="Item_003a-lambda"></a>
</p><dl>
<dt><u>Function:</u> <b>lambda</b><i> ([<var>x_1</var>, …, <var>x_m</var>], <var>expr_1</var>, …, <var>expr_n</var>)</i>
<a name="IDX1539"></a>
</dt>
<dt><u>Function:</u> <b>lambda</b><i> ([[<var>L</var>]], <var>expr_1</var>, …, <var>expr_n</var>)</i>
<a name="IDX1540"></a>
</dt>
<dt><u>Function:</u> <b>lambda</b><i> ([<var>x_1</var>, …, <var>x_m</var>, [<var>L</var>]], <var>expr_1</var>, …, <var>expr_n</var>)</i>
<a name="IDX1541"></a>
</dt>
<dd><p>Defines and returns a lambda expression (that is, an anonymous function).
The function may have required arguments <var>x_1</var>, …, <var>x_m</var> and/or
optional arguments <var>L</var>, which appear within the function body as a list.
The return value of the function is <var>expr_n</var>. A lambda expression can be
assigned to a variable and evaluated like an ordinary function. A lambda
expression may appear in some contexts in which a function name is expected.
</p>
<p>When the function is evaluated, unbound local variables <var>x_1</var>, …,
<var>x_m</var> are created. <code>lambda</code> may appear within <code>block</code> or another
<code>lambda</code>; local variables are established each time another <code>block</code> or
<code>lambda</code> is evaluated. Local variables appear to be global to any enclosed
<code>block</code> or <code>lambda</code>. If a variable is not local, its value is the
value most recently assigned in an enclosing <code>block</code> or <code>lambda</code>, if
any, otherwise, it is the value of the variable in the global environment.
This policy may coincide with the usual understanding of "dynamic scope".
</p>
<p>After local variables are established, <var>expr_1</var> through <var>expr_n</var> are
evaluated in turn. The special variable <code>%%</code>, representing the value of
the preceding expression, is recognized. <code>throw</code> and <code>catch</code> may also
appear in the list of expressions.
</p>
<p><code>return</code> cannot appear in a lambda expression unless enclosed by
<code>block</code>, in which case <code>return</code> defines the return value of the block
and not of the lambda expression, unless the block happens to be <var>expr_n</var>.
Likewise, <code>go</code> cannot appear in a lambda expression unless enclosed by
<code>block</code>.
</p>
<p><code>lambda</code> quotes its arguments;
the quote-quote operator <code>''</code> defeats quotation.
</p>
<p>Examples:
</p>
<ul>
<li>
A lambda expression can be assigned to a variable and evaluated like an ordinary
function.
</li></ul>
<pre class="example">(%i1) f: lambda ([x], x^2);
2
(%o1) lambda([x], x )
(%i2) f(a);
2
(%o2) a
</pre><ul>
<li>
A lambda expression may appear in contexts in which a function evaluation is expected.
</li></ul>
<pre class="example">(%i3) lambda ([x], x^2) (a);
2
(%o3) a
(%i4) apply (lambda ([x], x^2), [a]);
2
(%o4) a
(%i5) map (lambda ([x], x^2), [a, b, c, d, e]);
2 2 2 2 2
(%o5) [a , b , c , d , e ]
</pre><ul>
<li>
Argument variables are local variables.
Other variables appear to be global variables.
Global variables are evaluated at the time the lambda expression is evaluated,
unless some special evaluation is forced by some means, such as <code>''</code>.
</li></ul>
<pre class="example">(%i6) a: %pi$
(%i7) b: %e$
(%i8) g: lambda ([a], a*b);
(%o8) lambda([a], a b)
(%i9) b: %gamma$
(%i10) g(1/2);
%gamma
(%o10) ------
2
(%i11) g2: lambda ([a], a*''b);
(%o11) lambda([a], a %gamma)
(%i12) b: %e$
(%i13) g2(1/2);
%gamma
(%o13) ------
2
</pre><ul>
<li>
Lambda expressions may be nested. Local variables within the outer lambda
expression appear to be global to the inner expression unless masked by local
variables of the same names.
</li></ul>
<pre class="example">(%i14) h: lambda ([a, b], h2: lambda ([a], a*b), h2(1/2));
1
(%o14) lambda([a, b], h2 : lambda([a], a b), h2(-))
2
(%i15) h(%pi, %gamma);
%gamma
(%o15) ------
2
</pre><ul>
<li>
Since <code>lambda</code> quotes its arguments, lambda expression <code>i</code> below does
not define a "multiply by <code>a</code>" function. Such a function can be defined
via <code>buildq</code>, as in lambda expression <code>i2</code> below.
</li></ul>
<pre class="example">(%i16) i: lambda ([a], lambda ([x], a*x));
(%o16) lambda([a], lambda([x], a x))
(%i17) i(1/2);
(%o17) lambda([x], a x)
(%i18) i2: lambda([a], buildq([a: a], lambda([x], a*x)));
(%o18) lambda([a], buildq([a : a], lambda([x], a x)))
(%i19) i2(1/2);
x
(%o19) lambda([x], -)
2
(%i20) i2(1/2)(%pi);
%pi
(%o20) ---
2
</pre><ul>
<li>
A lambda expression may take a variable number of arguments,
which are indicated by <code>[<var>L</var>]</code> as the sole or final argument.
The arguments appear within the function body as a list.
</li></ul>
<pre class="example">(%i1) f : lambda ([aa, bb, [cc]], aa * cc + bb);
(%o1) lambda([aa, bb, [cc]], aa cc + bb)
(%i2) f (foo, %i, 17, 29, 256);
(%o2) [17 foo + %i, 29 foo + %i, 256 foo + %i]
(%i3) g : lambda ([[aa]], apply ("+", aa));
(%o3) lambda([[aa]], apply(+, aa))
(%i4) g (17, 29, x, y, z, %e);
(%o4) z + y + x + %e + 46
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function definition}
</div>
</p></dd></dl>
<p><a name="local"></a>
<a name="Item_003a-local"></a>
</p><dl>
<dt><u>Function:</u> <b>local</b><i> (<var>v_1</var>, …, <var>v_n</var>)</i>
<a name="IDX1542"></a>
</dt>
<dd><p>Saves the properties associated with the symbols <var>v_1</var>, …, <var>v_n</var>,
removes any properties before evaluating other expressions,
and restores any saved properties on exit
from the block or other compound expression in which <code>local</code> appears.
</p>
<p>Some declarations are implemented as properties of a symbol, including
<code>:=</code>, <code>array</code>, <code>dependencies</code>, <code>atvalue</code>,
<code>matchdeclare</code>, <code>atomgrad</code>, <code>constant</code>, <code>nonscalar</code>,
<code>assume</code>, and some others. The effect of <code>local</code> is to make such
declarations effective only within the block or other compound expression in
which <code>local</code> appears; otherwise such declarations are global declarations.
</p>
<p><code>local</code> can only appear in <code>block</code>
or in the body of a function definition or <code>lambda</code> expression,
and only one occurrence is permitted in each.
</p>
<p><code>local</code> quotes its arguments.
<code>local</code> returns <code>done</code>.
</p>
<p>Example:
</p>
<p>A local function definition.
</p>
<pre class="example">(%i1) foo (x) := 1 - x;
(%o1) foo(x) := 1 - x
(%i2) foo (100);
(%o2) - 99
(%i3) block (local (foo), foo (x) := 2 * x, foo (100));
(%o3) 200
(%i4) foo (100);
(%o4) - 99
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function definition} ·
@ref{Category: Programming}
</div>
</p></dd></dl>
<p><a name="macroexpansion"></a>
<a name="Item_003a-macroexpansion"></a>
</p><dl>
<dt><u>Option variable:</u> <b>macroexpansion</b>
<a name="IDX1543"></a>
</dt>
<dd><p>Default value: <code>false</code>
</p>
<p><code>macroexpansion</code> controls whether the expansion (that is, the return value)
of a macro function is substituted for the macro function call.
A substitution may speed up subsequent expression evaluations,
at the cost of storing the expansion.
</p>
<dl compact="compact">
<dt> <code>false</code></dt>
<dd><p>The expansion of a macro function is not substituted for the macro function call.
</p></dd>
<dt> <code>expand</code></dt>
<dd><p>The first time a macro function call is evaluated,
the expansion is stored.
The expansion is not recomputed on subsequent calls;
any side effects (such as <code>print</code> or assignment to global variables) happen
only when the macro function call is first evaluated.
Expansion in an expression does not affect other expressions
which have the same macro function call.
</p></dd>
<dt> <code>displace</code></dt>
<dd><p>The first time a macro function call is evaluated,
the expansion is substituted for the call,
thus modifying the expression from which the macro function was called.
The expansion is not recomputed on subsequent calls;
any side effects happen only when the macro function call is first evaluated.
Expansion in an expression does not affect other expressions
which have the same macro function call.
</p></dd>
</dl>
<p>Examples
</p>
<p>When <code>macroexpansion</code> is <code>false</code>,
a macro function is called every time the calling expression is evaluated,
and the calling expression is not modified.
</p>
<pre class="example">(%i1) f (x) := h (x) / g (x);
h(x)
(%o1) f(x) := ----
g(x)
(%i2) g (x) ::= block (print ("x + 99 is equal to", x),
return (x + 99));
(%o2) g(x) ::= block(print("x + 99 is equal to", x),
return(x + 99))
(%i3) h (x) ::= block (print ("x - 99 is equal to", x),
return (x - 99));
(%o3) h(x) ::= block(print("x - 99 is equal to", x),
return(x - 99))
(%i4) macroexpansion: false;
(%o4) false
(%i5) f (a * b);
x - 99 is equal to x
x + 99 is equal to x
a b - 99
(%o5) --------
a b + 99
(%i6) dispfun (f);
h(x)
(%t6) f(x) := ----
g(x)
(%o6) done
(%i7) f (a * b);
x - 99 is equal to x
x + 99 is equal to x
a b - 99
(%o7) --------
a b + 99
</pre>
<p>When <code>macroexpansion</code> is <code>expand</code>,
a macro function is called once,
and the calling expression is not modified.
</p>
<pre class="example">(%i1) f (x) := h (x) / g (x);
h(x)
(%o1) f(x) := ----
g(x)
(%i2) g (x) ::= block (print ("x + 99 is equal to", x),
return (x + 99));
(%o2) g(x) ::= block(print("x + 99 is equal to", x),
return(x + 99))
(%i3) h (x) ::= block (print ("x - 99 is equal to", x),
return (x - 99));
(%o3) h(x) ::= block(print("x - 99 is equal to", x),
return(x - 99))
(%i4) macroexpansion: expand;
(%o4) expand
(%i5) f (a * b);
x - 99 is equal to x
x + 99 is equal to x
a b - 99
(%o5) --------
a b + 99
(%i6) dispfun (f);
h(x)
(%t6) f(x) := ----
g(x)
(%o6) done
(%i7) f (a * b);
a b - 99
(%o7) --------
a b + 99
</pre>
<p>When <code>macroexpansion</code> is <code>expand</code>,
a macro function is called once,
and the calling expression is modified.
</p>
<pre class="example">(%i1) f (x) := h (x) / g (x);
h(x)
(%o1) f(x) := ----
g(x)
(%i2) g (x) ::= block (print ("x + 99 is equal to", x),
return (x + 99));
(%o2) g(x) ::= block(print("x + 99 is equal to", x),
return(x + 99))
(%i3) h (x) ::= block (print ("x - 99 is equal to", x),
return (x - 99));
(%o3) h(x) ::= block(print("x - 99 is equal to", x),
return(x - 99))
(%i4) macroexpansion: displace;
(%o4) displace
(%i5) f (a * b);
x - 99 is equal to x
x + 99 is equal to x
a b - 99
(%o5) --------
a b + 99
(%i6) dispfun (f);
x - 99
(%t6) f(x) := ------
x + 99
(%o6) done
(%i7) f (a * b);
a b - 99
(%o7) --------
a b + 99
</pre>
<div class=categorybox>
·
<p>@ref{Category: Function application} ·
@ref{Category: Global flags}
</div>
</p></dd></dl>
<p><a name="mode_005fcheckp"></a>
<a name="Item_003a-mode_005fcheckp"></a>
</p><dl>
<dt><u>Option variable:</u> <b>mode_checkp</b>
<a name="IDX1544"></a>
</dt>
<dd><p>Default value: <code>true</code>
</p>
<p>When <code>mode_checkp</code> is <code>true</code>, <code>mode_declare</code> checks the modes
of bound variables.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="mode_005fcheck_005ferrorp"></a>
<a name="Item_003a-mode_005fcheck_005ferrorp"></a>
</p><dl>
<dt><u>Option variable:</u> <b>mode_check_errorp</b>
<a name="IDX1545"></a>
</dt>
<dd><p>Default value: <code>false</code>
</p>
<p>When <code>mode_check_errorp</code> is <code>true</code>, <code>mode_declare</code> calls
error.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="mode_005fcheck_005fwarnp"></a>
<a name="Item_003a-mode_005fcheck_005fwarnp"></a>
</p><dl>
<dt><u>Option variable:</u> <b>mode_check_warnp</b>
<a name="IDX1546"></a>
</dt>
<dd><p>Default value: <code>true</code>
</p>
<p>When <code>mode_check_warnp</code> is <code>true</code>, mode errors are
described.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="mode_005fdeclare"></a>
<a name="Item_003a-mode_005fdeclare"></a>
</p><dl>
<dt><u>Function:</u> <b>mode_declare</b><i> (<var>y_1</var>, <var>mode_1</var>, …, <var>y_n</var>, <var>mode_n</var>)</i>
<a name="IDX1547"></a>
</dt>
<dd><p><code>mode_declare</code> is used to declare the modes of variables and functions for
subsequent translation or compilation of functions. <code>mode_declare</code> is
typically placed at the beginning of a function definition, at the beginning of
a Maxima script, or executed at the interactive prompt.
</p>
<p>The arguments of <code>mode_declare</code> are pairs consisting of a variable and a
mode which is one of <code>boolean</code>, <code>fixnum</code>, <code>number</code>,
<code>rational</code>, or <code>float</code>. Each variable may also be a list of variables
all of which are declared to have the same mode.
</p>
<p>If a variable is an array, and if every element of the array which is
referenced has a value then <code>array (yi, complete, dim1, dim2, ...)</code>
rather than
</p><pre class="example">array(yi, dim1, dim2, ...)
</pre><p>should be used when first declaring the bounds of the array.
If all the elements of the array are of mode <code>fixnum</code> (<code>float</code>), use
<code>fixnum</code> (<code>float</code>) instead of <code>complete</code>.
Also if every element of the array is of the same mode, say <code>m</code>, then
</p>
<pre class="example">mode_declare (completearray (yi), m))
</pre>
<p>should be used for efficient translation.
</p>
<p>Numeric code using arrays might run faster
by declaring the expected size of the array, as in:
</p>
<pre class="example">mode_declare (completearray (a [10, 10]), float)
</pre>
<p>for a floating point number array which is 10 x 10.
</p>
<p>One may declare the mode of the result of a function by using
<code>function (f_1, f_2, ...)</code> as an argument; here <code>f_1</code>, <code>f_2</code>,
… are the names of functions. For example the expression,
</p>
<pre class="example">mode_declare ([function (f_1, f_2, ...)], fixnum)
</pre>
<p>declares that the values returned by <code>f_1</code>, <code>f_2</code>, … are
single-word integers.
</p>
<p><code>modedeclare</code> is a synonym for <code>mode_declare</code>.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation and compilation}
</div>
</p></dd></dl>
<p><a name="mode_005fidentity"></a>
<a name="Item_003a-mode_005fidentity"></a>
</p><dl>
<dt><u>Function:</u> <b>mode_identity</b><i> (<var>arg_1</var>, <var>arg_2</var>)</i>
<a name="IDX1548"></a>
</dt>
<dd><p>A special form used with <code>mode_declare</code> and <code>macros</code> to declare, e.g.,
a list of lists of flonums, or other compound data object. The first argument
to <code>mode_identity</code> is a primitive value mode name as given to
<code>mode_declare</code> (i.e., one of <code>float</code>, <code>fixnum</code>, <code>number</code>,
<code>list</code>, or <code>any</code>), and the second argument is an expression which is
evaluated and returned as the value of <code>mode_identity</code>. However, if the
return value is not allowed by the mode declared in the first
argument, an error or warning is signalled. The important thing is
that the mode of the expression as determined by the Maxima to Lisp
translator, will be that given as the first argument, independent of
anything that goes on in the second argument.
E.g., <code>x: 3.3; mode_identity (fixnum, x);</code> yields an error.
<code>mode_identity (flonum, x)</code> returns 3.3 .
This has a number of uses, e.g., if you knew that <code>first (l)</code> returned a
number then you might write <code>mode_identity (number, first (l))</code>. However,
a more efficient way to do it would be to define a new primitive,
</p>
<pre class="example">firstnumb (x) ::= buildq ([x], mode_identity (number, x));
</pre>
<p>and use <code>firstnumb</code>
every time you take the first of a list of numbers.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation and compilation}
</div>
</p></dd></dl>
<p><a name="remfunction"></a>
<a name="Item_003a-remfunction"></a>
</p><dl>
<dt><u>Function:</u> <b>remfunction</b><i> (<var>f_1</var>, …, <var>f_n</var>)</i>
<a name="IDX1549"></a>
</dt>
<dt><u>Function:</u> <b>remfunction</b><i> (all)</i>
<a name="IDX1550"></a>
</dt>
<dd><p>Unbinds the function definitions of the symbols <var>f_1</var>, …, <var>f_n</var>.
The arguments may be the names of ordinary functions (created by <code><a href="maxima_7.html#g_t_003a_003d">:=</a></code> or
<code><a href="#define">define</a></code>) or macro functions (created by <code><a href="maxima_7.html#g_t_003a_003a_003d">::=</a></code>).
</p>
<p><code>remfunction (all)</code> unbinds all function definitions.
</p>
<p><code>remfunction</code> quotes its arguments.
</p>
<p><code>remfunction</code> returns a list of the symbols for which the function
definition was unbound. <code>false</code> is returned in place of any symbol for
which there is no function definition.
</p>
<p><code>remfunction</code> does not apply to array functions or subscripted functions.
<code><a href="maxima_5.html#remarray">remarray</a></code> applies to those types of functions.
</p>
<div class=categorybox>
·
<p>@ref{Category: Function definition}
</div>
</p></dd></dl>
<p><a name="savedef"></a>
<a name="Item_003a-savedef"></a>
</p><dl>
<dt><u>Option variable:</u> <b>savedef</b>
<a name="IDX1551"></a>
</dt>
<dd><p>Default value: <code>true</code>
</p>
<p>When <code>savedef</code> is <code>true</code>, the Maxima version of a user function is
preserved when the function is translated. This permits the definition to be
displayed by <code>dispfun</code> and allows the function to be edited.
</p>
<p>When <code>savedef</code> is <code>false</code>, the names of translated functions are
removed from the <code>functions</code> list.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="transcompile"></a>
<a name="Item_003a-transcompile"></a>
</p><dl>
<dt><u>Option variable:</u> <b>transcompile</b>
<a name="IDX1552"></a>
</dt>
<dd><p>Default value: <code>true</code>
</p>
<p>When <code>transcompile</code> is <code>true</code>, <code>translate</code> and
<code>translate_file</code> generate declarations to make the translated code more
suitable for compilation.
</p>
<p><code>compfile</code> sets <code>transcompile: true</code> for the duration.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="translate"></a>
<a name="Item_003a-translate"></a>
</p><dl>
<dt><u>Function:</u> <b>translate</b><i> (<var>f_1</var>, …, <var>f_n</var>)</i>
<a name="IDX1553"></a>
</dt>
<dt><u>Function:</u> <b>translate</b><i> (functions)</i>
<a name="IDX1554"></a>
</dt>
<dt><u>Function:</u> <b>translate</b><i> (all)</i>
<a name="IDX1555"></a>
</dt>
<dd><p>Translates the user-defined functions <var>f_1</var>, …, <var>f_n</var> from the
Maxima language into Lisp and evaluates the Lisp translations.
Typically the translated functions run faster than the originals.
</p>
<p><code>translate (all)</code> or <code>translate (functions)</code> translates all
user-defined functions.
</p>
<p>Functions to be translated should include a call to <code>mode_declare</code> at the
beginning when possible in order to produce more efficient code. For example:
</p>
<pre class="example">f (x_1, x_2, ...) := block ([v_1, v_2, ...],
mode_declare (v_1, mode_1, v_2, mode_2, ...), ...)
</pre>
<p>where the <var>x_1</var>, <var>x_2</var>, … are the parameters to the function and
the <var>v_1</var>, <var>v_2</var>, … are the local variables.
</p>
<p>The names of translated functions are removed from the <code>functions</code> list
if <code>savedef</code> is <code>false</code> (see below) and are added to the <code>props</code>
lists.
</p>
<p>Functions should not be translated unless they are fully debugged.
</p>
<p>Expressions are assumed simplified; if they are not, correct but non-optimal
code gets generated. Thus, the user should not set the <code>simp</code> switch to
<code>false</code> which inhibits simplification of the expressions to be translated.
</p>
<p>The switch <code>translate</code>, if <code>true</code>, causes automatic
translation of a user's function to Lisp.
</p>
<p>Note that translated
functions may not run identically to the way they did before
translation as certain incompatabilities may exist between the Lisp
and Maxima versions. Principally, the <code>rat</code> function with more than
one argument and the <code>ratvars</code> function should not be used if any
variables are <code>mode_declare</code>'d canonical rational expressions (CRE).
Also the <code>prederror: false</code> setting
will not translate.
</p>
<p><code>savedef</code> - if <code>true</code> will cause the Maxima version of a user
function to remain when the function is <code>translate</code>'d. This permits the
definition to be displayed by <code>dispfun</code> and allows the function to be
edited.
</p>
<p><code>transrun</code> - if <code>false</code> will cause the interpreted version of all
functions to be run (provided they are still around) rather than the
translated version.
</p>
<p>The result returned by <code>translate</code> is a list of the names of the
functions translated.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation and compilation}
</div>
</p></dd></dl>
<p><a name="translate_005ffile"></a>
<a name="Item_003a-translate_005ffile"></a>
</p><dl>
<dt><u>Function:</u> <b>translate_file</b><i> (<var>maxima_filename</var>)</i>
<a name="IDX1556"></a>
</dt>
<dt><u>Function:</u> <b>translate_file</b><i> (<var>maxima_filename</var>, <var>lisp_filename</var>)</i>
<a name="IDX1557"></a>
</dt>
<dd><p>Translates a file of Maxima code into a file of Lisp code.
<code>translate_file</code> returns a list of three filenames:
the name of the Maxima file, the name of the Lisp file, and the name of file
containing additional information about the translation.
<code>translate_file</code> evaluates its arguments.
</p>
<p><code>translate_file ("foo.mac"); load("foo.LISP")</code> is the same as the command
<code>batch ("foo.mac")</code> except for certain restrictions, the use of
<code>''</code> and <code>%</code>, for example.
</p>
<p><code>translate_file (<var>maxima_filename</var>)</code> translates a Maxima file
<var>maxima_filename</var> into a similarly-named Lisp file.
For example, <code>foo.mac</code> is translated into <code>foo.LISP</code>.
The Maxima filename may include a directory name or names,
in which case the Lisp output file is written
to the same directory from which the Maxima input comes.
</p>
<p><code>translate_file (<var>maxima_filename</var>, <var>lisp_filename</var>)</code> translates
a Maxima file <var>maxima_filename</var> into a Lisp file <var>lisp_filename</var>.
<code>translate_file</code> ignores the filename extension, if any, of
<code>lisp_filename</code>; the filename extension of the Lisp output file is always
<code>LISP</code>. The Lisp filename may include a directory name or names,
in which case the Lisp output file is written to the specified directory.
</p>
<p><code>translate_file</code> also writes a file of translator warning
messages of various degrees of severity.
The filename extension of this file is <code>UNLISP</code>.
This file may contain valuable information, though possibly obscure,
for tracking down bugs in translated code.
The <code>UNLISP</code> file is always written
to the same directory from which the Maxima input comes.
</p>
<p><code>translate_file</code> emits Lisp code which causes
some declarations and definitions to take effect as soon
as the Lisp code is compiled.
See <code>compile_file</code> for more on this topic.
</p>
<p>See also
</p><p align="left"><code>tr_array_as_ref</code>,
<code>tr_bound_function_applyp</code>,
<code>tr_exponent</code>,
<code>tr_file_tty_messagesp</code>,
<code>tr_float_can_branch_complex</code>,
<code>tr_function_call_default</code>,
<code>tr_numer</code>,
<code>tr_optimize_max_loop</code>,
<code>tr_semicompile</code>,
<code>tr_state_vars</code>,
<code>tr_warnings_get</code>,
<code>tr_warn_bad_function_calls</code>,
<code>tr_warn_fexpr</code>,
<code>tr_warn_meval</code>,
<code>tr_warn_mode</code>,
<code>tr_warn_undeclared</code>,
and <code>tr_warn_undefined_variable</code>.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation and compilation}
</div>
</p></dd></dl>
<p><a name="transrun"></a>
<a name="Item_003a-transrun"></a>
</p><dl>
<dt><u>Option variable:</u> <b>transrun</b>
<a name="IDX1558"></a>
</dt>
<dd><p>Default value: <code>true</code>
</p>
<p>When <code>transrun</code> is <code>false</code> will cause the interpreted
version of all functions to be run (provided they are still around)
rather than the translated version.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005farray_005fas_005fref"></a>
<a name="Item_003a-tr_005farray_005fas_005fref"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_array_as_ref</b>
<a name="IDX1559"></a>
</dt>
<dd><p>Default value: <code>true</code>
</p>
<p>If <code>translate_fast_arrays</code> is <code>false</code>, array references in Lisp code
emitted by <code>translate_file</code> are affected by <code>tr_array_as_ref</code>.
When <code>tr_array_as_ref</code> is <code>true</code>,
array names are evaluated,
otherwise array names appear as literal symbols in translated code.
</p>
<p><code>tr_array_as_ref</code> has no effect if <code>translate_fast_arrays</code> is
<code>true</code>.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005fbound_005ffunction_005fapplyp"></a>
<a name="Item_003a-tr_005fbound_005ffunction_005fapplyp"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_bound_function_applyp</b>
<a name="IDX1560"></a>
</dt>
<dd><p>Default value: <code>true</code>
</p>
<p>When <code>tr_bound_function_applyp</code> is <code>true</code>, Maxima gives a warning if a
bound variable (such as a function argument) is found being used as a function.
<code>tr_bound_function_applyp</code> does not affect the code generated in such
cases.
</p>
<p>For example, an expression such as <code>g (f, x) := f (x+1)</code> will trigger
the warning message.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005ffile_005ftty_005fmessage"></a>
<a name="Item_003a-tr_005ffile_005ftty_005fmessagesp"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_file_tty_messagesp</b>
<a name="IDX1561"></a>
</dt>
<dd><p>Default value: <code>false</code>
</p>
<p>When <code>tr_file_tty_messagesp</code> is <code>true</code>, messages generated by
<code>translate_file</code> during translation of a file are displayed on the console
and inserted into the UNLISP file. When <code>false</code>, messages about
translation of the file are only inserted into the UNLISP file.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005ffloat_005fcan_005fbranch_005fcomplex"></a>
<a name="Item_003a-tr_005ffloat_005fcan_005fbranch_005fcomplex"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_float_can_branch_complex</b>
<a name="IDX1562"></a>
</dt>
<dd><p>Default value: <code>true</code>
</p>
<p>Tells the Maxima-to-Lisp translator to assume that the functions
<code>acos</code>, <code>asin</code>, <code>asec</code>, and <code>acsc</code> can return complex results.
</p>
<p>The ostensible effect of <code>tr_float_can_branch_complex</code> is the following.
However, it appears that this flag has no effect on the translator output.
</p>
<p>When it is <code>true</code> then <code>acos(x)</code> is of mode <code>any</code>
even if <code>x</code> is of mode <code>float</code> (as set by <code>mode_declare</code>).
When <code>false</code> then <code>acos(x)</code> is of mode
<code>float</code> if and only if <code>x</code> is of mode <code>float</code>.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005ffunction_005fcall_005fdefault"></a>
<a name="Item_003a-tr_005ffunction_005fcall_005fdefault"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_function_call_default</b>
<a name="IDX1563"></a>
</dt>
<dd><p>Default value: <code>general</code>
</p>
<p><code>false</code> means give up and call <code>meval</code>, <code>expr</code> means assume Lisp
fixed arg function. <code>general</code>, the default gives code good for
<code>mexprs</code> and <code>mlexprs</code> but not <code>macros</code>. <code>general</code> assures
variable bindings are correct in compiled code. In <code>general</code> mode, when
translating F(X), if F is a bound variable, then it assumes that
<code>apply (f, [x])</code> is meant, and translates a such, with appropriate warning.
There is no need to turn this off. With the default settings, no warning
messages implies full compatibility of translated and compiled code with the
Maxima interpreter.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005fnumer"></a>
<a name="Item_003a-tr_005fnumer"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_numer</b>
<a name="IDX1564"></a>
</dt>
<dd><p>Default value: <code>false</code>
</p>
<p>When <code>tr_numer</code> is <code>true</code>, <code>numer</code> properties are used for
atoms which have them, e.g. <code>%pi</code>.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005foptimize_005fmax_005floop"></a>
<a name="Item_003a-tr_005foptimize_005fmax_005floop"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_optimize_max_loop</b>
<a name="IDX1565"></a>
</dt>
<dd><p>Default value: 100
</p>
<p><code>tr_optimize_max_loop</code> is the maximum number of times the
macro-expansion and optimization pass of the translator will loop in
considering a form. This is to catch macro expansion errors, and
non-terminating optimization properties.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005fsemicompile"></a>
<a name="Item_003a-tr_005fsemicompile"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_semicompile</b>
<a name="IDX1566"></a>
</dt>
<dd><p>Default value: <code>false</code>
</p>
<p>When <code>tr_semicompile</code> is <code>true</code>, <code>translate_file</code> and
<code>compfile</code> output forms which will be macroexpanded but not compiled into
machine code by the Lisp compiler.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005fstate_005fvars"></a>
<a name="Item_003a-tr_005fstate_005fvars"></a>
</p><dl>
<dt><u>System variable:</u> <b>tr_state_vars</b>
<a name="IDX1567"></a>
</dt>
<dd><p>Default value:
</p><pre class="example">[transcompile, tr_semicompile, tr_warn_undeclared, tr_warn_meval,
tr_warn_fexpr, tr_warn_mode, tr_warn_undefined_variable,
tr_function_call_default, tr_array_as_ref,tr_numer]
</pre>
<p>The list of the switches that affect the form of the
translated output.
This information is useful to system people when
trying to debug the translator. By comparing the translated product
to what should have been produced for a given state, it is possible to
track down bugs.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005fwarnings_005fget"></a>
<a name="Item_003a-tr_005fwarnings_005fget"></a>
</p><dl>
<dt><u>Function:</u> <b>tr_warnings_get</b><i> ()</i>
<a name="IDX1568"></a>
</dt>
<dd><p>Prints a list of warnings which have been given by
the translator during the current translation.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation and compilation}
</div>
</p></dd></dl>
<p><a name="Item_003a-tr_005fwarn_005fbad_005ffunction_005fcalls"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_warn_bad_function_calls</b>
<a name="IDX1569"></a>
</dt>
<dd><p>Default value: <code>true</code>
</p>
<p>- Gives a warning when
when function calls are being made which may not be correct due to
improper declarations that were made at translate time.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005fwarn_005ffexpr"></a>
<a name="Item_003a-tr_005fwarn_005ffexpr"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_warn_fexpr</b>
<a name="IDX1570"></a>
</dt>
<dd><p>Default value: <code>compfile</code>
</p>
<p>- Gives a warning if any FEXPRs are
encountered. FEXPRs should not normally be output in translated code,
all legitimate special program forms are translated.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005fwarn_005fmeval"></a>
<a name="Item_003a-tr_005fwarn_005fmeval"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_warn_meval</b>
<a name="IDX1571"></a>
</dt>
<dd><p>Default value: <code>compfile</code>
</p>
<p>- Gives a warning if the function <code>meval</code> gets called. If <code>meval</code> is
called that indicates problems in the translation.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005fwarn_005fmode"></a>
<a name="Item_003a-tr_005fwarn_005fmode"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_warn_mode</b>
<a name="IDX1572"></a>
</dt>
<dd><p>Default value: <code>all</code>
</p>
<p>- Gives a warning when variables are
assigned values inappropriate for their mode.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005fwarn_005fundeclared"></a>
<a name="Item_003a-tr_005fwarn_005fundeclared"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_warn_undeclared</b>
<a name="IDX1573"></a>
</dt>
<dd><p>Default value: <code>compile</code>
</p>
<p>- Determines when to send
warnings about undeclared variables to the TTY.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="tr_005fwarn_005fundefined_005fvariable"></a>
<a name="Item_003a-tr_005fwarn_005fundefined_005fvariable"></a>
</p><dl>
<dt><u>Option variable:</u> <b>tr_warn_undefined_variable</b>
<a name="IDX1574"></a>
</dt>
<dd><p>Default value: <code>all</code>
</p>
<p>- Gives a warning when
undefined global variables are seen.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation flags and variables}
</div>
</p></dd></dl>
<p><a name="compile_005ffile"></a>
<a name="Item_003a-compile_005ffile"></a>
</p><dl>
<dt><u>Function:</u> <b>compile_file</b><i> (<var>filename</var>)</i>
<a name="IDX1575"></a>
</dt>
<dt><u>Function:</u> <b>compile_file</b><i> (<var>filename</var>, <var>compiled_filename</var>)</i>
<a name="IDX1576"></a>
</dt>
<dt><u>Function:</u> <b>compile_file</b><i> (<var>filename</var>, <var>compiled_filename</var>, <var>lisp_filename</var>)</i>
<a name="IDX1577"></a>
</dt>
<dd><p>Translates the Maxima file <var>filename</var> into Lisp, executes the Lisp compiler,
and, if the translation and compilation succeed, loads the compiled code into
Maxima.
</p>
<p><code>compile_file</code> returns a list of the names of four files: the original
Maxima file, the Lisp translation, notes on translation, and the compiled code.
If the compilation fails, the fourth item is <code>false</code>.
</p>
<p>Some declarations and definitions take effect as soon
as the Lisp code is compiled (without loading the compiled code).
These include functions defined with the <code>:=</code> operator,
macros define with the <code>::=</code> operator,
<code>alias</code>, <code>declare</code>,
<code>define_variable</code>, <code>mode_declare</code>,
and
<code>infix</code>, <code>matchfix</code>,
<code>nofix</code>, <code>postfix</code>, <code>prefix</code>,
and <code>compfile</code>.
</p>
<p>Assignments and function calls are not evaluated until the compiled code is
loaded. In particular, within the Maxima file, assignments to the translation
flags (<code>tr_numer</code>, etc.) have no effect on the translation.
</p>
<p><var>filename</var> may not contain <code>:lisp</code> statements.
</p>
<p><code>compile_file</code> evaluates its arguments.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation and compilation}
</div>
</p></dd></dl>
<p><a name="declare_005ftranslated"></a>
<a name="Item_003a-declare_005ftranslated"></a>
</p><dl>
<dt><u>Function:</u> <b>declare_translated</b><i> (<var>f_1</var>, <var>f_2</var>, …)</i>
<a name="IDX1578"></a>
</dt>
<dd><p>When translating a file of Maxima code
to Lisp, it is important for the translator to know which functions it
sees in the file are to be called as translated or compiled functions,
and which ones are just Maxima functions or undefined. Putting this
declaration at the top of the file, lets it know that although a symbol
does which does not yet have a Lisp function value, will have one at
call time. <code>(MFUNCTION-CALL fn arg1 arg2 ...)</code> is generated when
the translator does not know <code>fn</code> is going to be a Lisp function.
</p>
<div class=categorybox>
·
<p>@ref{Category: Translation and compilation}
</div>
</p></dd></dl>
<p><a name="Item_003a-Program-Flow"></a>
</p><hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC193" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="maxima_37.html#SEC200" title="Next chapter"> >> </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima.html#SEC_Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="maxima_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="maxima_82.html#SEC380" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="maxima_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
<font size="-1">
This document was generated by <em>root</em> on <em>January, 10 2014</em> using <a href="http://texi2html.cvshome.org/"><em>texi2html 1.76</em></a>.
</font>
<br>
</p>
</body>
</html>
|