Sponsored links: Algebra eBooks ### The Maxima on-line user's manual

Algebra Calculator

#### Search: #### Syntax

6.7 Syntax==========

It is possible to define new operators with specified precedence, toundefine existing operators, or to redefine the precedence of existingoperators. An operator may be unary prefix or unary postfix, binaryinfix, n-ary infix, matchfix, or nofix. "Matchfix" means a pair ofsymbols which enclose their argument or arguments, and "nofix" means anoperator which takes no arguments. As examples of the different typesof operators, there are the following.

unary prefix negation `- a`

unary postfix factorial `a!`

binary infix exponentiation `a^b`

n-ary infix addition `a + b`

matchfix list construction `[a, b]`

(There are no built-in nofix operators; for an example of such anoperator, see `nofix`.)

The mechanism to define a new operator is straightforward. It isonly necessary to declare a function as an operator; the operatorfunction might or might not be defined.

An example of user-defined operators is the following. Note thatthe explicit function call `"dd" (a)` is equivalent to `dd a`, likewise`"<-" (a, b)` is equivalent to `a <- b`. Note also that the functions`"dd"` and `"<-"` are undefined in this 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```

The Maxima functions which define new operators are summarized inthis table, stating the default left and right binding powers (lbp andrbp, respectively). (Binding power determines operator precedence.However, since left and right binding powers can differ, binding poweris somewhat more complicated than precedence.) Some of the operationdefinition functions take additional arguments; see the functiondescriptions for details.

`prefix` rbp=180

`postfix` lbp=180

`infix` lbp=180, rbp=180

`nary` lbp=180, rbp=180

`matchfix` (binding power not applicable)

`nofix` (binding power not applicable)

For comparison, here are some built-in operators and their left andright binding powers.

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

`remove` and `kill` remove operator properties from an atom.`remove ("<a>", op)` removes only the operator properties of <a>.`kill ("<a>")` removes all properties of <a>, including the operatorproperties. Note that the name of the operator must be enclosed inquotation marks.

```     (%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)```

There are also some inexact matches for `syntax`. Try `?? syntax` to see them.

```(%o1)                                true
(%i2) ```

### Related Examples

? syntax;

Calculate

##### syntax

? syntax;

Calculate 