8.1.2 Defining custom operators
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.
- To delete an operator, user_operator takes two arguments:
-
name, a string which is the name of the operator.
- Delete, the symbol.
- user_operator(name,Delete) deletes
the operator.
Examples
Let R be defined on
ℝ×ℝ by x R y=x y+x+y.
To input R:
user_operator("R",(x,y)->x*y+x+y,Binary) |
(Do not forget to put spaces around R.)
Let S be defined on ℕ by
“for x and y integers, x S y means that x and y are not coprime.”
To input S:
user_operator("S",(x,y)->(gcd(x,y))!=1,Binary) |
(Do not forget to put spaces around S.)
Let T be defined on ℝ by T x=x2. To input T:
user_operator("T",x->x^2,Prefix) |
(Do not forget to put a space before T.)
Let U be defined on ℝ by x U=5x. To input U:
user_operator("U",x->5*x,Postfix) |
(Do not forget to put a space before T.)