Online Algebra Calculator
Many of users do not use powerful Maxima computer algebra system for systematic work, but for ad hoc algebraic calculations – equations, functions, matrixes, etc. only. To do this job, it is not useful to download the whole application from a web site.
Function: infix (<op>)
Function: infix (<op>, <lbp>, <rbp>)
Function: infix (<op>, <lbp>, <rbp>, <lpos>, <rpos>, <pos>) Declares <op> 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 - is an infix operator.
infix (<op>) declares <op> 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 any).
infix (<op>, <lbp>, <rbp>) declares <op> to be an infix operator with stated left and right binding powers and default parts of speech (left and right both equal to any).
infix (<op>, <lbp>, <rbp>, <lpos>, <rpos>, <pos>) declares <op> to be an infix operator with stated left and right binding powers and parts of speech <lpos>, <rpos>, and <pos> for the left operand, the right operand, and the operator result, respectively.
"Part of speech", in reference to operator declarations, means expression type. Three types are recognized: expr, clause, and any, 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.
The precedence of <op> 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 <op> are both greater the left and right binding powers of some other operator, then <op> takes precedence over the other operator. If the binding powers are not both greater or less, some more complicated relation holds.
The associativity of <op> depends on its binding powers. Greater left binding power (<lbp>) implies an instance of <op> is evaluated before other operators to its left in an expression, while greater right binding power (<rbp>) implies an instance of <op> is evaluated before other operators to its right in an expression. Thus greater <lbp> makes <op> right-associative, while greater <rbp> makes <op> left-associative. If <lbp> is equal to <rbp>, <op> is left-associative.
See also Syntax.
Examples:
If the left and right binding powers of <op> are both greater the left and right binding powers of some other operator, then <op> takes precedence over the other operator.
(%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)Greater <lbp> makes <op> right-associative, while greater <rbp> makes <op> left-associative.
(%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)Maxima can detect some syntax errors by comparing the declared part of speech to an actual expression.
(%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(%o1) true (%i2)