Defining an operator: user_operator

### 5.14.2 Defining an operator: user_operator

The user_operator command lets you define an operator or delete an operator you previously defined. When you use an operator you defined, you have to make sure that you leave spaces around the operator.

To define an operator:

- user_operator takes three arguments:
  - name, a string which is the name of the operator.
  - fn, a function of one or two variables with values in ℝ or in true, false.
  - type, to specify what kind of an operator you are defining. The possible values are:
    - Binary, to define an infixed operator. In this case, fn must be a function of two variables.
    - Prefix (or Unary), to define a prefixed operator. In this case, fn must be a function of one variable.
    - Postfix, to define a postfixed operator. In this case fn must be a function of one variable.
- user_operator(name,fn,type) returns 1 if the definition was successful and otherwise returns 0.

#### Examples

- Example 1.
  Let R be defined on ℝ×ℝ by x R y= x*y+x+y.
  To define R:
  Input:
  user_operator("R",(x,y)->x*y+x+y,Binary)
  Output:

  1

  Input:
  5 R 7
  (Do not forget to put spaces around R.)
  Output:

  47

- Example 2.
  Let S be defined on ℕ by:
  for x and y integers, x S y means that x and y are not coprime.
  To define S:
  Input:
  user_operator("S",(x,y)->(gcd(x,y))!=1,Binary)
  Output:

  1

  Input:
  5 S 7
  (Do not forget to put spaces around S.)
  Output:

  false

  Input:
  8 S 12
  Do not forget to put spaces around S.
  Output:

  true

- Example 3.
  Let T be defined on ℝ by T x = x2.
  To define T:
  Input:
  user_operator("T",x->x^2,Prefix)
  Output:

  1

  Input:
  T 4
  (Do not forget to put a space before T.)
  Output:

  16

- Example 4.
  Let U be defined on ℝ by x U = 5x.
  To define U:
  Input:
  user_operator("U",x->5*x,Postfix)
  Output:

  1

  Input:
  3 U
  (Do not forget to put a space before T.)
  Output:

  15

To delete an operator:

- user_operator takes two arguments:
  - name, a string which is the name of the operator.
  - Delete
- user_operator(name,Delete) deletes the operator.