OPERATOR INDEX

OPERATOR _ _ _ _ _ _ _ _ _ _ _ _ declaration

Use the operator declaration to declare your own operators.

syntax:

operator<identifier>{,<identifier>}*

<identifier> can be any valid REDUCE identifier, which is not the name of a matrix, array, scalar variable or previously-defined operator.

examples:


operator dis,fac; 

let dis(~x,~y) = sqrt(x^2 + y^2); 

dis(1,2); 

  SQRT(5) 


dis(a,10); 

        2
  SQRT(A  + 100) 


on rounded; 

dis(1.5,7.2); 

  7.35459040329


let fac(~n) = if n=0 then 1
               else if not(fixp n and n>0)
                then rederr "choose non-negative integer"
               else for i := 1:n product i;
 

fac(5); 

  120 


fac(-2); 

  ***** choose non-negative integer

The first operator is the Euclidean distance metric, the distance of point (x,y) from the origin. The second operator is the factorial.

Operators can have various properties assigned to them; they can be declared infix, linear, symmetric, antisymmetric, or noncommutative. The default operator is prefix, nonlinear, and commutative. Precedence can also be assigned to operators using the declaration precedence.

Functionality is assigned to an operator by a let statement or a forall...let statement, (or possibly by a procedure with the name of the operator). Be careful not to redefine a system operator by accident. REDUCE permits you to redefine system operators, giving you a warning message that the operator was already defined. This flexibility allows you to add mathematical rules that do what you want them to do, but can produce odd or erroneous behavior if you are not careful.

You can declare operators from inside procedures, as long as they are not local variables. Operators defined inside procedures are global. A formal parameter may be declared as an operator, and has the effect of declaring the calling variable as the operator.