/usr/share/doc/maxima-sage-doc/html/maxima_7.html is in maxima-sage-doc 5.39.0+ds-3.
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 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
<html>
<!-- Created on May, 8 2017 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.39.0 Manual: 7. Operators</title>
<meta name="description" content="Maxima 5.39.0 Manual: 7. Operators">
<meta name="keywords" content="Maxima 5.39.0 Manual: 7. Operators">
<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%;
font-family: "FreeSans", sans-serif}
h1 {font-size: 150%; font-family: "FreeSans", sans-serif}
h2 {font-size: 125%; font-family: "FreeSans", sans-serif}
h3 {font-size: 100%; font-family: "FreeSans", sans-serif}
a[href] {color: rgb(0,0,255); text-decoration: none;}
a[href]:hover {background: rgb(220,220,220);}
div.textbox {border: solid; border-width: thin; 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);}
pre.example {border: 1px solid rgb(180,180,180); padding-top: 1em;
padding-bottom: 1em; padding-left: 1em; padding-right: 1em;
background-color: rgb(238,238,255)}
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)}
img {max-width:80%; max-height: 80%}
-->
</style>
<link rel="icon" href="figures/favicon.ico"/>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Operators"></a>
<a name="SEC36"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="maxima_6.html#SEC35" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC37" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="maxima_6.html#SEC30" 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_8.html#SEC44" 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_89.html#SEC425" 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"> 7. Operators </h1>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#SEC37">7.1 Introduction to operators</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC38">7.2 Arithmetic operators</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC39">7.3 Relational operators</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC40">7.4 Logical operators</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC41">7.5 Operators for Equations</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC42">7.6 Assignment operators</a></td><td> </td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#SEC43">7.7 User defined operators</a></td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<p><a name="Item_003a-Introduction-to-operators"></a>
</p><hr size="6">
<a name="Introduction-to-operators"></a>
<a name="SEC37"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC36" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC38" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC36" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC36" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_8.html#SEC44" 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_89.html#SEC425" 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"> 7.1 Introduction to operators </h2>
<p>It is possible to define new operators with specified precedence, to undefine
existing operators, or to redefine the precedence of existing operators. An
operator may be unary prefix or unary postfix, binary infix, n-ary infix,
matchfix, or nofix. "Matchfix" means a pair of symbols which enclose their
argument or arguments, and "nofix" means an operator which takes no arguments.
As examples of the different types of operators, there are the following.
</p>
<dl compact="compact">
<dt> unary prefix</dt>
<dd><p>negation <code>- a</code>
</p></dd>
<dt> unary postfix</dt>
<dd><p>factorial <code>a!</code>
</p></dd>
<dt> binary infix</dt>
<dd><p>exponentiation <code>a^b</code>
</p></dd>
<dt> n-ary infix</dt>
<dd><p>addition <code>a + b</code>
</p></dd>
<dt> matchfix</dt>
<dd><p>list construction <code>[a, b]</code>
</p></dd>
</dl>
<p>(There are no built-in nofix operators; for an example of such an operator,
see <code>nofix</code>.)
</p>
<p>The mechanism to define a new operator is straightforward. It is only necessary
to declare a function as an operator; the operator function might or might not
be defined.
</p>
<p>An example of user-defined operators is the following. Note that the explicit
function call <code>"dd" (a)</code> is equivalent to <code>dd a</code>, likewise
<code>"<-" (a, b)</code> is equivalent to <code>a <- b</code>. Note also that the functions
<code>"dd"</code> and <code>"<-"</code> are undefined in this example.
</p>
<pre class="example">(%i1) prefix ("dd");
(%o1) dd
(%i2) dd a;
(%o2) dd a
(%i3) "dd" (a);
(%o3) dd a
(%i4) infix ("<-");
(%o4) <-
(%i5) a <- dd b;
(%o5) a <- dd b
(%i6) "<-" (a, "dd" (b));
(%o6) a <- dd b
</pre>
<p>The Maxima functions which define new operators are summarized in this table,
stating the default left and right binding powers (lbp and rbp, respectively).
(Binding power determines operator precedence. However, since left and right
binding powers can differ, binding power is somewhat more complicated than
precedence.) Some of the operation definition functions take additional
arguments; see the function descriptions for details.
</p>
<dl compact="compact">
<dt> <code>prefix</code></dt>
<dd><p>rbp=180
</p></dd>
<dt> <code>postfix</code></dt>
<dd><p>lbp=180
</p></dd>
<dt> <code>infix</code></dt>
<dd><p>lbp=180, rbp=180
</p></dd>
<dt> <code>nary</code></dt>
<dd><p>lbp=180, rbp=180
</p></dd>
<dt> <code>matchfix</code></dt>
<dd><p>(binding power not applicable)
</p></dd>
<dt> <code>nofix</code></dt>
<dd><p>(binding power not applicable)
</p></dd>
</dl>
<p>For comparison, here are some built-in operators and their left and right
binding powers.
</p>
<pre class="example">Operator lbp rbp
: 180 20
:: 180 20
:= 180 20
::= 180 20
! 160
!! 160
^ 140 139
. 130 129
* 120
/ 120 120
+ 100 100
- 100 134
= 80 80
# 80 80
> 80 80
>= 80 80
< 80 80
<= 80 80
not 70
and 65
or 60
, 10
$ -1
; -1
</pre>
<p><code><a href="maxima_11.html#remove">remove</a></code> and <code><a href="maxima_4.html#kill">kill</a></code> remove operator properties from an atom.
<code>remove ("<var>a</var>", op)</code> removes only the operator properties of <var>a</var>.
<code>kill ("<var>a</var>")</code> removes all properties of <var>a</var>, including the
operator properties. Note that the name of the operator must be enclosed in
quotation marks.
</p>
<pre class="example">(%i1) infix ("##");
(%o1) ##
(%i2) "##" (a, b) := a^b;
b
(%o2) a ## b := a
(%i3) 5 ## 3;
(%o3) 125
(%i4) remove ("##", op);
(%o4) done
(%i5) 5 ## 3;
Incorrect syntax: # is not a prefix operator
5 ##
^
(%i5) "##" (5, 3);
(%o5) 125
(%i6) infix ("##");
(%o6) ##
(%i7) 5 ## 3;
(%o7) 125
(%i8) kill ("##");
(%o8) done
(%i9) 5 ## 3;
Incorrect syntax: # is not a prefix operator
5 ##
^
(%i9) "##" (5, 3);
(%o9) ##(5, 3)
</pre>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a> ·
<a href="maxima_105.html#Category_003a-Syntax">Syntax</a>
</div>
</p>
<p><a name="Item_003a-Arithmetic-operators"></a>
</p><hr size="6">
<a name="Arithmetic-operators"></a>
<a name="SEC38"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC37" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC39" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC36" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC36" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_8.html#SEC44" 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_89.html#SEC425" 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"> 7.2 Arithmetic operators </h2>
<p><a name="g_t_002b"></a>
<a name="g_t_002d"></a>
<a name="g_t_002a"></a>
<a name="g_t_002f"></a>
<a name="g_t_005e"></a>
</p>
<p><a name="Item_003a-_002b"></a>
</p><dl>
<dt><u>Operator:</u> <b>+</b>
<a name="IDX219"></a>
</dt>
<dt><u>Operator:</u> <b>-</b>
<a name="IDX220"></a>
</dt>
<dt><u>Operator:</u> <b>*</b>
<a name="IDX221"></a>
</dt>
<dt><u>Operator:</u> <b>/</b>
<a name="IDX222"></a>
</dt>
<dt><u>Operator:</u> <b>^</b>
<a name="IDX223"></a>
</dt>
<dd><p>The symbols <code>+</code> <code>*</code> <code>/</code> and <code>^</code> represent addition,
multiplication, division, and exponentiation, respectively. The names of these
operators are <code>"+"</code> <code>"*"</code> <code>"/"</code> and <code>"^"</code>, which may appear
where the name of a function or operator is required.
</p>
<p>The symbols <code>+</code> and <code>-</code> represent unary addition and negation,
respectively, and the names of these operators are <code>"+"</code> and <code>"-"</code>,
respectively.
</p>
<p>Subtraction <code>a - b</code> is represented within Maxima as addition,
<code>a + (- b)</code>. Expressions such as <code>a + (- b)</code> are displayed as
subtraction. Maxima recognizes <code>"-"</code> only as the name of the unary
negation operator, and not as the name of the binary subtraction operator.
</p>
<p>Division <code>a / b</code> is represented within Maxima as multiplication,
<code>a * b^(- 1)</code>. Expressions such as <code>a * b^(- 1)</code> are displayed as
division. Maxima recognizes <code>"/"</code> as the name of the division operator.
</p>
<p>Addition and multiplication are n-ary, commutative operators.
Division and exponentiation are binary, noncommutative operators.
</p>
<p>Maxima sorts the operands of commutative operators to construct a canonical
representation. For internal storage, the ordering is determined by
<code><a href="maxima_6.html#orderlessp">orderlessp</a></code>. For display, the ordering for addition is determined by
<code><a href="maxima_6.html#ordergreatp">ordergreatp</a></code>, and for multiplication, it is the same as the internal
ordering.
</p>
<p>Arithmetic computations are carried out on literal numbers (integers, rationals,
ordinary floats, and bigfloats). Except for exponentiation, all arithmetic
operations on numbers are simplified to numbers. Exponentiation is simplified
to a number if either operand is an ordinary float or bigfloat or if the result
is an exact integer or rational; otherwise an exponentiation may be simplified
to <code><a href="maxima_10.html#sqrt">sqrt</a></code> or another exponentiation or left unchanged.
</p>
<p>Floating-point contagion applies to arithmetic computations: if any operand is
a bigfloat, the result is a bigfloat; otherwise, if any operand is an ordinary
float, the result is an ordinary float; otherwise, the operands are rationals
or integers and the result is a rational or integer.
</p>
<p>Arithmetic computations are a simplification, not an evaluation.
Thus arithmetic is carried out in quoted (but simplified) expressions.
</p>
<p>Arithmetic operations are applied element-by-element to lists when the global
flag <code><a href="maxima_5.html#listarith">listarith</a></code> is <code>true</code>, and always applied element-by-element to
matrices. When one operand is a list or matrix and another is an operand of
some other type, the other operand is combined with each of the elements of the
list or matrix.
</p>
<p>Examples:
</p>
<p>Addition and multiplication are n-ary, commutative operators.
Maxima sorts the operands to construct a canonical representation.
The names of these operators are <code>"+"</code> and <code>"*"</code>.
</p>
<pre class="example">(%i1) c + g + d + a + b + e + f;
(%o1) g + f + e + d + c + b + a
(%i2) [op (%), args (%)];
(%o2) [+, [g, f, e, d, c, b, a]]
(%i3) c * g * d * a * b * e * f;
(%o3) a b c d e f g
(%i4) [op (%), args (%)];
(%o4) [*, [a, b, c, d, e, f, g]]
(%i5) apply ("+", [a, 8, x, 2, 9, x, x, a]);
(%o5) 3 x + 2 a + 19
(%i6) apply ("*", [a, 8, x, 2, 9, x, x, a]);
2 3
(%o6) 144 a x
</pre>
<p>Division and exponentiation are binary, noncommutative operators.
The names of these operators are <code>"/"</code> and <code>"^"</code>.
</p>
<pre class="example">(%i1) [a / b, a ^ b];
a b
(%o1) [-, a ]
b
(%i2) [map (op, %), map (args, %)];
(%o2) [[/, ^], [[a, b], [a, b]]]
(%i3) [apply ("/", [a, b]), apply ("^", [a, b])];
a b
(%o3) [-, a ]
b
</pre>
<p>Subtraction and division are represented internally
in terms of addition and multiplication, respectively.
</p>
<pre class="example">(%i1) [inpart (a - b, 0), inpart (a - b, 1), inpart (a - b, 2)];
(%o1) [+, a, - b]
(%i2) [inpart (a / b, 0), inpart (a / b, 1), inpart (a / b, 2)];
1
(%o2) [*, a, -]
b
</pre>
<p>Computations are carried out on literal numbers.
Floating-point contagion applies.
</p>
<pre class="example">(%i1) 17 + b - (1/2)*29 + 11^(2/4);
5
(%o1) b + sqrt(11) + -
2
(%i2) [17 + 29, 17 + 29.0, 17 + 29b0];
(%o2) [46, 46.0, 4.6b1]
</pre>
<p>Arithmetic computations are a simplification, not an evaluation.
</p>
<pre class="example">(%i1) simp : false;
(%o1) false
(%i2) '(17 + 29*11/7 - 5^3);
29 11 3
(%o2) 17 + ----- - 5
7
(%i3) simp : true;
(%o3) true
(%i4) '(17 + 29*11/7 - 5^3);
437
(%o4) - ---
7
</pre>
<p>Arithmetic is carried out element-by-element for lists (depending on
<code>listarith</code>) and matrices.
</p>
<pre class="example">(%i1) matrix ([a, x], [h, u]) - matrix ([1, 2], [3, 4]);
[ a - 1 x - 2 ]
(%o1) [ ]
[ h - 3 u - 4 ]
(%i2) 5 * matrix ([a, x], [h, u]);
[ 5 a 5 x ]
(%o2) [ ]
[ 5 h 5 u ]
(%i3) listarith : false;
(%o3) false
(%i4) [a, c, m, t] / [1, 7, 2, 9];
[a, c, m, t]
(%o4) ------------
[1, 7, 2, 9]
(%i5) [a, c, m, t] ^ x;
x
(%o5) [a, c, m, t]
(%i6) listarith : true;
(%o6) true
(%i7) [a, c, m, t] / [1, 7, 2, 9];
c m t
(%o7) [a, -, -, -]
7 2 9
(%i8) [a, c, m, t] ^ x;
x x x x
(%o8) [a , c , m , t ]
</pre>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="g_t_002a_002a"></a>
<a name="Item_003a-_002a_002a"></a>
</p><dl>
<dt><u>Operator:</u> <b>**</b>
<a name="IDX224"></a>
</dt>
<dd><p>Exponentiation operator.
Maxima recognizes <code>**</code> as the same operator as <code><a href="#g_t_005e">^</a></code> in input,
and it is displayed as <code>^</code> in 1-dimensional output,
or by placing the exponent as a superscript in 2-dimensional output.
</p>
<p>The <code><a href="maxima_13.html#fortran">fortran</a></code> function displays the exponentiation operator as <code>**</code>,
whether it was input as <code>**</code> or <code>^</code>.
</p>
<p>Examples:
</p>
<pre class="example">(%i1) is (a**b = a^b);
(%o1) true
(%i2) x**y + x^z;
z y
(%o2) x + x
(%i3) string (x**y + x^z);
(%o3) x^z+x^y
(%i4) fortran (x**y + x^z);
x**z+x**y
(%o4) done
</pre>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="g_t_005e_005e"></a>
<a name="Item_003a-_005e_005e"></a>
</p><dl>
<dt><u>Operator:</u> <b>^^</b>
<a name="IDX225"></a>
</dt>
<dd><p>Noncommutative exponentiation operator.
<code>^^</code> is the exponentiation operator corresponding to noncommutative
multiplication <code>.</code>, just as the ordinary exponentiation operator <code>^</code>
corresponds to commutative multiplication <code>*</code>.
</p>
<p>Noncommutative exponentiation is displayed by <code>^^</code> in 1-dimensional output,
and by placing the exponent as a superscript within angle brackets <code>< ></code>
in 2-dimensional output.
</p>
<p>Examples:
</p>
<pre class="example">(%i1) a . a . b . b . b + a * a * a * b * b;
3 2 <2> <3>
(%o1) a b + a . b
(%i2) string (a . a . b . b . b + a * a * a * b * b);
(%o2) a^3*b^2+a^^2 . b^^3
</pre>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="g_t_002e"></a>
<a name="Item_003a-_002e"></a>
</p><dl>
<dt><u>Operator:</u> <b>.</b>
<a name="IDX226"></a>
</dt>
<dd><p>The dot operator, for matrix (non-commutative) multiplication.
When <code>"."</code> is used in this way, spaces should be left on both sides of
it, e.g. <code>A . B</code> This distinguishes it plainly from a decimal point in
a floating point number.
</p>
<p>See also
<code><a href="maxima_23.html#SEC116">Dot</a></code>,
<code><a href="maxima_23.html#dot0nscsimp">dot0nscsimp</a></code>,
<code><a href="maxima_23.html#dot0simp">dot0simp</a></code>,
<code><a href="maxima_23.html#dot1simp">dot1simp</a></code>,
<code><a href="maxima_23.html#dotassoc">dotassoc</a></code>,
<code><a href="maxima_23.html#dotconstrules">dotconstrules</a></code>,
<code><a href="maxima_23.html#dotdistrib">dotdistrib</a></code>,
<code><a href="maxima_23.html#dotexptsimp">dotexptsimp</a></code>,
<code><a href="maxima_23.html#dotident">dotident</a></code>,
and
<code><a href="maxima_23.html#dotscrules">dotscrules</a></code>.
</p>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="Item_003a-Relational-operators"></a>
</p><hr size="6">
<a name="Relational-operators"></a>
<a name="SEC39"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC38" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC40" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC36" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC36" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_8.html#SEC44" 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_89.html#SEC425" 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"> 7.3 Relational operators </h2>
<p><a name="g_t_003c"></a>
<a name="g_t_003c_003d"></a>
<a name="g_t_003e_003d"></a>
<a name="g_t_003e"></a>
</p>
<p><a name="Item_003a-_003c"></a>
</p><dl>
<dt><u>Operator:</u> <b><</b>
<a name="IDX227"></a>
</dt>
<dt><u>Operator:</u> <b><=</b>
<a name="IDX228"></a>
</dt>
<dt><u>Operator:</u> <b>>=</b>
<a name="IDX229"></a>
</dt>
<dt><u>Operator:</u> <b>></b>
<a name="IDX230"></a>
</dt>
<dd><p>The symbols <code><</code> <code><=</code> <code>>=</code> and <code>></code> represent less than, less
than or equal, greater than or equal, and greater than, respectively. The names
of these operators are <code>"<"</code> <code>"<="</code> <code>">="</code> and <code>">"</code>, which
may appear where the name of a function or operator is required.
</p>
<p>These relational operators are all binary operators; constructs such as
<code>a < b < c</code> are not recognized by Maxima.
</p>
<p>Relational expressions are evaluated to Boolean values by the functions
<code><a href="maxima_11.html#is">is</a></code> and <code><a href="maxima_11.html#maybe">maybe</a></code>, and the programming constructs
<code><a href="maxima_37.html#if">if</a></code>, <code><a href="maxima_37.html#while">while</a></code>, and <code><a href="maxima_37.html#unless">unless</a></code>. Relational expressions
are not otherwise evaluated or simplified to Boolean values, although the
arguments of relational expressions are evaluated (when evaluation is not
otherwise prevented by quotation).
</p>
<p>When a relational expression cannot be evaluated to <code>true</code> or <code>false</code>,
the behavior of <code>is</code> and <code>if</code> are governed by the global flag
<code><a href="maxima_37.html#prederror">prederror</a></code>. When <code>prederror</code> is <code>true</code>, <code>is</code> and
<code>if</code> trigger an error. When <code>prederror</code> is <code>false</code>, <code>is</code>
returns <code>unknown</code>, and <code>if</code> returns a partially-evaluated conditional
expression.
</p>
<p><code>maybe</code> always behaves as if <code>prederror</code> were <code>false</code>, and
<code>while</code> and <code>unless</code> always behave as if <code>prederror</code> were
<code>true</code>.
</p>
<p>Relational operators do not distribute over lists or other aggregates.
</p>
<p>See also <code><a href="#g_t_003d">=</a></code>, <code><a href="#g_t_0023">#</a></code>, <code><a href="maxima_11.html#equal">equal</a></code>, and <code><a href="maxima_11.html#notequal">notequal</a></code>.
</p>
<p>Examples:
</p>
<p>Relational expressions are evaluated to Boolean values by some functions and
programming constructs.
</p>
<pre class="example">(%i1) [x, y, z] : [123, 456, 789];
(%o1) [123, 456, 789]
(%i2) is (x < y);
(%o2) true
(%i3) maybe (y > z);
(%o3) false
(%i4) if x >= z then 1 else 0;
(%o4) 0
(%i5) block ([S], S : 0, for i:1 while i <= 100 do S : S + i,
return (S));
(%o5) 5050
</pre>
<p>Relational expressions are not otherwise evaluated or simplified to Boolean
values, although the arguments of relational expressions are evaluated.
</p>
<pre class="example">(%o1) [123, 456, 789]
(%i2) [x < y, y <= z, z >= y, y > z];
(%o2) [123 < 456, 456 <= 789, 789 >= 456, 456 > 789]
(%i3) map (is, %);
(%o3) [true, true, true, false]
</pre>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="Item_003a-Logical-operators"></a>
</p><hr size="6">
<a name="Logical-operators"></a>
<a name="SEC40"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC39" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC41" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC36" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC36" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_8.html#SEC44" 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_89.html#SEC425" 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"> 7.4 Logical operators </h2>
<p><a name="and"></a>
<a name="Item_003a-and"></a>
</p><dl>
<dt><u>Operator:</u> <b>and</b>
<a name="IDX231"></a>
</dt>
<dd><p>The logical conjunction operator. <code>and</code> is an n-ary infix operator;
its operands are Boolean expressions, and its result is a Boolean value.
</p>
<p><code>and</code> forces evaluation (like <code><a href="maxima_11.html#is">is</a></code>) of one or more operands,
and may force evaluation of all operands.
</p>
<p>Operands are evaluated in the order in which they appear. <code>and</code> evaluates
only as many of its operands as necessary to determine the result. If any
operand is <code>false</code>, the result is <code>false</code> and no further operands are
evaluated.
</p>
<p>The global flag <code><a href="maxima_37.html#prederror">prederror</a></code> governs the behavior of <code>and</code> when an
evaluated operand cannot be determined to be <code>true</code> or <code>false</code>.
<code>and</code> prints an error message when <code>prederror</code> is <code>true</code>.
Otherwise, operands which do not evaluate to <code>true</code> or <code>false</code> are
accepted, and the result is a Boolean expression.
</p>
<p><code>and</code> is not commutative: <code>a and b</code> might not be equal to
<code>b and a</code> due to the treatment of indeterminate operands.
</p>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="not"></a>
<a name="Item_003a-not"></a>
</p><dl>
<dt><u>Operator:</u> <b>not</b>
<a name="IDX232"></a>
</dt>
<dd><p>The logical negation operator. <code>not</code> is a prefix operator;
its operand is a Boolean expression, and its result is a Boolean value.
</p>
<p><code>not</code> forces evaluation (like <code>is</code>) of its operand.
</p>
<p>The global flag <code><a href="maxima_37.html#prederror">prederror</a></code> governs the behavior of <code>not</code> when its
operand cannot be determined to be <code>true</code> or <code>false</code>. <code>not</code>
prints an error message when <code>prederror</code> is <code>true</code>. Otherwise,
operands which do not evaluate to <code>true</code> or <code>false</code> are accepted,
and the result is a Boolean expression.
</p>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="or"></a>
<a name="Item_003a-or"></a>
</p><dl>
<dt><u>Operator:</u> <b>or</b>
<a name="IDX233"></a>
</dt>
<dd><p>The logical disjunction operator. <code>or</code> is an n-ary infix operator;
its operands are Boolean expressions, and its result is a Boolean value.
</p>
<p><code>or</code> forces evaluation (like <code><a href="maxima_11.html#is">is</a></code>) of one or more operands,
and may force evaluation of all operands.
</p>
<p>Operands are evaluated in the order in which they appear. <code>or</code> evaluates
only as many of its operands as necessary to determine the result. If any
operand is <code>true</code>, the result is <code>true</code> and no further operands are
evaluated.
</p>
<p>The global flag <code><a href="maxima_37.html#prederror">prederror</a></code> governs the behavior of <code>or</code> when an
evaluated operand cannot be determined to be <code>true</code> or <code>false</code>.
<code>or</code> prints an error message when <code>prederror</code> is <code>true</code>.
Otherwise, operands which do not evaluate to <code>true</code> or <code>false</code> are
accepted, and the result is a Boolean expression.
</p>
<p><code>or</code> is not commutative: <code>a or b</code> might not be equal to <code>b or a</code>
due to the treatment of indeterminate operands.
</p>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="Item_003a-Operators-for-Equations"></a>
</p><hr size="6">
<a name="Operators-for-Equations"></a>
<a name="SEC41"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC40" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC42" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC36" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC36" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_8.html#SEC44" 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_89.html#SEC425" 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"> 7.5 Operators for Equations </h2>
<p><a name="g_t_0023"></a>
<a name="Item_003a-_0023"></a>
</p><dl>
<dt><u>Operator:</u> <b>#</b>
<a name="IDX234"></a>
</dt>
<dd><p>Represents the negation of syntactic equality <code><a href="#g_t_003d">=</a></code>.
</p>
<p>Note that because of the rules for evaluation of predicate expressions
(in particular because <code>not <var>expr</var></code> causes evaluation of <var>expr</var>),
<code>not <var>a</var> = <var>b</var></code> is equivalent to <code>is(<var>a</var> # <var>b</var>)</code>,
instead of <code><var>a</var> # <var>b</var></code>.
</p>
<p>Examples:
</p>
<pre class="example">(%i1) a = b;
(%o1) a = b
(%i2) is (a = b);
(%o2) false
(%i3) a # b;
(%o3) a # b
(%i4) not a = b;
(%o4) true
(%i5) is (a # b);
(%o5) true
(%i6) is (not a = b);
(%o6) true
</pre>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="g_t_003d"></a>
<a name="Item_003a-_003d"></a>
</p><dl>
<dt><u>Operator:</u> <b>=</b>
<a name="IDX235"></a>
</dt>
<dd><p>The equation operator.
</p>
<p>An expression <code><var>a</var> = <var>b</var></code>, by itself, represents an unevaluated
equation, which might or might not hold. Unevaluated equations may appear as
arguments to <code><a href="maxima_20.html#solve">solve</a></code> and <code><a href="maxima_20.html#algsys">algsys</a></code> or some other functions.
</p>
<p>The function <code><a href="maxima_11.html#is">is</a></code> evaluates <code>=</code> to a Boolean value.
<code>is(<var>a</var> = <var>b</var>)</code> evaluates <code><var>a</var> = <var>b</var></code> to <code>true</code>
when <var>a</var> and <var>b</var> are identical. That is, <var>a</var> and <var>b</var> are atoms
which are identical, or they are not atoms and their operators are identical and
their arguments are identical. Otherwise, <code>is(<var>a</var> = <var>b</var>)</code>
evaluates to <code>false</code>; it never evaluates to <code>unknown</code>. When
<code>is(<var>a</var> = <var>b</var>)</code> is <code>true</code>, <var>a</var> and <var>b</var> are said to be
syntactically equal, in contrast to equivalent expressions, for which
<code>is(equal(<var>a</var>, <var>b</var>))</code> is <code>true</code>. Expressions can be
equivalent and not syntactically equal.
</p>
<p>The negation of <code>=</code> is represented by <code><a href="#g_t_0023">#</a></code>.
As with <code>=</code>, an expression <code><var>a</var> # <var>b</var></code>, by itself, is not
evaluated. <code>is(<var>a</var> # <var>b</var>)</code> evaluates <code><var>a</var> # <var>b</var></code> to
<code>true</code> or <code>false</code>.
</p>
<p>In addition to <code>is</code>, some other operators evaluate <code>=</code> and <code>#</code>
to <code>true</code> or <code>false</code>, namely <code><a href="maxima_37.html#if">if</a></code>, <code><a href="#and">and</a></code>,
<code><a href="#or">or</a></code>, and <code><a href="#not">not</a></code>.
</p>
<p>Note that because of the rules for evaluation of predicate expressions
(in particular because <code>not <var>expr</var></code> causes evaluation of <var>expr</var>),
<code>not <var>a</var> = <var>b</var></code> is equivalent to <code>is(<var>a</var> # <var>b</var>)</code>,
instead of <code><var>a</var> # <var>b</var></code>.
</p>
<p><code><a href="maxima_20.html#rhs">rhs</a></code> and <code><a href="maxima_20.html#lhs">lhs</a></code> return the right-hand and left-hand sides,
respectively, of an equation or inequation.
</p>
<p>See also <code><a href="maxima_11.html#equal">equal</a></code> and <code><a href="maxima_11.html#notequal">notequal</a></code>.
</p>
<p>Examples:
</p>
<p>An expression <code><var>a</var> = <var>b</var></code>, by itself, represents
an unevaluated equation, which might or might not hold.
</p>
<pre class="example">(%i1) eq_1 : a * x - 5 * y = 17;
(%o1) a x - 5 y = 17
(%i2) eq_2 : b * x + 3 * y = 29;
(%o2) 3 y + b x = 29
(%i3) solve ([eq_1, eq_2], [x, y]);
196 29 a - 17 b
(%o3) [[x = ---------, y = -----------]]
5 b + 3 a 5 b + 3 a
(%i4) subst (%, [eq_1, eq_2]);
196 a 5 (29 a - 17 b)
(%o4) [--------- - --------------- = 17,
5 b + 3 a 5 b + 3 a
196 b 3 (29 a - 17 b)
--------- + --------------- = 29]
5 b + 3 a 5 b + 3 a
(%i5) ratsimp (%);
(%o5) [17 = 17, 29 = 29]
</pre>
<p><code>is(<var>a</var> = <var>b</var>)</code> evaluates <code><var>a</var> = <var>b</var></code> to <code>true</code>
when <var>a</var> and <var>b</var> are syntactically equal (that is, identical).
Expressions can be equivalent and not syntactically equal.
</p>
<pre class="example">(%i1) a : (x + 1) * (x - 1);
(%o1) (x - 1) (x + 1)
(%i2) b : x^2 - 1;
2
(%o2) x - 1
(%i3) [is (a = b), is (a # b)];
(%o3) [false, true]
(%i4) [is (equal (a, b)), is (notequal (a, b))];
(%o4) [true, false]
</pre>
<p>Some operators evaluate <code>=</code> and <code>#</code> to <code>true</code> or <code>false</code>.
</p>
<pre class="example">(%i1) if expand ((x + y)^2) = x^2 + 2 * x * y + y^2 then FOO else
BAR;
(%o1) FOO
(%i2) eq_3 : 2 * x = 3 * x;
(%o2) 2 x = 3 x
(%i3) eq_4 : exp (2) = %e^2;
2 2
(%o3) %e = %e
(%i4) [eq_3 and eq_4, eq_3 or eq_4, not eq_3];
(%o4) [false, true, true]
</pre>
<p>Because <code>not <var>expr</var></code> causes evaluation of <var>expr</var>,
<code>not <var>a</var> = <var>b</var></code> is equivalent to <code>is(<var>a</var> # <var>b</var>)</code>.
</p>
<pre class="example">(%i1) [2 * x # 3 * x, not (2 * x = 3 * x)];
(%o1) [2 x # 3 x, true]
(%i2) is (2 * x # 3 * x);
(%o2) true
</pre>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="Item_003a-Assignment-operators"></a>
</p><hr size="6">
<a name="Assignment-operators"></a>
<a name="SEC42"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC41" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="#SEC43" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC36" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC36" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_8.html#SEC44" 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_89.html#SEC425" 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"> 7.6 Assignment operators </h2>
<p><a name="g_t_003a"></a>
<a name="Item_003a-_003a"></a>
</p><dl>
<dt><u>Operator:</u> <b>:</b>
<a name="IDX236"></a>
</dt>
<dd><p>Assignment operator.
</p>
<p>When the left-hand side is a simple variable (not subscripted), <code>:</code>
evaluates its right-hand side and associates that value with the left-hand side.
</p>
<p>When the left-hand side is a subscripted element of a list, matrix, declared
Maxima array, or Lisp array, the right-hand side is assigned to that element.
The subscript must name an existing element; such objects cannot be extended by
naming nonexistent elements.
</p>
<p>When the left-hand side is a subscripted element of an undeclared Maxima array,
the right-hand side is assigned to that element, if it already exists,
or a new element is allocated, if it does not already exist.
</p>
<p>When the left-hand side is a list of simple and/or subscripted variables, the
right-hand side must evaluate to a list, and the elements of the right-hand
side are assigned to the elements of the left-hand side, in parallel.
</p>
<p>See also <code><a href="maxima_4.html#kill">kill</a></code> and <code><a href="maxima_33.html#remvalue">remvalue</a></code>, which undo the association between
the left-hand side and its value.
</p>
<p>Examples:
</p>
<p>Assignment to a simple variable.
</p>
<pre class="example">(%i1) a;
(%o1) a
(%i2) a : 123;
(%o2) 123
(%i3) a;
(%o3) 123
</pre>
<p>Assignment to an element of a list.
</p>
<pre class="example">(%i1) b : [1, 2, 3];
(%o1) [1, 2, 3]
(%i2) b[3] : 456;
(%o2) 456
(%i3) b;
(%o3) [1, 2, 456]
</pre>
<p>Assignment creates an undeclared array.
</p>
<pre class="example">(%i1) c[99] : 789;
(%o1) 789
(%i2) c[99];
(%o2) 789
(%i3) c;
(%o3) c
(%i4) arrayinfo (c);
(%o4) [hashed, 1, [99]]
(%i5) listarray (c);
(%o5) [789]
</pre>
<p>Multiple assignment.
</p>
<pre class="example">(%i1) [a, b, c] : [45, 67, 89];
(%o1) [45, 67, 89]
(%i2) a;
(%o2) 45
(%i3) b;
(%o3) 67
(%i4) c;
(%o4) 89
</pre>
<p>Multiple assignment is carried out in parallel.
The values of <code>a</code> and <code>b</code> are exchanged in this example.
</p>
<pre class="example">(%i1) [a, b] : [33, 55];
(%o1) [33, 55]
(%i2) [a, b] : [b, a];
(%o2) [55, 33]
(%i3) a;
(%o3) 55
(%i4) b;
(%o4) 33
</pre>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Evaluation">Evaluation</a> ·
<a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="g_t_003a_003a"></a>
<a name="Item_003a-_003a_003a"></a>
</p><dl>
<dt><u>Operator:</u> <b>::</b>
<a name="IDX237"></a>
</dt>
<dd><p>Assignment operator.
</p>
<p><code>::</code> is the same as <code><a href="#g_t_003a">:</a></code> (which see) except that <code>::</code> evaluates
its left-hand side as well as its right-hand side.
</p>
<p>Examples:
</p>
<pre class="example">(%i1) x : 'foo;
(%o1) foo
(%i2) x :: 123;
(%o2) 123
(%i3) foo;
(%o3) 123
(%i4) x : '[a, b, c];
(%o4) [a, b, c]
(%i5) x :: [11, 22, 33];
(%o5) [11, 22, 33]
(%i6) a;
(%o6) 11
(%i7) b;
(%o7) 22
(%i8) c;
(%o8) 33
</pre>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Evaluation">Evaluation</a> ·
<a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="g_t_003a_003a_003d"></a>
<a name="Item_003a-_003a_003a_003d"></a>
</p><dl>
<dt><u>Operator:</u> <b>::=</b>
<a name="IDX238"></a>
</dt>
<dd><p>Macro function definition operator.
<code>::=</code> defines a function (called a "macro" for historical reasons) which
quotes its arguments, and the expression which it returns (called the "macro
expansion") is evaluated in the context from which the macro was called.
A macro function is otherwise the same as an ordinary function.
</p>
<p><code><a href="maxima_36.html#macroexpand">macroexpand</a></code> returns a macro expansion (without evaluating it).
<code>macroexpand (foo (x))</code> followed by <code>''%</code> is equivalent to
<code>foo (x)</code> when <code>foo</code> is a macro function.
</p>
<p><code>::=</code> puts the name of the new macro function onto the global list
<code><a href="maxima_36.html#macros">macros</a></code>. <code><a href="maxima_4.html#kill">kill</a></code>, <code><a href="maxima_11.html#remove">remove</a></code>, and <code><a href="maxima_36.html#remfunction">remfunction</a></code>
unbind macro function definitions and remove names from <code>macros</code>.
</p>
<p><code><a href="maxima_36.html#fundef">fundef</a></code> or <code><a href="maxima_36.html#dispfun">dispfun</a></code> return a macro function definition or assign it
to a label, respectively.
</p>
<p>Macro functions commonly contain <code><a href="maxima_36.html#buildq">buildq</a></code> and <code><a href="maxima_36.html#splice">splice</a></code> expressions to
construct an expression, which is then evaluated.
</p>
<p>Examples
</p>
<p>A macro function quotes its arguments, so message (1) shows <code>y - z</code>, not
the value of <code>y - z</code>. The macro expansion (the quoted expression
<code>'(print ("(2) x is equal to", x))</code>) is evaluated in the context from which
the macro was called, printing message (2).
</p>
<pre class="example">(%i1) x: %pi$
(%i2) y: 1234$
(%i3) z: 1729 * w$
(%i4) printq1 (x) ::= block (print ("(1) x is equal to", x),
'(print ("(2) x is equal to", x)))$
(%i5) printq1 (y - z);
(1) x is equal to y - z
(2) x is equal to %pi
(%o5) %pi
</pre>
<p>An ordinary function evaluates its arguments, so message (1) shows the value of
<code>y - z</code>. The return value is not evaluated, so message (2) is not printed
until the explicit evaluation <code>''%</code>.
</p>
<pre class="example">(%i1) x: %pi$
(%i2) y: 1234$
(%i3) z: 1729 * w$
(%i4) printe1 (x) := block (print ("(1) x is equal to", x),
'(print ("(2) x is equal to", x)))$
(%i5) printe1 (y - z);
(1) x is equal to 1234 - 1729 w
(%o5) print((2) x is equal to, x)
(%i6) ''%;
(2) x is equal to %pi
(%o6) %pi
</pre>
<p><code>macroexpand</code> returns a macro expansion.
<code>macroexpand (foo (x))</code> followed by <code>''%</code> is equivalent to
<code>foo (x)</code> when <code>foo</code> is a macro function.
</p>
<pre class="example">(%i1) x: %pi$
(%i2) y: 1234$
(%i3) z: 1729 * w$
(%i4) g (x) ::= buildq ([x], print ("x is equal to", x))$
(%i5) macroexpand (g (y - z));
(%o5) print(x is equal to, y - z)
(%i6) ''%;
x is equal to 1234 - 1729 w
(%o6) 1234 - 1729 w
(%i7) g (y - z);
x is equal to 1234 - 1729 w
(%o7) 1234 - 1729 w
</pre>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Function-definition">Function definition</a> ·
<a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="g_t_003a_003d"></a>
<a name="Item_003a-_003a_003d"></a>
</p><dl>
<dt><u>Operator:</u> <b>:=</b>
<a name="IDX239"></a>
</dt>
<dd><p>The function definition operator.
</p>
<p><code><var>f</var>(<var>x_1</var>, ..., <var>x_n</var>) := <var>expr</var></code> defines a function named
<var>f</var> with arguments <var>x_1</var>, …, <var>x_n</var> and function body
<var>expr</var>. <code>:=</code> never evaluates the function body (unless explicitly
evaluated by quote-quote <code>''</code>).
The function body is evaluated every time the function is called.
</p>
<p><code><var>f</var>[<var>x_1</var>, ..., <var>x_n</var>] := <var>expr</var></code> defines a so-called array function.
Its function body is evaluated just once for each distinct value of its arguments,
and that value is returned, without evaluating the function body,
whenever the arguments have those values again.
(A function of this kind is commonly known as a "memoizing function".)
</p>
<p><code><var>f</var>[<var>x_1</var>, ..., <var>x_n</var>](<var>y_1</var>, ..., <var>y_m</var>) := <var>expr</var></code>
is a special case of an array function.
<code><var>f</var>[<var>x_1</var>, ..., <var>x_n</var>]</code> is an array function which returns a lambda expression
with arguments <code><var>y_1</var>, ..., <var>y_m</var></code>.
The function body is evaluated once for each distinct value of <code><var>x_1</var>, ..., <var>x_n</var></code>,
and the body of the lambda expression is that value.
</p>
<p>When the last or only function argument <var>x_n</var> is a list of one element, the
function defined by <code>:=</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>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><a href="maxima_36.html#local">local</a></code> appears.
</p>
<p>If some formal argument <var>x_k</var> is a quoted symbol, the function defined by
<code>:=</code> does not evaluate the corresponding actual argument. Otherwise all
actual arguments are evaluated.
</p>
<p>See also <code><a href="maxima_36.html#define">define</a></code> and <code><a href="#g_t_003a_003a_003d">::=</a></code>.
</p>
<p>Examples:
</p>
<p><code>:=</code> never evaluates the function body (unless explicitly evaluated by
quote-quote).
</p>
<pre class="example">(%i1) expr : cos(y) - sin(x);
(%o1) cos(y) - sin(x)
(%i2) F1 (x, y) := expr;
(%o2) F1(x, y) := expr
(%i3) F1 (a, b);
(%o3) cos(y) - sin(x)
(%i4) F2 (x, y) := ''expr;
(%o4) F2(x, y) := cos(y) - sin(x)
(%i5) F2 (a, b);
(%o5) cos(b) - sin(a)
</pre>
<p><code>f(<var>x_1</var>, ..., <var>x_n</var>) := ...</code> defines an ordinary function.
</p>
<pre class="example">(%i1) G1(x, y) := (print ("Evaluating G1 for x=", x, "and y=", y), x.y - y.x);
(%o1) G1(x, y) := (print("Evaluating G1 for x=", x, "and y=",
y), x . y - y . x)
(%i2) G1([1, a], [2, b]);
Evaluating G1 for x= [1, a] and y= [2, b]
(%o2) 0
(%i3) G1([1, a], [2, b]);
Evaluating G1 for x= [1, a] and y= [2, b]
(%o3) 0
</pre>
<p><code>f[<var>x_1</var>, ..., <var>x_n</var>] := ...</code> defines an array function.
</p>
<pre class="example">(%i1) G2[a] := (print ("Evaluating G2 for a=", a), a^2);
2
(%o1) G2 := (print("Evaluating G2 for a=", a), a )
a
(%i2) G2[1234];
Evaluating G2 for a= 1234
(%o2) 1522756
(%i3) G2[1234];
(%o3) 1522756
(%i4) G2[2345];
Evaluating G2 for a= 2345
(%o4) 5499025
(%i5) arrayinfo (G2);
(%o5) [hashed, 1, [1234], [2345]]
(%i6) listarray (G2);
(%o6) [1522756, 5499025]
</pre>
<p><code><var>f</var>[<var>x_1</var>, ..., <var>x_n</var>](<var>y_1</var>, ..., <var>y_m</var>) := <var>expr</var></code>
is a special case of an array function.
</p>
<pre class="example">(%i1) G3[n](x) := (print ("Evaluating G3 for n=", n), diff (sin(x)^2, x, n));
(%o1) G3 (x) := (print("Evaluating G3 for n=", n),
n
2
diff(sin (x), x, n))
(%i2) G3[2];
Evaluating G3 for n= 2
2 2
(%o2) lambda([x], 2 cos (x) - 2 sin (x))
(%i3) G3[2];
2 2
(%o3) lambda([x], 2 cos (x) - 2 sin (x))
(%i4) G3[2](1);
2 2
(%o4) 2 cos (1) - 2 sin (1)
(%i5) arrayinfo (G3);
(%o5) [hashed, 1, [2]]
(%i6) listarray (G3);
2 2
(%o6) [lambda([x], 2 cos (x) - 2 sin (x))]
</pre>
<p>When the last or only function argument <var>x_n</var> is a list of one element,
the function defined by <code>:=</code> accepts a variable number of arguments.
</p>
<pre class="example">(%i1) H ([L]) := apply ("+", L);
(%o1) H([L]) := apply("+", L)
(%i2) H (a, b, c);
(%o2) c + b + a
</pre>
<p><code>local</code> makes 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>Categories: <a href="maxima_105.html#Category_003a-Function-definition">Function definition</a> ·
<a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="Item_003a-User-defined-operators"></a>
</p><hr size="6">
<a name="User-defined-operators"></a>
<a name="SEC43"></a>
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC42" title="Previous section in reading order"> < </a>]</td>
<td valign="middle" align="left">[<a href="maxima_8.html#SEC44" title="Next section in reading order"> > </a>]</td>
<td valign="middle" align="left"> </td>
<td valign="middle" align="left">[<a href="#SEC36" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="#SEC36" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="maxima_8.html#SEC44" 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_89.html#SEC425" 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"> 7.7 User defined operators </h2>
<p><a name="infix"></a>
<a name="Item_003a-infix"></a>
</p><dl>
<dt><u>Function:</u> <b>infix</b><i> <br> <tt>infix</tt> (<var>op</var>) <br> <tt>infix</tt> (<var>op</var>, <var>lbp</var>, <var>rbp</var>) <br> <tt>infix</tt> (<var>op</var>, <var>lbp</var>, <var>rbp</var>, <var>lpos</var>, <var>rpos</var>, <var>pos</var>)</i>
<a name="IDX240"></a>
</dt>
<dd><p>Declares <var>op</var> to be an infix operator. An infix operator is a function of
two arguments, with the name of the function written between the arguments.
For example, the subtraction operator <code>-</code> is an infix operator.
</p>
<p><code>infix (<var>op</var>)</code> declares <var>op</var> to be an infix operator with default
binding powers (left and right both equal to 180) and parts of speech (left and
right both equal to <code>any</code>).
</p>
<p><code>infix (<var>op</var>, <var>lbp</var>, <var>rbp</var>)</code> declares <var>op</var> to be an infix
operator with stated left and right binding powers and default parts of speech
(left and right both equal to <code>any</code>).
</p>
<p><code>infix (<var>op</var>, <var>lbp</var>, <var>rbp</var>, <var>lpos</var>, <var>rpos</var>, <var>pos</var>)</code>
declares <var>op</var> to be an infix operator with stated left and right binding
powers and parts of speech <var>lpos</var>, <var>rpos</var>, and <var>pos</var> for the left
operand, the right operand, and the operator result, respectively.
</p>
<p>"Part of speech", in reference to operator declarations, means expression type.
Three types are recognized: <code>expr</code>, <code>clause</code>, and <code>any</code>,
indicating an algebraic expression, a Boolean expression, or any kind of
expression, respectively. Maxima can detect some syntax errors by comparing the
declared part of speech to an actual expression.
</p>
<p>The precedence of <var>op</var> with respect to other operators derives from the left
and right binding powers of the operators in question. If the left and right
binding powers of <var>op</var> are both greater the left and right binding powers of
some other operator, then <var>op</var> takes precedence over the other operator.
If the binding powers are not both greater or less, some more complicated
relation holds.
</p>
<p>The associativity of <var>op</var> depends on its binding powers. Greater left
binding power (<var>lbp</var>) implies an instance of <var>op</var> is evaluated before
other operators to its left in an expression, while greater right binding power
(<var>rbp</var>) implies an instance of <var>op</var> is evaluated before other operators
to its right in an expression. Thus greater <var>lbp</var> makes <var>op</var>
right-associative, while greater <var>rbp</var> makes <var>op</var> left-associative.
If <var>lbp</var> is equal to <var>rbp</var>, <var>op</var> is left-associative.
</p>
<p>See also <a href="#SEC37">Introduction to operators</a>.
</p>
<p>Examples:
</p>
<p>If the left and right binding powers of <var>op</var> are both greater
the left and right binding powers of some other operator,
then <var>op</var> takes precedence over the other operator.
</p>
<pre class="example">(%i1) :lisp (get '$+ 'lbp)
100
(%i1) :lisp (get '$+ 'rbp)
100
(%i1) infix ("##", 101, 101);
(%o1) ##
(%i2) "##"(a, b) := sconcat("(", a, ",", b, ")");
(%o2) (a ## b) := sconcat("(", a, ",", b, ")")
(%i3) 1 + a ## b + 2;
(%o3) (a,b) + 3
(%i4) infix ("##", 99, 99);
(%o4) ##
(%i5) 1 + a ## b + 2;
(%o5) (a+1,b+2)
</pre>
<p>Greater <var>lbp</var> makes <var>op</var> right-associative,
while greater <var>rbp</var> makes <var>op</var> left-associative.
</p>
<pre class="example">(%i1) infix ("##", 100, 99);
(%o1) ##
(%i2) "##"(a, b) := sconcat("(", a, ",", b, ")")$
(%i3) foo ## bar ## baz;
(%o3) (foo,(bar,baz))
(%i4) infix ("##", 100, 101);
(%o4) ##
(%i5) foo ## bar ## baz;
(%o5) ((foo,bar),baz)
</pre>
<p>Maxima can detect some syntax errors by comparing the
declared part of speech to an actual expression.
</p>
<pre class="example">(%i1) infix ("##", 100, 99, expr, expr, expr);
(%o1) ##
(%i2) if x ## y then 1 else 0;
Incorrect syntax: Found algebraic expression where logical
expression expected
if x ## y then
^
(%i2) infix ("##", 100, 99, expr, expr, clause);
(%o2) ##
(%i3) if x ## y then 1 else 0;
(%o3) if x ## y then 1 else 0
</pre>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a> ·
<a href="maxima_105.html#Category_003a-Declarations-and-inferences">Declarations and inferences</a> ·
<a href="maxima_105.html#Category_003a-Syntax">Syntax</a>
</div>
</p></dd></dl>
<p><a name="matchfix"></a>
<a name="Item_003a-matchfix"></a>
</p><dl>
<dt><u>Function:</u> <b>matchfix</b><i> <br> <tt>matchfix</tt> (<var>ldelimiter</var>, <var>rdelimiter</var>) <br> <tt>matchfix</tt> (<var>ldelimiter</var>, <var>rdelimiter</var>, <var>arg_pos</var>, <var>pos</var>)</i>
<a name="IDX241"></a>
</dt>
<dd><p>Declares a matchfix operator with left and right delimiters <var>ldelimiter</var>
and <var>rdelimiter</var>. The delimiters are specified as strings.
</p>
<p>A "matchfix" operator is a function of any number of arguments,
such that the arguments occur between matching left and right delimiters.
The delimiters may be any strings, so long as the parser can
distinguish the delimiters from the operands
and other expressions and operators.
In practice this rules out unparseable delimiters such as
<code>%</code>, <code>,</code>, <code>$</code> and <code>;</code>,
and may require isolating the delimiters with white space.
The right delimiter can be the same or different from the left delimiter.
</p>
<p>A left delimiter can be associated with only one right delimiter;
two different matchfix operators cannot have the same left delimiter.
</p>
<p>An existing operator may be redeclared as a matchfix operator
without changing its other properties.
In particular, built-in operators such as addition <code>+</code> can
be declared matchfix,
but operator functions cannot be defined for built-in operators.
</p>
<p>The command <code>matchfix (<var>ldelimiter</var>, <var>rdelimiter</var>, <var>arg_pos</var>,
<var>pos</var>)</code> declares the argument part-of-speech <var>arg_pos</var> and result
part-of-speech <var>pos</var>, and the delimiters <var>ldelimiter</var> and
<var>rdelimiter</var>.
</p>
<p>"Part of speech", in reference to operator declarations, means expression type.
Three types are recognized: <code>expr</code>, <code>clause</code>, and <code>any</code>,
indicating an algebraic expression, a Boolean expression, or any kind of
expression, respectively.
Maxima can detect some syntax errors by comparing the
declared part of speech to an actual expression.
</p>
<p>The function to carry out a matchfix operation is an ordinary
user-defined function.
The operator function is defined
in the usual way
with the function definition operator <code>:=</code> or <code>define</code>.
The arguments may be written between the delimiters,
or with the left delimiter as a quoted string and the arguments
following in parentheses.
<code>dispfun (<var>ldelimiter</var>)</code> displays the function definition.
</p>
<p>The only built-in matchfix operator is the list constructor <code>[ ]</code>.
Parentheses <code>( )</code> and double-quotes <code>" "</code>
act like matchfix operators,
but are not treated as such by the Maxima parser.
</p>
<p><code>matchfix</code> evaluates its arguments.
<code>matchfix</code> returns its first argument, <var>ldelimiter</var>.
</p>
<p>Examples:
</p>
<p>Delimiters may be almost any strings.
</p>
<pre class="example">(%i1) matchfix ("@@", "~");
(%o1) @@
(%i2) @@ a, b, c ~;
(%o2) @@a, b, c~
(%i3) matchfix (">>", "<<");
(%o3) >>
(%i4) >> a, b, c <<;
(%o4) >>a, b, c<<
(%i5) matchfix ("foo", "oof");
(%o5) foo
(%i6) foo a, b, c oof;
(%o6) fooa, b, coof
(%i7) >> w + foo x, y oof + z << / @@ p, q ~;
>>z + foox, yoof + w<<
(%o7) ----------------------
@@p, q~
</pre>
<p>Matchfix operators are ordinary user-defined functions.
</p>
<pre class="example">(%i1) matchfix ("!-", "-!");
(%o1) "!-"
(%i2) !- x, y -! := x/y - y/x;
x y
(%o2) !-x, y-! := - - -
y x
(%i3) define (!-x, y-!, x/y - y/x);
x y
(%o3) !-x, y-! := - - -
y x
(%i4) define ("!-" (x, y), x/y - y/x);
x y
(%o4) !-x, y-! := - - -
y x
(%i5) dispfun ("!-");
x y
(%t5) !-x, y-! := - - -
y x
(%o5) done
(%i6) !-3, 5-!;
16
(%o6) - --
15
(%i7) "!-" (3, 5);
16
(%o7) - --
15
</pre>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Syntax">Syntax</a> ·
<a href="maxima_105.html#Category_003a-Operators">Operators</a>
</div>
</p></dd></dl>
<p><a name="function_005fnary"></a>
<a name="Item_003a-nary"></a>
</p><dl>
<dt><u>Function:</u> <b>nary</b><i> <br> <tt>nary</tt> (<var>op</var>) <br> <tt>nary</tt> (<var>op</var>, <var>bp</var>, <var>arg_pos</var>, <var>pos</var>)</i>
<a name="IDX242"></a>
</dt>
<dd><p>An <code>nary</code> operator is used to denote a function of any number of arguments,
each of which is separated by an occurrence of the operator, e.g. A+B or A+B+C.
The <code>nary("x")</code> function is a syntax extension function to declare <code>x</code>
to be an <code>nary</code> operator. Functions may be declared to be <code>nary</code>. If
<code>declare(j,nary);</code> is done, this tells the simplifier to simplify, e.g.
<code>j(j(a,b),j(c,d))</code> to <code>j(a, b, c, d)</code>.
</p>
<p>See also <a href="#SEC37">Introduction to operators</a>.
</p>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a> ·
<a href="maxima_105.html#Category_003a-Syntax">Syntax</a>
</div>
</p></dd></dl>
<p><a name="nofix"></a>
<a name="Item_003a-nofix"></a>
</p><dl>
<dt><u>Function:</u> <b>nofix</b><i> <br> <tt>nofix</tt> (<var>op</var>) <br> <tt>nofix</tt> (<var>op</var>, <var>pos</var>)</i>
<a name="IDX243"></a>
</dt>
<dd><p><code>nofix</code> operators are used to denote functions of no arguments.
The mere presence of such an operator in a command will cause the
corresponding function to be evaluated. For example, when one types
"exit;" to exit from a Maxima break, "exit" is behaving similar to a
<code>nofix</code> operator. The function <code>nofix("x")</code> is a syntax extension
function which declares <code>x</code> to be a <code>nofix</code> operator.
</p>
<p>See also <a href="#SEC37">Introduction to operators</a>.
</p>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a> ·
<a href="maxima_105.html#Category_003a-Syntax">Syntax</a>
</div>
</p></dd></dl>
<p><a name="postfix"></a>
<a name="Item_003a-postfix"></a>
</p><dl>
<dt><u>Function:</u> <b>postfix</b><i> <br> <tt>postfix</tt> (<var>op</var>) <br> <tt>postfix</tt> (<var>op</var>, <var>lbp</var>, <var>lpos</var>, <var>pos</var>)</i>
<a name="IDX244"></a>
</dt>
<dd><p><code>postfix</code> operators like the <code>prefix</code> variety denote functions of a
single argument, but in this case the argument immediately precedes an
occurrence of the operator in the input string, e.g. 3!. The
<code>postfix("x")</code> function is a syntax extension function to declare <code>x</code>
to be a <code>postfix</code> operator.
</p>
<p>See also <a href="#SEC37">Introduction to operators</a>.
</p>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a> ·
<a href="maxima_105.html#Category_003a-Syntax">Syntax</a>
</div>
</p></dd></dl>
<p><a name="prefix"></a>
<a name="Item_003a-prefix"></a>
</p><dl>
<dt><u>Function:</u> <b>prefix</b><i> <br> <tt>prefix</tt> (<var>op</var>) <br> <tt>prefix</tt> (<var>op</var>, <var>rbp</var>, <var>rpos</var>, <var>pos</var>)</i>
<a name="IDX245"></a>
</dt>
<dd><p>A <code>prefix</code> operator is one which signifies a function of one argument,
which argument immediately follows an occurrence of the operator.
<code>prefix("x")</code> is a syntax extension function to declare <code>x</code> to be a
<code>prefix</code> operator.
</p>
<p>See also <a href="#SEC37">Introduction to operators</a>.
</p>
<div class=categorybox>
<p>Categories: <a href="maxima_105.html#Category_003a-Operators">Operators</a> ·
<a href="maxima_105.html#Category_003a-Syntax">Syntax</a>
</div>
</p></dd></dl>
<p><a name="Item_003a-Evaluation"></a>
</p><hr size="6">
<table cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#SEC36" title="Beginning of this chapter or previous chapter"> << </a>]</td>
<td valign="middle" align="left">[<a href="maxima_8.html#SEC44" 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_89.html#SEC425" 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>Build Daemon user</em> on <em>May, 8 2017</em> using <a href="http://texi2html.cvshome.org/"><em>texi2html 1.76</em></a>.
</font>
<br>
</p>
</body>
</html>
|